Commit f24ef6aa authored by Daniel Honsel's avatar Daniel Honsel
Browse files

checkNoUnusedLocalDefinitions considers only references in own module

parent 718ac24a
Loading
Loading
Loading
Loading
+22 −22
Original line number Diff line number Diff line
@@ -728,74 +728,74 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
		if (definition.def instanceof ConstDef) {
			val constDefList = (definition.def as ConstDef).defs as ConstList
			for (SingleConstDef d : constDefList.list) {
				notReferenced = d.isUnreferenced(parentModule)
				notReferenced = d.isUnreferenced(parentModule, true)
				detailDef = d
			}
		} else if (definition.def instanceof ModuleParDef) {
			if ((definition.def as ModuleParDef).param != null) {
				for (ModuleParameter p : (definition.def as ModuleParDef).param.list.params) {
					notReferenced = p.isUnreferenced(parentModule)
					notReferenced = p.isUnreferenced(parentModule, true)
					detailDef = p
				}
			} else if ((definition.def as ModuleParDef).multitypeParam != null) {
				for (ModulePar p : (definition.def as ModuleParDef).multitypeParam.params) {
					for (ModuleParameter pa : p.list.params) {
						notReferenced = pa.isUnreferenced(parentModule)
						notReferenced = pa.isUnreferenced(parentModule, true)
						detailDef = pa
					}
				}
			}
		} else if (definition.def instanceof FunctionDef) {
			notReferenced = definition.def.isUnreferenced(parentModule)
			notReferenced = definition.def.isUnreferenced(parentModule, true)
			detailDef = definition.def as FunctionDef
		} else if (definition.def instanceof ExtFunctionDef) {
			notReferenced = definition.def.isUnreferenced(parentModule)
			notReferenced = definition.def.isUnreferenced(parentModule, true)
			detailDef = definition.def as ExtFunctionDef			
		} else if (definition.def instanceof TemplateDef) {
			notReferenced = (definition.def as TemplateDef).base.isUnreferenced(parentModule)
			notReferenced = (definition.def as TemplateDef).base.isUnreferenced(parentModule, true)
			detailDef = (definition.def as TemplateDef).base
		} else if (definition.def instanceof SignatureDef) {
			notReferenced = definition.def.isUnreferenced(parentModule)
			notReferenced = definition.def.isUnreferenced(parentModule, true)
			detailDef = definition.def as SignatureDef
		} else if (definition.def instanceof TestcaseDef) {
			notReferenced = definition.def.isUnreferenced(parentModule)
			notReferenced = definition.def.isUnreferenced(parentModule, true)
			detailDef = definition.def as TestcaseDef
		} else if (definition.def instanceof AltstepDef) {
			notReferenced = definition.def.isUnreferenced(parentModule)
			notReferenced = definition.def.isUnreferenced(parentModule, true)
			detailDef = definition.def as AltstepDef
		} else if (definition.def instanceof TypeDef) {
			val body = (definition.def as TypeDef).body

			if (body.structured != null) {
				if (body.structured.recordOf != null && body.structured.recordOf instanceof RecordOfDefNamed) {
					notReferenced = body.structured.recordOf.isUnreferenced(parentModule)
					notReferenced = body.structured.recordOf.isUnreferenced(parentModule, true)
					detailDef = body.structured.recordOf as RecordOfDefNamed
				} else if (body.structured.setOf != null && body.structured.setOf instanceof SetOfDefNamed) {
					notReferenced = body.structured.setOf.isUnreferenced(parentModule)
					notReferenced = body.structured.setOf.isUnreferenced(parentModule, true)
					detailDef = body.structured.setOf as SetOfDefNamed
				} else if (body.structured.record != null && body.structured.record instanceof RecordDefNamed) {
					notReferenced = body.structured.record.isUnreferenced(parentModule)
					notReferenced = body.structured.record.isUnreferenced(parentModule, true)
					detailDef = body.structured.record as RecordDefNamed
				} else if (body.structured.union != null && body.structured.union instanceof UnionDefNamed) {
					notReferenced = body.structured.union.isUnreferenced(parentModule)
					notReferenced = body.structured.union.isUnreferenced(parentModule, true)
					detailDef = body.structured.union as UnionDefNamed
				} else if (body.structured.set != null && body.structured.set instanceof SetDefNamed) {
					notReferenced = body.structured.set.isUnreferenced(parentModule)
					notReferenced = body.structured.set.isUnreferenced(parentModule, true)
					detailDef = body.structured.set as SetDefNamed
				} else if (body.structured.port != null && body.structured.port instanceof PortDef) {
					notReferenced = body.structured.port.isUnreferenced(parentModule)
					notReferenced = body.structured.port.isUnreferenced(parentModule, true)
					detailDef = body.structured.port as PortDef
					showEndLine = true
				} else if (body.structured.component != null && body.structured.component instanceof ComponentDef) {
					notReferenced = body.structured.component.isUnreferenced(parentModule)
					notReferenced = body.structured.component.isUnreferenced(parentModule, true)
					detailDef = body.structured.component as ComponentDef
				} else if (body.structured.enumDef != null && body.structured.enumDef instanceof EnumDefNamed) {
					notReferenced = body.structured.enumDef.isUnreferenced(parentModule)
					notReferenced = body.structured.enumDef.isUnreferenced(parentModule, true)
					detailDef = body.structured.enumDef as EnumDefNamed
				}
			} else if (body.sub != null) {
				if (body.sub instanceof SubTypeDefNamed) {
					notReferenced = body.sub.isUnreferenced(parentModule)
					notReferenced = body.sub.isUnreferenced(parentModule, true)
					detailDef = body.sub as SubTypeDefNamed
				}
			}
@@ -822,11 +822,11 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
		}
	}

	private def boolean isUnreferenced(EObject type, TTCN3Module parent) {
	private def boolean isUnreferenced(EObject type, TTCN3Module parent, boolean searchAllImports) {
		val target = newHashSet(type);
		var boolean found = parent.isReferenced2(target)

		if (!found) {
		if (searchAllImports && !found) {
			synchronized (IMPORTED_FROM) {
				if (IMPORTED_FROM.containsKey(parent)) {
					val list = IMPORTED_FROM.get(parent)
@@ -1144,7 +1144,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
	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 and fix this! Parameters passed to other functions are not recognized.
			if (p.isUnreferenced(module, false)) { // TODO: Parameters passed to other functions are not recognized.
				statistics.incrementCountStyle
				val message = "Formal parameter \"" + (p as TTCN3Reference).name + "\" in definition for \"" +
					(parent as TTCN3Reference).name + "\" is never used!"
@@ -1206,7 +1206,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
		val parent = variable.variableLocal
		if (parent != null || parentControl != null) {
			val module = variable.findDesiredParent(TTCN3Module)
			if (variable.isUnreferenced(module)) {
			if (variable.isUnreferenced(module, false)) {
				statistics.incrementCountStyle
				var varName = "Module Control Part"
				if (parent != null) {