Commit 63ab5b5f authored by Daniel Honsel's avatar Daniel Honsel
Browse files

improved validation

parent e02cb175
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -77,12 +77,12 @@ Workflow {

			// validators for the standalone app according to t3q tools
			// can only be used in standalone app, throws an error in eclipse editor
			//composedCheck = "de.ugoe.cs.swe.validation.NamingConventionsValidator"
			//composedCheck = "de.ugoe.cs.swe.validation.StructureOfDataValidator"
			//composedCheck = "de.ugoe.cs.swe.validation.CodeStyleValidator"
			//composedCheck = "de.ugoe.cs.swe.validation.ModularizationValidator"
			//composedCheck = "de.ugoe.cs.swe.validation.MiscFeatureValidator"
			//composedCheck = "de.ugoe.cs.swe.validation.LogValidator"
			composedCheck = "de.ugoe.cs.swe.validation.NamingConventionsValidator"
			composedCheck = "de.ugoe.cs.swe.validation.StructureOfDataValidator"
			composedCheck = "de.ugoe.cs.swe.validation.CodeStyleValidator"
			composedCheck = "de.ugoe.cs.swe.validation.ModularizationValidator"
			composedCheck = "de.ugoe.cs.swe.validation.MiscFeatureValidator"
			composedCheck = "de.ugoe.cs.swe.validation.LogValidator"

			// name clash validator
			// can currently only be used with the eclipse editor, does not work 
+28 −23
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
@@ -55,18 +54,15 @@ import de.ugoe.cs.swe.tTCN3.Type
import de.ugoe.cs.swe.tTCN3.TypeDef
import de.ugoe.cs.swe.tTCN3.UnionDefNamed
import de.ugoe.cs.swe.tTCN3.VarInstance

import java.util.ArrayList
import java.util.List
import java.util.Map
import java.util.concurrent.ConcurrentHashMap
import java.util.regex.Matcher
import java.util.regex.Pattern

import org.eclipse.emf.ecore.EClass
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.util.EcoreUtil.UsageCrossReferencer

import org.eclipse.xtext.nodemodel.INode
import org.eclipse.xtext.nodemodel.util.NodeModelUtils
import org.eclipse.xtext.validation.AbstractDeclarativeValidator
@@ -116,7 +112,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
			MessageClass.STYLE.toString,
			node.startLine.toString,
			node.endLine.toString,
			"6.1, " + MiscTools.getMethodName()
			"6.1, " + "checkNoGotoStatements"
		);
	}

@@ -355,8 +351,12 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {

	private def String eClassesToString(List<EClass> order) {
		var String res = ""
		var index = 0
		for (c : order) {
			res += c.name + " "
			res += c.name
			index++
			if (index < order.size)
				res += ", "
		}
		res
	}
@@ -604,8 +604,9 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
		}
	}
	
	// TODO: figure out another way to find referenced objects
	private def boolean isUnreferenced(EObject type, EObject parent) {
		val result = UsageCrossReferencer.find(type, parent)
		val result = UsageCrossReferencer.find(type, parent.eResource)
		result.size == 0
	}

@@ -614,6 +615,10 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
		if (!activeProfile.checkNoInlineTemplates)
			return;
		
		// only consider templates with a type
		if (template.type == null)
			return;
		
		TTCN3StatisticsProvider.getInstance.incrementCountStyle

		val message = "Inline Template is used!"
@@ -671,7 +676,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
					MessageClass.STYLE.toString,
					node.startLine.toString,
					node.endLine.toString,
					"6.13, " + MiscTools.getMethodName()
					"6.13, " + "checkNoOverSpecificRunsOnClauses"
				);
			}
		}
@@ -690,7 +695,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
				MessageClass.STYLE.toString,
				node.startLine.toString,
				node.endLine.toString,
				"6.13, " + MiscTools.getMethodName(),
				"6.13, " + "checkNoOverSpecificRunsOnClauses",
				LogLevel.INFORMATION.toString
			);
			return false
@@ -713,7 +718,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
					MessageClass.STYLE.toString,
					node.startLine.toString,
					node.endLine.toString,
					"6.13, " + MiscTools.getMethodName(),
					"6.13, " + "checkNoOverSpecificRunsOnClauses",
					LogLevel.INFORMATION.toString
				);
			} else {
@@ -732,7 +737,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
					MessageClass.STYLE.toString,
					node.startLine.toString,
					node.endLine.toString,
					"6.13, " + MiscTools.getMethodName(),
					"6.13, " + "checkNoOverSpecificRunsOnClauses",
					LogLevel.INFORMATION.toString
				);
			} else {
@@ -809,8 +814,8 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
		false
	}

	private def ArrayList<EObject> findAllParameters(EObject parent) {
		val ArrayList<EObject> paramList = newArrayList
	private def ArrayList<TTCN3Reference> findAllParameters(EObject parent) {
		val ArrayList<TTCN3Reference> paramList = newArrayList
		paramList.addAll(parent.getAllContentsOfType(FormalValuePar))
		paramList.addAll(parent.getAllContentsOfType(FormalTimerPar))
		paramList.addAll(parent.getAllContentsOfType(FormalTemplatePar))
@@ -822,7 +827,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
	def checkNoUnusedFormalParameters(AltstepDef altstep) {
		if (activeProfile.checkNoUnusedFormalParameters) {
			if (altstep.params != null) {
				val ArrayList<EObject> paramList = altstep.params.findAllParameters
				val ArrayList<TTCN3Reference> paramList = altstep.params.findAllParameters
				altstep.checkNoUnusedFormalParameters(paramList)
			}
		}
@@ -832,7 +837,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
	def checkNoUnusedFormalParameters(TestcaseDef testcase) {
		if (activeProfile.checkNoUnusedFormalParameters) {
			if (testcase.parList != null) {
				val ArrayList<EObject> paramList = testcase.parList.findAllParameters
				val ArrayList<TTCN3Reference> paramList = testcase.parList.findAllParameters
				testcase.checkNoUnusedFormalParameters(paramList)
			}
		}
@@ -842,7 +847,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
	def checkNoUnusedFormalParameters(FunctionDef function) {
		if (activeProfile.checkNoUnusedFormalParameters) {
			if (function.parameterList != null) {
				val ArrayList<EObject> paramList = function.parameterList.findAllParameters
				val ArrayList<TTCN3Reference> paramList = function.parameterList.findAllParameters
				function.checkNoUnusedFormalParameters(paramList)
			}
		}
@@ -854,7 +859,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
			return

		var current = template
		val ArrayList<EObject> paramList = newArrayList
		val ArrayList<TTCN3Reference> paramList = newArrayList
		val ArrayList<BaseTemplate> consideredTemplates = newArrayList
		consideredTemplates.add(current)

@@ -893,10 +898,10 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
		template.checkNoUnusedFormalParameters(paramList)
	}

	private def checkNoUnusedFormalParameters(EObject parent, ArrayList<EObject> params) {
	private def checkNoUnusedFormalParameters(EObject parent, ArrayList<TTCN3Reference> params) {
		val module = parent.findDesiredParent(TTCN3Module)
		for (p : params) {
			if (p.isUnreferenced(module)) { // TODO: test this call and consider alternatives
			if (p.isUnreferenced(module)) { // TODO: test this call and consider alternatives and fix this! Parameters passed to other functions are not recognized.
				TTCN3StatisticsProvider.getInstance.incrementCountStyle
				val message = "Formal parameter \"" + (p as TTCN3Reference).name + "\" in definition for \"" +
					(parent as TTCN3Reference).name + "\" is never used!"
@@ -959,7 +964,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
					MessageClass.STYLE.toString,
					node.startLine.toString,
					node.endLine.toString,
					"6.11, " + MiscTools.getMethodName()
					"6.11, " + "checkNoUnusedLocalDefinitions"
				);
			}
		}
+10 −10
Original line number Diff line number Diff line
@@ -37,32 +37,32 @@ class ModularizationValidator extends AbstractDeclarativeValidator {
	def checkModuleContainment(TTCN3Module module) {
		if (activeProfile.checkTypesAndValuesModuleContainmentCheck &&
			module.name.contains(ModuleContentHelper.TypesAndValuesModuleIDSubstring)) {
			module.checkModuleContainmentDefinitions(ModuleContentHelper.TypesAndValuesModuleIDSubstring)
			module.checkModuleContainment(ModuleContentHelper.TypesAndValuesModuleIDSubstring)
		} else if (activeProfile.checkTemplatesModuleContainmentCheck &&
			module.name.contains(ModuleContentHelper.TemplatesModuleIDSubstring)) {
			module.checkModuleContainmentDefinitions(ModuleContentHelper.TemplatesModuleIDSubstring)
			module.checkModuleContainment(ModuleContentHelper.TemplatesModuleIDSubstring)
		} else if (activeProfile.checkFunctionsModuleContainmentCheck &&
			module.name.contains(ModuleContentHelper.FunctionsModuleIDSubstring)) {
			module.checkModuleContainmentDefinitions(ModuleContentHelper.FunctionsModuleIDSubstring)
			module.checkModuleContainment(ModuleContentHelper.FunctionsModuleIDSubstring)
		} else if (activeProfile.checkTestcasesModuleContainmentCheck &&
			module.name.contains(ModuleContentHelper.TestcasesModuleIDSubstring)) {
			module.checkModuleContainmentDefinitions(ModuleContentHelper.TestcasesModuleIDSubstring)
			module.checkModuleContainment(ModuleContentHelper.TestcasesModuleIDSubstring)
		} else if (activeProfile.checkModuleParamsModuleContainmentCheck &&
			module.name.contains(ModuleContentHelper.ModuleParamsModuleIDSubstring)) {
			module.checkModuleContainmentDefinitions(ModuleContentHelper.ModuleParamsModuleIDSubstring)
			module.checkModuleContainment(ModuleContentHelper.ModuleParamsModuleIDSubstring)
		} else if (activeProfile.checkInterfaceModuleContainmentCheck &&
			module.name.contains(ModuleContentHelper.InterfaceModuleIDSubstring)) {
			module.checkModuleContainmentDefinitions(ModuleContentHelper.InterfaceModuleIDSubstring)
			module.checkModuleContainment(ModuleContentHelper.InterfaceModuleIDSubstring)
		} else if (activeProfile.checkTestSystemModuleContainmentCheck &&
			module.name.contains(ModuleContentHelper.TestSystemModuleIDSubstring)) {
			module.checkModuleContainmentDefinitions(ModuleContentHelper.TestSystemModuleIDSubstring)
			module.checkModuleContainment(ModuleContentHelper.TestSystemModuleIDSubstring)
		} else if (activeProfile.checkTestControlModuleContainmentCheck &&
			module.name.contains(ModuleContentHelper.TestControlModuleIDSubstring)) {
			module.checkModuleContainmentDefinitions(ModuleContentHelper.TestControlModuleIDSubstring)
			module.checkModuleContainment(ModuleContentHelper.TestControlModuleIDSubstring)
		}
	}

	private def checkModuleContainmentDefinitions(TTCN3Module module, String moduleRestriction) {
	private def checkModuleContainment(TTCN3Module module, String moduleRestriction) {
		for (d : module.getAllContentsOfType(ModuleDefinition)) {
			var EObject definition = null
			if (moduleRestriction == ModuleContentHelper.TestSystemModuleIDSubstring) {
@@ -136,7 +136,7 @@ class ModularizationValidator extends AbstractDeclarativeValidator {
		val referenceSize = activeProfile.getMaximumAllowedModuleSizeInBytes();
		if (moduleSize > referenceSize) {
			TTCN3StatisticsProvider.getInstance.incrementCountModularization
			val message = "Module \"" + module.name + "\" is greater (" + moduleSize +
			val message = "Module \"" + module.name + "\" is larger (" + moduleSize +
				" bytes) than the maximum allowed module size (" + referenceSize + " bytes)!"
			warning(
				message,
+7 −13
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
import de.ugoe.cs.swe.common.logging.LoggingInterface.LogLevel
import de.ugoe.cs.swe.common.logging.LoggingInterface.MessageClass
import de.ugoe.cs.swe.tTCN3.AltstepDef
import de.ugoe.cs.swe.tTCN3.BaseTemplate
@@ -34,10 +32,8 @@ import de.ugoe.cs.swe.tTCN3.TTCN3Reference
import de.ugoe.cs.swe.tTCN3.TemplateDef
import de.ugoe.cs.swe.tTCN3.TestcaseDef
import de.ugoe.cs.swe.tTCN3.TimerInstance

import java.util.regex.Matcher
import java.util.regex.Pattern

import org.eclipse.xtext.nodemodel.INode
import org.eclipse.xtext.nodemodel.util.NodeModelUtils
import org.eclipse.xtext.validation.AbstractDeclarativeValidator
@@ -250,14 +246,13 @@ public class NamingConventionsValidator extends AbstractDeclarativeValidator {
					val INode node = NodeModelUtils.getNode(template)
					val infoMessage = "The template definition for \"" + template.name +
						"\" is ambiguous. It cannot be determined whether it is a send or a receive template according to STF160's conventions. It will not be analyzed further for naming conventions compliance."
					info(
					warning(
						infoMessage,
						TTCN3Package.eINSTANCE.TTCN3Reference_Name,
						MessageClass.NAMING.toString,
						node.startLine.toString,
						node.endLine.toString,
						"2.1, " + MiscTools.getMethodName(),
						LogLevel.INFORMATION.toString
						"2.1, " + MiscTools.getMethodName()
					);
					return;
				}
@@ -307,14 +302,13 @@ public class NamingConventionsValidator extends AbstractDeclarativeValidator {
		if (!regExp.regExpMatch(object.name)) {
			TTCN3StatisticsProvider.getInstance.increaseCountNaming
			val message = "\"" + object.name + "\" does not comply to the naming conventions for \"" + type + "\"!"
			info(
			warning(
				message,
				TTCN3Package.eINSTANCE.TTCN3Reference_Name,
				MessageClass.NAMING.toString,
				node.startLine.toString,
				node.endLine.toString,
				"2.1, " + regExp,
				LogLevel.INFORMATION.toString
				"2.1, " + regExp
			);
			return;
		}
+4 −4
Original line number Diff line number Diff line
@@ -174,7 +174,7 @@ class StructureOfDataValidator extends AbstractDeclarativeValidator {
				MessageClass.STRUCTURE.toString,
				nodeType.startLine.toString,
				nodeType.endLine.toString,
				"4.2, " + MiscTools.getMethodName()
				"4.2, " + "checkPortMessageGrouping"
			);
			return;
		}
@@ -192,7 +192,7 @@ class StructureOfDataValidator extends AbstractDeclarativeValidator {
				MessageClass.STRUCTURE.toString,
				nodeType.startLine.toString,
				nodeType.endLine.toString,
				"4.2, " + MiscTools.getMethodName()
				"4.2, " + "checkPortMessageGrouping"
			);
			return;
		}
@@ -212,7 +212,7 @@ class StructureOfDataValidator extends AbstractDeclarativeValidator {
					MessageClass.STRUCTURE.toString,
					nodeType.startLine.toString,
					nodeType.endLine.toString,
					"4.2, " + MiscTools.getMethodName(),
					"4.2, " + "checkPortMessageGrouping",
					LogLevel.INFORMATION.toString
				);
				return;
@@ -228,7 +228,7 @@ class StructureOfDataValidator extends AbstractDeclarativeValidator {
					MessageClass.STRUCTURE.toString,
					nodeType.startLine.toString,
					nodeType.endLine.toString,
					"4.2, " + MiscTools.getMethodName()
					"4.2, " + "checkPortMessageGrouping"
				);
				return;
			}