Commit 023da2e4 authored by Kristof Szabados's avatar Kristof Szabados
Browse files

could be final.


Signed-off-by: Kristof Szabados's avatarKristof Szabados <Kristof.Szabados@ericsson.com>
parent e93c6170
...@@ -46,7 +46,7 @@ public class DefinitionNameTooLong extends BaseModuleCodeSmellSpotter{ ...@@ -46,7 +46,7 @@ public class DefinitionNameTooLong extends BaseModuleCodeSmellSpotter{
public void process(final IVisitableNode node, final Problems problems) { public void process(final IVisitableNode node, final Problems problems) {
if (node instanceof Definition) { if (node instanceof Definition) {
final Definition s = (Definition) node; final Definition s = (Definition) node;
int lengthOfFunctionName=s.getIdentifier().getDisplayName().length(); final int lengthOfFunctionName = s.getIdentifier().getDisplayName().length();
if(lengthOfFunctionName>recommendedLenghtOfFunctionName){ if(lengthOfFunctionName>recommendedLenghtOfFunctionName){
final String msg = MessageFormat.format(WARNING_MESSAGE, final String msg = MessageFormat.format(WARNING_MESSAGE,
lengthOfFunctionName, recommendedLenghtOfFunctionName); lengthOfFunctionName, recommendedLenghtOfFunctionName);
......
...@@ -94,11 +94,11 @@ final class SuspiciouslyUsedIf extends ASTVisitor { ...@@ -94,11 +94,11 @@ final class SuspiciouslyUsedIf extends ASTVisitor {
for (final If_Clause clause : ifs) { for (final If_Clause clause : ifs) {
final Value cond = clause.getExpression(); final Value cond = clause.getExpression();
if (cond != null) { if (cond != null) {
ReferenceCollector refCollector = new ReferenceCollector(); final ReferenceCollector refCollector = new ReferenceCollector();
redirectValue.accept(refCollector); redirectValue.accept(refCollector);
ArrayList<Reference> foundReferences = refCollector.getReferences(); final ArrayList<Reference> foundReferences = refCollector.getReferences();
for (Reference reference : foundReferences) { for (final Reference reference : foundReferences) {
final RefUsedInMatching mv = new RefUsedInMatching(reference); final RefUsedInMatching mv = new RefUsedInMatching(reference);
cond.accept(mv); cond.accept(mv);
if (mv.getUsed()) { if (mv.getUsed()) {
......
...@@ -59,8 +59,8 @@ public class InvokingFunctionsFromSpecificPlaces extends BaseModuleCodeSmellSpot ...@@ -59,8 +59,8 @@ public class InvokingFunctionsFromSpecificPlaces extends BaseModuleCodeSmellSpot
@Override @Override
public int visit(final IVisitableNode node) { public int visit(final IVisitableNode node) {
if(node instanceof Referenced_Value) { if(node instanceof Referenced_Value) {
Referenced_Value value = (Referenced_Value) node; final Referenced_Value value = (Referenced_Value) node;
Assignment_type asst = value.getReference().getAssOld().getAssignmentType(); final Assignment_type asst = value.getReference().getAssOld().getAssignmentType();
if (asst == Assignment_type.A_FUNCTION_RVAL || if (asst == Assignment_type.A_FUNCTION_RVAL ||
asst == Assignment_type.A_EXT_FUNCTION_RVAL || asst == Assignment_type.A_EXT_FUNCTION_RVAL ||
asst == Assignment_type.A_FUNCTION_RTEMP || asst == Assignment_type.A_FUNCTION_RTEMP ||
...@@ -70,26 +70,26 @@ public class InvokingFunctionsFromSpecificPlaces extends BaseModuleCodeSmellSpot ...@@ -70,26 +70,26 @@ public class InvokingFunctionsFromSpecificPlaces extends BaseModuleCodeSmellSpot
} }
if(node instanceof RNDExpression || node instanceof RNDWithValueExpression ) { if(node instanceof RNDExpression || node instanceof RNDWithValueExpression ) {
Expression_Value exp = (Expression_Value) node; final Expression_Value exp = (Expression_Value) node;
problems.report(exp.getLocation(), "Random number generation change the actual snapshot"); problems.report(exp.getLocation(), "Random number generation change the actual snapshot");
} }
if(node instanceof AllComponentAliveExpression || node instanceof AllComponentRunningExpression || if(node instanceof AllComponentAliveExpression || node instanceof AllComponentRunningExpression ||
node instanceof AnyComponentAliveExpression || node instanceof AnyComponentRunningExpression || node instanceof AnyComponentAliveExpression || node instanceof AnyComponentRunningExpression ||
node instanceof ComponentAliveExpression || node instanceof ComponentRunningExpression ) { node instanceof ComponentAliveExpression || node instanceof ComponentRunningExpression ) {
Expression_Value exp = (Expression_Value) node; final Expression_Value exp = (Expression_Value) node;
problems.report(exp.getLocation(), "State of component may change during the actual snapshot"); problems.report(exp.getLocation(), "State of component may change during the actual snapshot");
} }
if(node instanceof AnyPortCheckStateExpression ||node instanceof AllPortCheckSateExpression || node instanceof CheckStateExpression) { if(node instanceof AnyPortCheckStateExpression ||node instanceof AllPortCheckSateExpression || node instanceof CheckStateExpression) {
Expression_Value exp = (Expression_Value) node; final Expression_Value exp = (Expression_Value) node;
problems.report(exp.getLocation(), "State of port may change during the actual snapshot"); problems.report(exp.getLocation(), "State of port may change during the actual snapshot");
} }
if(node instanceof AnyTimerRunningExpression || if(node instanceof AnyTimerRunningExpression ||
node instanceof TimerRunningExpression || node instanceof TimerRunningExpression ||
node instanceof TimerReadExpression) { node instanceof TimerReadExpression) {
Expression_Value exp = (Expression_Value) node; final Expression_Value exp = (Expression_Value) node;
problems.report(exp.getLocation(), "State of timer may change during the actual snapshot"); problems.report(exp.getLocation(), "State of timer may change during the actual snapshot");
} }
return V_CONTINUE; return V_CONTINUE;
...@@ -99,7 +99,7 @@ public class InvokingFunctionsFromSpecificPlaces extends BaseModuleCodeSmellSpot ...@@ -99,7 +99,7 @@ public class InvokingFunctionsFromSpecificPlaces extends BaseModuleCodeSmellSpot
@Override @Override
public void process(final IVisitableNode node, final Problems problems) { public void process(final IVisitableNode node, final Problems problems) {
FunctionVisitor visitor = new FunctionVisitor(problems); final FunctionVisitor visitor = new FunctionVisitor(problems);
if (node instanceof AltGuard) { if (node instanceof AltGuard) {
final AltGuard altGuard = (AltGuard) node; final AltGuard altGuard = (AltGuard) node;
......
...@@ -50,7 +50,7 @@ public class LanguageMixing extends BaseProjectCodeSmellSpotter { ...@@ -50,7 +50,7 @@ public class LanguageMixing extends BaseProjectCodeSmellSpotter {
final Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames(); final Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
final List<TTCN3Module> modules = new ArrayList<TTCN3Module>(); final List<TTCN3Module> modules = new ArrayList<TTCN3Module>();
for (final String moduleName : new TreeSet<String>(knownModuleNames)) { for (final String moduleName : new TreeSet<String>(knownModuleNames)) {
Module module = projectSourceParser.getModuleByName(moduleName); final Module module = projectSourceParser.getModuleByName(moduleName);
if(module instanceof TTCN3Module) { if(module instanceof TTCN3Module) {
modules.add((TTCN3Module) module); modules.add((TTCN3Module) module);
} }
...@@ -65,10 +65,10 @@ public class LanguageMixing extends BaseProjectCodeSmellSpotter { ...@@ -65,10 +65,10 @@ public class LanguageMixing extends BaseProjectCodeSmellSpotter {
String lastLanguage = null; String lastLanguage = null;
TTCN3Module lastModule = null; TTCN3Module lastModule = null;
for (TTCN3Module module: modules) { for (final TTCN3Module module: modules) {
List<String> languageSpecifications = module.getLanguageSpecifictions(); final List<String> languageSpecifications = module.getLanguageSpecifictions();
if(languageSpecifications != null && languageSpecifications.size() > 0) { if(languageSpecifications != null && languageSpecifications.size() > 0) {
String tempLanguage = languageSpecifications.get(0); final String tempLanguage = languageSpecifications.get(0);
if(tempLanguage != null) { if(tempLanguage != null) {
if(lastLanguage == null) { if(lastLanguage == null) {
lastLanguage = tempLanguage; lastLanguage = tempLanguage;
......
...@@ -81,7 +81,7 @@ public class RunsOnScopeReduction extends BaseModuleCodeSmellSpotter{ ...@@ -81,7 +81,7 @@ public class RunsOnScopeReduction extends BaseModuleCodeSmellSpotter{
if (definitions.isEmpty()) { if (definitions.isEmpty()) {
if (isTestCase) { if (isTestCase) {
List<Definition> attributes = componentType.getComponentBody().getDefinitions(); final List<Definition> attributes = componentType.getComponentBody().getDefinitions();
if (!attributes.isEmpty()) { if (!attributes.isEmpty()) {
problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used. Use empty component.",componentIdentifier.getDisplayName())); problems.report(identifier.getLocation(), MessageFormat.format("The runs on component `{0}'' seems to be never used. Use empty component.",componentIdentifier.getDisplayName()));
} }
...@@ -111,7 +111,7 @@ public class RunsOnScopeReduction extends BaseModuleCodeSmellSpotter{ ...@@ -111,7 +111,7 @@ public class RunsOnScopeReduction extends BaseModuleCodeSmellSpotter{
} }
final Set<Identifier> setNodes = new HashSet<Identifier>(); final Set<Identifier> setNodes = new HashSet<Identifier>();
setNodes.add(component.getIdentifier()); setNodes.add(component.getIdentifier());
for (ComponentTypeBody variable : parentComponentBodies) { for (final ComponentTypeBody variable : parentComponentBodies) {
final Set<Identifier> identifiersOfNode = new HashSet<Identifier>(); final Set<Identifier> identifiersOfNode = new HashSet<Identifier>();
final ComponentTypeBody cb = searchComponent(variable, definitions, identifiersOfNode); final ComponentTypeBody cb = searchComponent(variable, definitions, identifiersOfNode);
if (cb != null) { if (cb != null) {
......
...@@ -79,9 +79,9 @@ public class SelectUnion extends BaseModuleCodeSmellSpotter { ...@@ -79,9 +79,9 @@ public class SelectUnion extends BaseModuleCodeSmellSpotter {
// Check the union, get the types. // Check the union, get the types.
final UnionItemVisitor unionVisitor = new UnionItemVisitor(); final UnionItemVisitor unionVisitor = new UnionItemVisitor();
List<Identifier> foundIds = new ArrayList<Identifier>(); final List<Identifier> foundIds = new ArrayList<Identifier>();
for(Reference ref : caseVisitor.getReferenceList()){ for(final Reference ref : caseVisitor.getReferenceList()){
List<ISubReference> reflist = ref.getSubreferences(); final List<ISubReference> reflist = ref.getSubreferences();
if(reflist.isEmpty()){ if(reflist.isEmpty()){
continue; continue;
} }
...@@ -96,11 +96,11 @@ public class SelectUnion extends BaseModuleCodeSmellSpotter { ...@@ -96,11 +96,11 @@ public class SelectUnion extends BaseModuleCodeSmellSpotter {
caseVisitor.getUnionType().accept(unionVisitor); caseVisitor.getUnionType().accept(unionVisitor);
// Check if the found types are the same as the union types. // Check if the found types are the same as the union types.
List<Identifier> unionItems = unionVisitor.getItemsFound(); final List<Identifier> unionItems = unionVisitor.getItemsFound();
if(unionItems.isEmpty()){ if(unionItems.isEmpty()){
return; return;
} }
for(Identifier item : unionItems){ for(final Identifier item : unionItems){
foundIds.remove(item); foundIds.remove(item);
} }
if(foundIds.isEmpty()){ if(foundIds.isEmpty()){
...@@ -142,13 +142,13 @@ public class SelectUnion extends BaseModuleCodeSmellSpotter { ...@@ -142,13 +142,13 @@ public class SelectUnion extends BaseModuleCodeSmellSpotter {
return V_CONTINUE; return V_CONTINUE;
} else if (node instanceof TemplateInstance) { } else if (node instanceof TemplateInstance) {
final TemplateInstance ti = (TemplateInstance)node; final TemplateInstance ti = (TemplateInstance)node;
IValue val = ti.getTemplateBody().getValue(); final IValue val = ti.getTemplateBody().getValue();
if (val == null || val.getIsErroneous(timestamp) || !(val instanceof IsChoosenExpression)) { if (val == null || val.getIsErroneous(timestamp) || !(val instanceof IsChoosenExpression)) {
errorDuringVisiting = true; errorDuringVisiting = true;
return V_ABORT; return V_ABORT;
} }
IsChoosenExpression expr = (IsChoosenExpression)val; final IsChoosenExpression expr = (IsChoosenExpression)val;
final IsChoosenItemVisitor itemVisitor = new IsChoosenItemVisitor(); final IsChoosenItemVisitor itemVisitor = new IsChoosenItemVisitor();
expr.accept(itemVisitor); expr.accept(itemVisitor);
if(itemVisitor.getReference() == null){ if(itemVisitor.getReference() == null){
...@@ -210,9 +210,9 @@ public class SelectUnion extends BaseModuleCodeSmellSpotter { ...@@ -210,9 +210,9 @@ public class SelectUnion extends BaseModuleCodeSmellSpotter {
} else if (node instanceof WithAttributesPath) { } else if (node instanceof WithAttributesPath) {
return V_CONTINUE; return V_CONTINUE;
} else if (node instanceof CompFieldMap){ } else if (node instanceof CompFieldMap){
CompFieldMap cm = (CompFieldMap) node; final CompFieldMap cm = (CompFieldMap) node;
Map<String, CompField> map = cm.getComponentFieldMap(timestamp); final Map<String, CompField> map = cm.getComponentFieldMap(timestamp);
for(Map.Entry<String, CompField> entry : map.entrySet()) { for(final Map.Entry<String, CompField> entry : map.entrySet()) {
itemsFound.add(entry.getValue().getIdentifier()); itemsFound.add(entry.getValue().getIdentifier());
} }
return V_CONTINUE; return V_CONTINUE;
......
...@@ -45,23 +45,23 @@ public class UnusedGlobalDefinition extends BaseProjectCodeSmellSpotter { ...@@ -45,23 +45,23 @@ public class UnusedGlobalDefinition extends BaseProjectCodeSmellSpotter {
final Set<Assignment> unused = new HashSet<Assignment>(); final Set<Assignment> unused = new HashSet<Assignment>();
for (final String moduleName : new TreeSet<String>(knownModuleNames)) { for (final String moduleName : new TreeSet<String>(knownModuleNames)) {
Module module = projectSourceParser.getModuleByName(moduleName); final Module module = projectSourceParser.getModuleByName(moduleName);
modules.add(module); modules.add(module);
final GlobalDefinitionCheck chek = new GlobalDefinitionCheck(); final GlobalDefinitionCheck chek = new GlobalDefinitionCheck();
module.accept(chek); module.accept(chek);
unused.addAll(chek.getDefinitions()); unused.addAll(chek.getDefinitions());
} }
for (Module module : modules) { for (final Module module : modules) {
final GlobalUsedDefinitionCheck chekUsed = new GlobalUsedDefinitionCheck(); final GlobalUsedDefinitionCheck chekUsed = new GlobalUsedDefinitionCheck();
module.accept(chekUsed); module.accept(chekUsed);
Set<Assignment> used = chekUsed.getDefinitions(); final Set<Assignment> used = chekUsed.getDefinitions();
//remove from the unused list items that are referenced //remove from the unused list items that are referenced
unused.removeAll(used); unused.removeAll(used);
//remove from the unused list undefined items who's real version is referenced //remove from the unused list undefined items who's real version is referenced
final ArrayList<Assignment> tobeRemoved = new ArrayList<Assignment>(); final ArrayList<Assignment> tobeRemoved = new ArrayList<Assignment>();
for (Assignment assignment : unused) { for (final Assignment assignment : unused) {
if (assignment instanceof Undefined_Assignment) { if (assignment instanceof Undefined_Assignment) {
final Assignment realAssignment = ((Undefined_Assignment)assignment).getRealAssignment(CompilationTimeStamp.getBaseTimestamp()); final Assignment realAssignment = ((Undefined_Assignment)assignment).getRealAssignment(CompilationTimeStamp.getBaseTimestamp());
if (used.contains(realAssignment)) { if (used.contains(realAssignment)) {
...@@ -72,7 +72,7 @@ public class UnusedGlobalDefinition extends BaseProjectCodeSmellSpotter { ...@@ -72,7 +72,7 @@ public class UnusedGlobalDefinition extends BaseProjectCodeSmellSpotter {
unused.removeAll(tobeRemoved); unused.removeAll(tobeRemoved);
} }
for (Assignment ass : unused) { for (final Assignment ass : unused) {
final String name = ass.getIdentifier().getDisplayName(); final String name = ass.getIdentifier().getDisplayName();
final String msg = MessageFormat.format("The {0} `{1}'' seems to be never used globally", ass.getAssignmentName(), name); final String msg = MessageFormat.format("The {0} `{1}'' seems to be never used globally", ass.getAssignmentName(), name);
problems.report(ass.getIdentifier().getLocation(), msg); problems.report(ass.getIdentifier().getLocation(), msg);
......
...@@ -46,13 +46,13 @@ public class UnusedImportsProject extends BaseProjectCodeSmellSpotter{ ...@@ -46,13 +46,13 @@ public class UnusedImportsProject extends BaseProjectCodeSmellSpotter{
final Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames(); final Set<String> knownModuleNames = projectSourceParser.getKnownModuleNames();
final List<Module> modules = new ArrayList<Module>(); final List<Module> modules = new ArrayList<Module>();
for (final String moduleName : new TreeSet<String>(knownModuleNames)) { for (final String moduleName : new TreeSet<String>(knownModuleNames)) {
Module module = projectSourceParser.getModuleByName(moduleName); final Module module = projectSourceParser.getModuleByName(moduleName);
modules.add(module); modules.add(module);
} }
final Set<Module> setOfImportedModules = new HashSet<Module>(); final Set<Module> setOfImportedModules = new HashSet<Module>();
for (Module module : modules) { for (final Module module : modules) {
setOfImportedModules.clear(); setOfImportedModules.clear();
setOfImportedModules.addAll( module.getImportedModules()); setOfImportedModules.addAll( module.getImportedModules());
...@@ -62,9 +62,9 @@ public class UnusedImportsProject extends BaseProjectCodeSmellSpotter{ ...@@ -62,9 +62,9 @@ public class UnusedImportsProject extends BaseProjectCodeSmellSpotter{
setOfImportedModules.removeAll(check.getModules()); setOfImportedModules.removeAll(check.getModules());
if (module instanceof TTCN3Module) { if (module instanceof TTCN3Module) {
for (ImportModule mod : ((TTCN3Module)module).getImports()){ for (final ImportModule mod : ((TTCN3Module)module).getImports()){
final Identifier importIdentifier = mod.getIdentifier(); final Identifier importIdentifier = mod.getIdentifier();
for (Module m : setOfImportedModules) { for (final Module m : setOfImportedModules) {
if(m.getIdentifier().equals(importIdentifier)) { if(m.getIdentifier().equals(importIdentifier)) {
problems.report(importIdentifier.getLocation(), "Possibly unused importation"); problems.report(importIdentifier.getLocation(), "Possibly unused importation");
} }
...@@ -73,9 +73,9 @@ public class UnusedImportsProject extends BaseProjectCodeSmellSpotter{ ...@@ -73,9 +73,9 @@ public class UnusedImportsProject extends BaseProjectCodeSmellSpotter{
} else { } else {
final ModuleImportsCheck importsCheck = new ModuleImportsCheck(); final ModuleImportsCheck importsCheck = new ModuleImportsCheck();
module.accept(importsCheck); module.accept(importsCheck);
for (ModuleImportation im : importsCheck.getImports()) { for (final ModuleImportation im : importsCheck.getImports()) {
final Identifier importIdentifier = im.getIdentifier(); final Identifier importIdentifier = im.getIdentifier();
for (Module m : setOfImportedModules) { for (final Module m : setOfImportedModules) {
if(m.getIdentifier().equals(importIdentifier)) { if(m.getIdentifier().equals(importIdentifier)) {
problems.report(importIdentifier.getLocation(), "Possibly unused importation"); problems.report(importIdentifier.getLocation(), "Possibly unused importation");
} }
...@@ -131,7 +131,7 @@ public class UnusedImportsProject extends BaseProjectCodeSmellSpotter{ ...@@ -131,7 +131,7 @@ public class UnusedImportsProject extends BaseProjectCodeSmellSpotter{
@Override @Override
public int visit(final IVisitableNode node) { public int visit(final IVisitableNode node) {
if(node instanceof ModuleImportation){ if(node instanceof ModuleImportation){
ModuleImportation mod = (ModuleImportation) node; final ModuleImportation mod = (ModuleImportation) node;
setOfModules.add(mod); setOfModules.add(mod);
} }
return V_CONTINUE; return V_CONTINUE;
......
...@@ -46,7 +46,7 @@ public class UnusedLocalDefinition extends BaseModuleCodeSmellSpotter { ...@@ -46,7 +46,7 @@ public class UnusedLocalDefinition extends BaseModuleCodeSmellSpotter {
node.accept(chekUsed); node.accept(chekUsed);
unused.removeAll(chekUsed.getDefinitions()); unused.removeAll(chekUsed.getDefinitions());
for (Assignment ass : unused) { for (final Assignment ass : unused) {
final String name = ass.getIdentifier().getDisplayName(); final String name = ass.getIdentifier().getDisplayName();
final String msg = MessageFormat.format("The {0} `{1}'' seems to be never used locally (new)", ass.getAssignmentName(), name); final String msg = MessageFormat.format("The {0} `{1}'' seems to be never used locally (new)", ass.getAssignmentName(), name);
problems.report(ass.getIdentifier().getLocation(), msg); problems.report(ass.getIdentifier().getLocation(), msg);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment