Commit 72a0d0c7 authored by Daniel Honsel's avatar Daniel Honsel
Browse files

improved log validator

parent 0be542bf
Loading
Loading
Loading
Loading
+38 −52
Original line number Diff line number Diff line
package de.ugoe.cs.swe.validation

import com.google.common.base.Strings

import de.ugoe.cs.swe.TTCN3Configuration.QualityCheckProfile
import de.ugoe.cs.swe.common.ConfigTools
import de.ugoe.cs.swe.common.MiscTools
@@ -26,6 +24,9 @@ import de.ugoe.cs.swe.tTCN3.VerdictTypeValue
import java.util.regex.Matcher
import java.util.regex.Pattern

import org.eclipse.emf.common.util.EList
import org.eclipse.emf.ecore.EObject

import org.eclipse.xtext.nodemodel.INode
import org.eclipse.xtext.nodemodel.util.NodeModelUtils
import org.eclipse.xtext.validation.AbstractDeclarativeValidator
@@ -35,6 +36,7 @@ import org.eclipse.xtext.validation.EValidatorRegistrar
import static extension de.ugoe.cs.swe.common.TTCN3ScopeHelper.*
import static extension org.eclipse.xtext.EcoreUtil2.*

// TODO: check not resolved external function references
class LogValidator extends AbstractDeclarativeValidator {
	val ConfigTools configTools = ConfigTools.getInstance;
	var QualityCheckProfile activeProfile = configTools.selectedProfile as QualityCheckProfile
@@ -54,65 +56,49 @@ class LogValidator extends AbstractDeclarativeValidator {
			parent = parentAlt;
		}

		var INode node = null
		var statementToCheck = ""
		var other = false
		for (s : functionStmList.eContents) {
			if (s instanceof FunctionStatement) {
				val log = s.findLogStatement
				if (log != null) {
					node = NodeModelUtils.getNode(log)
					if (other) {
						if (!Strings.isNullOrEmpty(statementToCheck)) {
							statementToCheck.checkLogStatementFormat(node, parent)
						}
						other = false
						statementToCheck = ""
					}
					statementToCheck += log.concatLogItems
					if (!activeProfile.processSubsequentLogStatementsAsOne) {
						statementToCheck.checkLogStatementFormat(node, parent)
						statementToCheck = ""
					}
				} else {
					other = true
				}
			}
		}
		if (!Strings.isNullOrEmpty(statementToCheck)) {
			statementToCheck.checkLogStatementFormat(node, parent)
		}
		functionStmList.eContents.checkStatementList(parent)
	}

	@Check
	def checkLogStatementFormat(ModuleControlBody ctrl) {
		ctrl.eContents.checkStatementList(null)
	}

	private def checkStatementList(EList<EObject> statements, TTCN3Reference parent) {
		var INode node = null
		var statementToCheck = ""
		var String statementToCheck = null
		var other = false
		for (s : ctrl.eContents) {
			if (s instanceof ControlStatementOrDefList) {
				val log = s.findLogStatement
		var LogStatement log = null
		for (s : statements) {
			if (s instanceof FunctionStatement) {
				log = s.findLogStatement
			} else if (s instanceof ControlStatementOrDefList) {
				log = s.findLogStatement
			}
			if (log != null) {
				node = NodeModelUtils.getNode(log)
				if (other) {
						if (!Strings.isNullOrEmpty(statementToCheck)) {
							statementToCheck.checkLogStatementFormat(node, null)
					if (statementToCheck != null) {
						statementToCheck.checkLogStatementFormat(node, parent)
					}
					other = false
						statementToCheck = ""
					statementToCheck = null
				}

				if (statementToCheck == null)
					statementToCheck = "";

				statementToCheck += log.concatLogItems
				if (!activeProfile.processSubsequentLogStatementsAsOne) {
						statementToCheck.checkLogStatementFormat(node, null)
						statementToCheck = ""
					statementToCheck.checkLogStatementFormat(node, parent)
					statementToCheck = null
				}
			} else {
				other = true
			}
		}
		}
		if (!Strings.isNullOrEmpty(statementToCheck)) {
			statementToCheck.checkLogStatementFormat(node, null)
		if (statementToCheck != null) {
			statementToCheck.checkLogStatementFormat(node, parent)
		}
	}

@@ -170,7 +156,7 @@ class LogValidator extends AbstractDeclarativeValidator {
				MessageClass.LOGGING.toString,
				node.startLine.toString,
				node.endLine.toString,
				"5.1, " + MiscTools.getMethodName()
				"5.1, " + "checkLogFormat"
			);
		}
	}