Loading de.ugoe.cs.swe.TTCN3/src/de/ugoe/cs/swe/TTCN3.xtext +2 −2 Original line number Diff line number Diff line Loading @@ -215,10 +215,10 @@ ModuleControlPart: CONTROLKEYWORD LBRACKET body=ModuleControlBody RBRACKET ws=WithStatement? sc=SEMICOLON?; ModuleControlBody: {ModuleControlBody} list+=ControlStatementOrDefList*; {ModuleControlBody} list=ControlStatementOrDefList; ControlStatementOrDefList: def=ControlStatementOrDef sc=SEMICOLON?; {ControlStatementOrDefList} (((localDef+=FunctionLocalDef | localInst+=FunctionLocalInst) withstm+=WithStatement? | control+=ControlStatement) sc+=SEMICOLON)*; ControlStatementOrDef: (localDef=FunctionLocalDef | localInst=FunctionLocalInst) withstm=WithStatement? | control=ControlStatement; Loading de.ugoe.cs.swe.TTCN3/src/de/ugoe/cs/swe/common/TTCN3ScopeHelper.xtend +8 −6 Original line number Diff line number Diff line Loading @@ -226,16 +226,18 @@ class TTCN3ScopeHelper { } def static void scopeModuleControlPart(ModuleControlPart control, ArrayList<EObject> list) { for (ControlStatementOrDefList o : control.body.list) { if (o.def.localDef != null && o.def.localDef.constDef != null) { val constDefList = o.def.localDef.constDef.defs as ConstList for (o : control.body.list.localDef) { if (o.constDef != null) { val constDefList = o.constDef.defs as ConstList for (SingleConstDef d : constDefList.list) { list.add(d); } } if (o.def.localInst != null && o.def.localInst.variable != null) { val varList = o.def.localInst.variable.list val tempList = o.def.localInst.variable.tempList } for (o : control.body.list.localInst) { if (o.variable != null) { val varList = o.variable.list val tempList = o.variable.tempList if (varList != null) { list.addAll(varList.variables); } Loading de.ugoe.cs.swe.TTCN3/src/de/ugoe/cs/swe/scoping/TTCN3ScopeProvider.xtend +3 −3 Original line number Diff line number Diff line Loading @@ -319,9 +319,9 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { } } } else if (parent instanceof ModuleControlBody) { for (ControlStatementOrDefList l : parent.list) { if (l.def.localInst != null && l.def.localInst.timer != null) { for (SingleVarInstance v : l.def.localInst.timer.list.variables) { for (i : parent.list.localInst) { if (i.timer != null) { for (SingleVarInstance v : i.timer.list.variables) { list.add(v) } } Loading de.ugoe.cs.swe.TTCN3/src/de/ugoe/cs/swe/validation/CodeStyleValidator.xtend +160 −106 Original line number Diff line number Diff line Loading @@ -77,6 +77,7 @@ import org.eclipse.xtext.validation.EValidatorRegistrar import static extension de.ugoe.cs.swe.common.TTCN3ReferenceHelper.* import static extension de.ugoe.cs.swe.common.TTCN3ScopeHelper.* import static extension org.eclipse.xtext.EcoreUtil2.* import de.ugoe.cs.swe.tTCN3.PortInstance class CheckDefinitionComeFirstParameter { public boolean hasOtherDefinitions Loading Loading @@ -314,47 +315,64 @@ class CodeStyleValidator extends AbstractDeclarativeValidator { } @Check def checkLocalDefinitionsComeFirst(ModuleDefinition moduleDefinition) { def checkLocalDefinitionsComeFirst(SingleVarInstance variable) { // this considers timers, too if (!activeProfile.checkLocalDefinitionsComeFirst) return; val definition = moduleDefinition.def variable.checkLocalDefinitionsComeFirstAll } if (definition instanceof FunctionDef) { definition.statement.checkLocalDefinitionsComeFirst definition.statement.checkLocalDefinitionsComeFirstStatemanet } else if (definition instanceof TestcaseDef) { definition.statement.checkLocalDefinitionsComeFirst definition.statement.checkLocalDefinitionsComeFirstStatemanet } else if (definition instanceof AltstepDef) { definition.checkLocalDefinitionsComeFirstAltstepDef } else if (definition instanceof TypeDef) { if (definition.body.structured != null && definition.body.structured.component != null) { definition.body.structured.component.checkLocalDefinitionsComeFirstComponent @Check def checkLocalDefinitionsComeFirst(SingleConstDef variable) { if (!activeProfile.checkLocalDefinitionsComeFirst) return; variable.checkLocalDefinitionsComeFirstAll } @Check def checkLocalDefinitionsComeFirst(PortDef variable) { if (!activeProfile.checkLocalDefinitionsComeFirst) return; variable.checkLocalDefinitionsComeFirstAll } private def checkLocalDefinitionsComeFirstAll(TTCN3Reference definition) { val function = definition.findDesiredParent(FunctionDef) val altstep = definition.findDesiredParent(AltstepDef) val testcase = definition.findDesiredParent(TestcaseDef) val control = definition.findDesiredParent(ModuleControlBody) var lastDef = Integer.MIN_VALUE val line = NodeModelUtils.getNode(definition).startLine if (function != null) { if (function.statement != null && function.statement.def != null) { lastDef = NodeModelUtils.getNode(function.statement.def.last).startLine } } private def checkLocalDefinitionsComeFirst(StatementBlock statement) { var int firstStatement = Integer.MAX_VALUE; if (statement.stat.size > 0) { firstStatement = NodeModelUtils.getNode(statement.stat.get(0)).startLine if (testcase != null) { if (testcase.statement != null && testcase.statement.def != null) { lastDef = NodeModelUtils.getNode(testcase.statement.def.last).startLine } for (d : statement.def) { if (d.locDef != null && d.locDef.constDef != null) { d.locDef.constDef.checkDefinitionBeforeFirstOtherStatement(firstStatement) } else if (d.locInst != null && d.locInst.timer != null) { d.locInst.timer.checkDefinitionBeforeFirstOtherStatement(firstStatement) } else if (d.locInst != null && d.locInst.variable != null) { d.locInst.variable.checkDefinitionBeforeFirstOtherStatement(firstStatement) } if (altstep != null && altstep.local.defs != null) { lastDef = NodeModelUtils.getNode(altstep.local.defs.last).startLine } if (control != null && control.list.localDef != null) { lastDef = NodeModelUtils.getNode(control.list.localDef.last).startLine } private def checkDefinitionBeforeFirstOtherStatement(EObject object, int first) { var int line = NodeModelUtils.getNode(object).startLine if (line > first) { if (lastDef > Integer.MIN_VALUE && line > lastDef) { val message = "Local definition is not at the beginning!" var checkName = "checkLocalDefinitionsComeFirst" if (control != null) { checkName = "checkLocalDefinitionsComeFirstWithinControlPart" } statistics.incrementCountStyle warning( message, Loading @@ -362,11 +380,31 @@ class CodeStyleValidator extends AbstractDeclarativeValidator { MessageClass.STYLE.toString, line.toString, line.toString, "6.8, " + "checkLocalDefinitionsComeFirst" "6.8, " + checkName ); } } @Check def checkLocalDefinitionsComeFirst(ModuleDefinition moduleDefinition) { if (!activeProfile.checkLocalDefinitionsComeFirst) return; val definition = moduleDefinition.def if (definition instanceof FunctionDef) { definition.statement.checkLocalDefinitionsComeFirstStatemanet } else if (definition instanceof TestcaseDef) { definition.statement.checkLocalDefinitionsComeFirstStatemanet } else if (definition instanceof AltstepDef) { definition.checkLocalDefinitionsComeFirstAltstepDef } else if (definition instanceof TypeDef) { if (definition.body.structured != null && definition.body.structured.component != null) { definition.body.structured.component.checkLocalDefinitionsComeFirstComponent } } } private def checkLocalDefinitionsComeFirstStatemanet(StatementBlock statement) { val CheckDefinitionComeFirstParameter params = new CheckDefinitionComeFirstParameter for (d : statement.def) { Loading Loading @@ -693,7 +731,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator { null, MessageClass.STYLE.toString, node.startLine.toString, node.endLine.toString, node.startLine.toString, // only show the starting line "6.17, " + MiscTools.getMethodName() ); } Loading Loading @@ -804,7 +842,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator { null, MessageClass.STYLE.toString, node.startLine.toString, node.endLine.toString, node.startLine.toString, // only show the starting line "6.13, " + "checkNoOverSpecificRunsOnClauses" ); } Loading Loading @@ -1084,11 +1122,17 @@ class CodeStyleValidator extends AbstractDeclarativeValidator { } private def checkNoUnusedLocalDefinitionsAll(TTCN3Reference variable) { if (variable.variableLocal) { val parentControl = variable.findDesiredParent(ModuleControlBody) val parent = variable.variableLocal if (parent != null || parentControl != null) { val module = variable.findDesiredParent(TTCN3Module) if (variable.isUnreferenced(module)) { statistics.incrementCountStyle val message = "Local definition for \"" + variable.name + "\" in definition of \"" + module.name + var varName = "Module Control Part" if (parent != null) { varName = parent.name } val message = "Local definition for \"" + variable.name + "\" in definition of \"" + varName + "\" is never used!" val INode node = NodeModelUtils.getNode(variable) warning( Loading @@ -1103,15 +1147,25 @@ class CodeStyleValidator extends AbstractDeclarativeValidator { } } private def variableLocal(EObject variable) { private def TTCN3Reference variableLocal(EObject variable) { val parentFunction = variable.findDesiredParent(FunctionDef) val parentAltStep = variable.findDesiredParent(AltstepDef) val parentComponent = variable.findDesiredParent(ComponentDef) val parentTestcase = variable.findDesiredParent(TestcaseDef) val parentControl = variable.findDesiredParent(ModuleControlBody) return ( parentFunction != null || parentAltStep != null || parentComponent != null || parentTestcase != null || parentControl != null) if (parentFunction != null) { return parentFunction } if (parentAltStep != null) { return parentAltStep } if (parentComponent != null) { return parentComponent } if (parentTestcase != null) { return parentTestcase } } @Check Loading de.ugoe.cs.swe.TTCN3/src/de/ugoe/cs/swe/validation/LogValidator.xtend +5 −4 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import org.eclipse.xtext.validation.EValidatorRegistrar import static extension de.ugoe.cs.swe.common.TTCN3ScopeHelper.* import static extension org.eclipse.xtext.EcoreUtil2.* import de.ugoe.cs.swe.tTCN3.ControlStatement // TODO: check not resolved external function references class LogValidator extends AbstractDeclarativeValidator { Loading Loading @@ -78,7 +79,7 @@ class LogValidator extends AbstractDeclarativeValidator { for (s : statements) { if (s instanceof FunctionStatement) { log = s.findLogStatement } else if (s instanceof ControlStatementOrDefList) { } else if (s instanceof ControlStatement) { log = s.findLogStatement } if (log != null) { Loading Loading @@ -109,9 +110,9 @@ class LogValidator extends AbstractDeclarativeValidator { } } private def LogStatement findLogStatement(ControlStatementOrDefList stm) { if (stm.def.control != null && stm.def.control.basic != null && stm.def.control.basic.log != null) { return stm.def.control.basic.log private def LogStatement findLogStatement(ControlStatement control) { if (control.basic != null && control.basic.log != null) { return control.basic.log } else { return null } Loading Loading
de.ugoe.cs.swe.TTCN3/src/de/ugoe/cs/swe/TTCN3.xtext +2 −2 Original line number Diff line number Diff line Loading @@ -215,10 +215,10 @@ ModuleControlPart: CONTROLKEYWORD LBRACKET body=ModuleControlBody RBRACKET ws=WithStatement? sc=SEMICOLON?; ModuleControlBody: {ModuleControlBody} list+=ControlStatementOrDefList*; {ModuleControlBody} list=ControlStatementOrDefList; ControlStatementOrDefList: def=ControlStatementOrDef sc=SEMICOLON?; {ControlStatementOrDefList} (((localDef+=FunctionLocalDef | localInst+=FunctionLocalInst) withstm+=WithStatement? | control+=ControlStatement) sc+=SEMICOLON)*; ControlStatementOrDef: (localDef=FunctionLocalDef | localInst=FunctionLocalInst) withstm=WithStatement? | control=ControlStatement; Loading
de.ugoe.cs.swe.TTCN3/src/de/ugoe/cs/swe/common/TTCN3ScopeHelper.xtend +8 −6 Original line number Diff line number Diff line Loading @@ -226,16 +226,18 @@ class TTCN3ScopeHelper { } def static void scopeModuleControlPart(ModuleControlPart control, ArrayList<EObject> list) { for (ControlStatementOrDefList o : control.body.list) { if (o.def.localDef != null && o.def.localDef.constDef != null) { val constDefList = o.def.localDef.constDef.defs as ConstList for (o : control.body.list.localDef) { if (o.constDef != null) { val constDefList = o.constDef.defs as ConstList for (SingleConstDef d : constDefList.list) { list.add(d); } } if (o.def.localInst != null && o.def.localInst.variable != null) { val varList = o.def.localInst.variable.list val tempList = o.def.localInst.variable.tempList } for (o : control.body.list.localInst) { if (o.variable != null) { val varList = o.variable.list val tempList = o.variable.tempList if (varList != null) { list.addAll(varList.variables); } Loading
de.ugoe.cs.swe.TTCN3/src/de/ugoe/cs/swe/scoping/TTCN3ScopeProvider.xtend +3 −3 Original line number Diff line number Diff line Loading @@ -319,9 +319,9 @@ class TTCN3ScopeProvider extends AbstractDeclarativeScopeProvider { } } } else if (parent instanceof ModuleControlBody) { for (ControlStatementOrDefList l : parent.list) { if (l.def.localInst != null && l.def.localInst.timer != null) { for (SingleVarInstance v : l.def.localInst.timer.list.variables) { for (i : parent.list.localInst) { if (i.timer != null) { for (SingleVarInstance v : i.timer.list.variables) { list.add(v) } } Loading
de.ugoe.cs.swe.TTCN3/src/de/ugoe/cs/swe/validation/CodeStyleValidator.xtend +160 −106 Original line number Diff line number Diff line Loading @@ -77,6 +77,7 @@ import org.eclipse.xtext.validation.EValidatorRegistrar import static extension de.ugoe.cs.swe.common.TTCN3ReferenceHelper.* import static extension de.ugoe.cs.swe.common.TTCN3ScopeHelper.* import static extension org.eclipse.xtext.EcoreUtil2.* import de.ugoe.cs.swe.tTCN3.PortInstance class CheckDefinitionComeFirstParameter { public boolean hasOtherDefinitions Loading Loading @@ -314,47 +315,64 @@ class CodeStyleValidator extends AbstractDeclarativeValidator { } @Check def checkLocalDefinitionsComeFirst(ModuleDefinition moduleDefinition) { def checkLocalDefinitionsComeFirst(SingleVarInstance variable) { // this considers timers, too if (!activeProfile.checkLocalDefinitionsComeFirst) return; val definition = moduleDefinition.def variable.checkLocalDefinitionsComeFirstAll } if (definition instanceof FunctionDef) { definition.statement.checkLocalDefinitionsComeFirst definition.statement.checkLocalDefinitionsComeFirstStatemanet } else if (definition instanceof TestcaseDef) { definition.statement.checkLocalDefinitionsComeFirst definition.statement.checkLocalDefinitionsComeFirstStatemanet } else if (definition instanceof AltstepDef) { definition.checkLocalDefinitionsComeFirstAltstepDef } else if (definition instanceof TypeDef) { if (definition.body.structured != null && definition.body.structured.component != null) { definition.body.structured.component.checkLocalDefinitionsComeFirstComponent @Check def checkLocalDefinitionsComeFirst(SingleConstDef variable) { if (!activeProfile.checkLocalDefinitionsComeFirst) return; variable.checkLocalDefinitionsComeFirstAll } @Check def checkLocalDefinitionsComeFirst(PortDef variable) { if (!activeProfile.checkLocalDefinitionsComeFirst) return; variable.checkLocalDefinitionsComeFirstAll } private def checkLocalDefinitionsComeFirstAll(TTCN3Reference definition) { val function = definition.findDesiredParent(FunctionDef) val altstep = definition.findDesiredParent(AltstepDef) val testcase = definition.findDesiredParent(TestcaseDef) val control = definition.findDesiredParent(ModuleControlBody) var lastDef = Integer.MIN_VALUE val line = NodeModelUtils.getNode(definition).startLine if (function != null) { if (function.statement != null && function.statement.def != null) { lastDef = NodeModelUtils.getNode(function.statement.def.last).startLine } } private def checkLocalDefinitionsComeFirst(StatementBlock statement) { var int firstStatement = Integer.MAX_VALUE; if (statement.stat.size > 0) { firstStatement = NodeModelUtils.getNode(statement.stat.get(0)).startLine if (testcase != null) { if (testcase.statement != null && testcase.statement.def != null) { lastDef = NodeModelUtils.getNode(testcase.statement.def.last).startLine } for (d : statement.def) { if (d.locDef != null && d.locDef.constDef != null) { d.locDef.constDef.checkDefinitionBeforeFirstOtherStatement(firstStatement) } else if (d.locInst != null && d.locInst.timer != null) { d.locInst.timer.checkDefinitionBeforeFirstOtherStatement(firstStatement) } else if (d.locInst != null && d.locInst.variable != null) { d.locInst.variable.checkDefinitionBeforeFirstOtherStatement(firstStatement) } if (altstep != null && altstep.local.defs != null) { lastDef = NodeModelUtils.getNode(altstep.local.defs.last).startLine } if (control != null && control.list.localDef != null) { lastDef = NodeModelUtils.getNode(control.list.localDef.last).startLine } private def checkDefinitionBeforeFirstOtherStatement(EObject object, int first) { var int line = NodeModelUtils.getNode(object).startLine if (line > first) { if (lastDef > Integer.MIN_VALUE && line > lastDef) { val message = "Local definition is not at the beginning!" var checkName = "checkLocalDefinitionsComeFirst" if (control != null) { checkName = "checkLocalDefinitionsComeFirstWithinControlPart" } statistics.incrementCountStyle warning( message, Loading @@ -362,11 +380,31 @@ class CodeStyleValidator extends AbstractDeclarativeValidator { MessageClass.STYLE.toString, line.toString, line.toString, "6.8, " + "checkLocalDefinitionsComeFirst" "6.8, " + checkName ); } } @Check def checkLocalDefinitionsComeFirst(ModuleDefinition moduleDefinition) { if (!activeProfile.checkLocalDefinitionsComeFirst) return; val definition = moduleDefinition.def if (definition instanceof FunctionDef) { definition.statement.checkLocalDefinitionsComeFirstStatemanet } else if (definition instanceof TestcaseDef) { definition.statement.checkLocalDefinitionsComeFirstStatemanet } else if (definition instanceof AltstepDef) { definition.checkLocalDefinitionsComeFirstAltstepDef } else if (definition instanceof TypeDef) { if (definition.body.structured != null && definition.body.structured.component != null) { definition.body.structured.component.checkLocalDefinitionsComeFirstComponent } } } private def checkLocalDefinitionsComeFirstStatemanet(StatementBlock statement) { val CheckDefinitionComeFirstParameter params = new CheckDefinitionComeFirstParameter for (d : statement.def) { Loading Loading @@ -693,7 +731,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator { null, MessageClass.STYLE.toString, node.startLine.toString, node.endLine.toString, node.startLine.toString, // only show the starting line "6.17, " + MiscTools.getMethodName() ); } Loading Loading @@ -804,7 +842,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator { null, MessageClass.STYLE.toString, node.startLine.toString, node.endLine.toString, node.startLine.toString, // only show the starting line "6.13, " + "checkNoOverSpecificRunsOnClauses" ); } Loading Loading @@ -1084,11 +1122,17 @@ class CodeStyleValidator extends AbstractDeclarativeValidator { } private def checkNoUnusedLocalDefinitionsAll(TTCN3Reference variable) { if (variable.variableLocal) { val parentControl = variable.findDesiredParent(ModuleControlBody) val parent = variable.variableLocal if (parent != null || parentControl != null) { val module = variable.findDesiredParent(TTCN3Module) if (variable.isUnreferenced(module)) { statistics.incrementCountStyle val message = "Local definition for \"" + variable.name + "\" in definition of \"" + module.name + var varName = "Module Control Part" if (parent != null) { varName = parent.name } val message = "Local definition for \"" + variable.name + "\" in definition of \"" + varName + "\" is never used!" val INode node = NodeModelUtils.getNode(variable) warning( Loading @@ -1103,15 +1147,25 @@ class CodeStyleValidator extends AbstractDeclarativeValidator { } } private def variableLocal(EObject variable) { private def TTCN3Reference variableLocal(EObject variable) { val parentFunction = variable.findDesiredParent(FunctionDef) val parentAltStep = variable.findDesiredParent(AltstepDef) val parentComponent = variable.findDesiredParent(ComponentDef) val parentTestcase = variable.findDesiredParent(TestcaseDef) val parentControl = variable.findDesiredParent(ModuleControlBody) return ( parentFunction != null || parentAltStep != null || parentComponent != null || parentTestcase != null || parentControl != null) if (parentFunction != null) { return parentFunction } if (parentAltStep != null) { return parentAltStep } if (parentComponent != null) { return parentComponent } if (parentTestcase != null) { return parentTestcase } } @Check Loading
de.ugoe.cs.swe.TTCN3/src/de/ugoe/cs/swe/validation/LogValidator.xtend +5 −4 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import org.eclipse.xtext.validation.EValidatorRegistrar import static extension de.ugoe.cs.swe.common.TTCN3ScopeHelper.* import static extension org.eclipse.xtext.EcoreUtil2.* import de.ugoe.cs.swe.tTCN3.ControlStatement // TODO: check not resolved external function references class LogValidator extends AbstractDeclarativeValidator { Loading Loading @@ -78,7 +79,7 @@ class LogValidator extends AbstractDeclarativeValidator { for (s : statements) { if (s instanceof FunctionStatement) { log = s.findLogStatement } else if (s instanceof ControlStatementOrDefList) { } else if (s instanceof ControlStatement) { log = s.findLogStatement } if (log != null) { Loading Loading @@ -109,9 +110,9 @@ class LogValidator extends AbstractDeclarativeValidator { } } private def LogStatement findLogStatement(ControlStatementOrDefList stm) { if (stm.def.control != null && stm.def.control.basic != null && stm.def.control.basic.log != null) { return stm.def.control.basic.log private def LogStatement findLogStatement(ControlStatement control) { if (control.basic != null && control.basic.log != null) { return control.basic.log } else { return null } Loading