Permalink
Browse files

Fixed incorrect marker location #310

  • Loading branch information...
1 parent 4950557 commit 37d6692939ebf35af625670a272f085b0a06c9ed @ujhelyiz ujhelyiz committed Jan 7, 2013
@@ -393,12 +393,25 @@ public void checkReturnTypeOfCheckConstraints(CheckConstraint checkConstraint) {
@Check
public void checkVariableNames(PatternBody body) {
for (Variable var1 : body.getVariables()) {
+ Variable otherVar = null;
for (Variable var2 : body.getVariables()) {
if (isNamedSingleUse(var1) && var1.getSimpleName().substring(1).equals(var2.getName())) {
+ otherVar = var2;
+ }
+ }
+ if (otherVar != null) {
+ if (var1.eContainer() instanceof PatternBody && !var1.getReferences().isEmpty()) {
+ // Local variables do not have source location
warning(String.format(
"Dubius variable naming: Single use variable %s shares its name with the variable %s",
- var1.getSimpleName(), var2.getSimpleName()), var1,
- PatternLanguagePackage.Literals.VARIABLE__NAME, IssueCodes.DUBIUS_VARIABLE_NAME);
+ var1.getSimpleName(), otherVar.getSimpleName()), var1.getReferences().get(0),
+ PatternLanguagePackage.Literals.VARIABLE_REFERENCE__VARIABLE,
+ IssueCodes.DUBIUS_VARIABLE_NAME);
+ } else {
+ warning(String.format(
+ "Dubius variable naming: Single use variable %s shares its name with the variable %s",
+ var1.getSimpleName(), otherVar.getSimpleName()), var1,
+ PatternLanguagePackage.Literals.VARIABLE__NAME, IssueCodes.DUBIUS_VARIABLE_NAME);
}
}
}

0 comments on commit 37d6692

Please sign in to comment.