Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added simple validator for dubiusly named single use variables #310

  • Loading branch information...
commit e7e37f14b5dceba13aaa408857106175f33a07fe 1 parent 2c366c2
@ujhelyiz authored
View
4 ...org.eclipse.incquery.patternlanguage/src/org/eclipse/incquery/patternlanguage/validation/IssueCodes.java
@@ -60,6 +60,6 @@ private IssueCodes() {
+ "local_variable_no_positive_reference";
public static final String ANONYM_VARIABLE_MULTIPLE_REFERENCE = ISSUE_CODE_PREFIX
+ "anonym_variable_multiple_reference";
+ public static final String DUBIUS_VARIABLE_NAME = ISSUE_CODE_PREFIX + "dubius_variable_name";
-
-}
+}
View
16 ...ry.patternlanguage/src/org/eclipse/incquery/patternlanguage/validation/PatternLanguageJavaValidator.java
@@ -162,7 +162,7 @@ public void checkApplicabilityOfTransitiveClosureInPatternCall(PatternCall call)
if (!typeConformance.isConformant(type1, type2) && !typeConformance.isConformant(type2, type1)) {
error(String.format(
"The parameter types %s and %s are not compatible, so no transitive references can exist in instance models.",
- type1.getSimpleName().toString(), type2.getSimpleName().toString()),
+ type1.getSimpleName(), type2.getSimpleName()),
PatternLanguagePackage.Literals.PATTERN_CALL__PARAMETERS,
IssueCodes.TRANSITIVE_PATTERNCALL_TYPE);
}
@@ -391,6 +391,20 @@ public void checkReturnTypeOfCheckConstraints(CheckConstraint checkConstraint) {
}
@Check
+ public void checkVariableNames(PatternBody body) {
+ for (Variable var1 : body.getVariables()) {
+ for (Variable var2 : body.getVariables()) {
+ if (isNamedSingleUse(var1) && var1.getSimpleName().substring(1).equals(var2.getName())) {
+ 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);
+ }
+ }
+ }
+ }
+
+ @Check
public void checkVariableUsageCounters(PatternBody body) {
Map<Variable, VariableReferenceCount> refCounters = calculateUsageCounts(body);
UnionFindForVariables variableUnions = calculateEqualVariables(body);
View
25 ...nlanguage.emf.tests/src/org/eclipse/incquery/patternlanguage/emf/tests/basic/PatternValidationTest.xtend
@@ -78,5 +78,28 @@ class PatternValidationTest extends AbstractValidatorTest {
')
tester.validate(model).assertError(EMFIssueCodes::SINGLEUSE_PARAMETER)
}
-
+
+ @Test
+ def dubiusSingleUseVariable() {
+ val model = parseHelper.parse('''
+ import "http://www.eclipse.org/incquery/patternlanguage/PatternLanguage"
+ pattern unusedPrivatePattern(p) {
+ Pattern(p);
+ Pattern.name(p, _p);
+ }
+ ''')
+ tester.validate(model).assertWarning(IssueCodes::DUBIUS_VARIABLE_NAME)
+ }
+
+ @Test
+ def dubiusSingleUseVariableCapitalization() {
+ val model = parseHelper.parse('''
+ import "http://www.eclipse.org/incquery/patternlanguage/PatternLanguage"
+ pattern unusedPrivatePattern(p) {
+ Pattern(p);
+ Pattern.name(p, _P);
+ }
+ ''')
+ tester.validate(model).assertOK
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.