diff --git a/.project b/.project
deleted file mode 100644
index 47e71900..00000000
--- a/.project
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
- sonar-esql-plugin
- Plugin to analyse ESQL-code (for IBM WebSphere Message Broker). NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- org.eclipse.m2e.core.maven2Builder
-
-
-
-
-
- org.eclipse.m2e.core.maven2Nature
- org.eclipse.jdt.core.javanature
-
-
diff --git a/esql-checks/pom.xml b/esql-checks/pom.xml
index a8290bad..acc196b9 100644
--- a/esql-checks/pom.xml
+++ b/esql-checks/pom.xml
@@ -61,5 +61,4 @@
-
diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/NavigatingTreeCouldBeReferenceCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/NavigatingTreeCouldBeReferenceCheck.java
index 55254a03..537dcf27 100644
--- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/NavigatingTreeCouldBeReferenceCheck.java
+++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/NavigatingTreeCouldBeReferenceCheck.java
@@ -45,12 +45,19 @@ public class NavigatingTreeCouldBeReferenceCheck extends DoubleDispatchVisitorCh
private static final String MESSAGE = "Navigating message tree could be replaced by a reference.";
- private static final int DEFAULT_THRESHOLD = 3;
+ private static final int DEFAULT_ALLOWED_NUMBER_OF_FIELD_REFERENCE_USES = 2;
@RuleProperty(
- key = "NavigatingTreeCouldBeReference",
- description = "Navigating message tree could be replaced by a reference.",
- defaultValue = "" + DEFAULT_THRESHOLD)
- public int threshold = DEFAULT_THRESHOLD;
+ key = "AllowedNumberOfReferences",
+ description = "The maximum allowed number of reused field references. Issues will only created if a field reference is used more often.",
+ defaultValue = "" + DEFAULT_ALLOWED_NUMBER_OF_FIELD_REFERENCE_USES)
+ public int allowedNumberOfFieldReferenceUses = DEFAULT_ALLOWED_NUMBER_OF_FIELD_REFERENCE_USES;
+
+ private static final int DEFAULT_MAXIMUM_ALLOWED_PATH_ELEMENTS = 2;
+ @RuleProperty(
+ key = "MaximumAllowedPathElements",
+ description = "The number of allowed of path elements in a field reference for which no reference will be suggested. Issues will only be created for field references with more path elements.",
+ defaultValue = "" + DEFAULT_MAXIMUM_ALLOWED_PATH_ELEMENTS)
+ public int maximumAllowedPathElements = DEFAULT_MAXIMUM_ALLOWED_PATH_ELEMENTS;
private final Multimap occurrences = ArrayListMultimap.create();
@@ -77,6 +84,7 @@ public void visitProgram(ProgramTree tree) {
super.visitProgram(tree);
List sortedKeys = occurrences.keySet().stream()
+ .filter(a -> StringUtils.countMatches(a, ".") + 1 > maximumAllowedPathElements)
.sorted((k1, k2) -> StringUtils.countMatches(k2, ".") - StringUtils.countMatches(k1, "."))
.collect(Collectors.toList());
@@ -84,7 +92,7 @@ public void visitProgram(ProgramTree tree) {
for (String entry : sortedKeys) {
Collection fieldReferenceTrees = occurrences.get(entry);
- if (fieldReferenceTrees.size() > threshold) {
+ if (fieldReferenceTrees.size() > allowedNumberOfFieldReferenceUses) {
boolean alreadyIssued = false;
for (String issueKey : issueKeys) {
if (issueKey.startsWith(entry + ".")) {
diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/NavigatingTreeCouldBeReferenceCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/NavigatingTreeCouldBeReferenceCheckTest.java
index 5c52469f..dced3b73 100644
--- a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/NavigatingTreeCouldBeReferenceCheckTest.java
+++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/NavigatingTreeCouldBeReferenceCheckTest.java
@@ -6,9 +6,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,28 +16,37 @@
* limitations under the License.
*/
package com.exxeta.iss.sonar.esql.check;
-import java.io.File;
+import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
import org.junit.Test;
-import com.exxeta.iss.sonar.esql.api.EsqlCheck;
-import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier;
+import java.io.File;
+
/**
- * This java class is the test class for NavigatingTreeCouldBeReferenceCheck.java.
- * @author Sapna. singh
+ * This java class is the test class for NavigatingTreeCouldBeReferenceCheck.java.
*
+ * @author Sapna. singh
*/
public class NavigatingTreeCouldBeReferenceCheckTest {
-
- @Test
- public void test() {
- EsqlCheck check = new NavigatingTreeCouldBeReferenceCheck();
- EsqlCheckVerifier.issues(check, new File("src/test/resources/NavigatingTreeCouldBeReference.esql"))
- .next().atLine(4).withMessage("Navigating message tree could be replaced by a reference.")
- .next().atLine(16).withMessage("Navigating message tree could be replaced by a reference.")
- .next().atLine(16).withMessage("Navigating message tree could be replaced by a reference.")
- .noMore();
- }
+
+ @Test
+ public void test() {
+ NavigatingTreeCouldBeReferenceCheck check = new NavigatingTreeCouldBeReferenceCheck();
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/NavigatingTreeCouldBeReference.esql"))
+ .next().atLine(4).withMessage("Navigating message tree could be replaced by a reference.")
+ .next().atLine(16).withMessage("Navigating message tree could be replaced by a reference.")
+ .next().atLine(16).withMessage("Navigating message tree could be replaced by a reference.")
+ .noMore();
+ check.maximumAllowedPathElements = 3;
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/NavigatingTreeCouldBeReference.esql"))
+ .next().atLine(4).withMessage("Navigating message tree could be replaced by a reference.")
+ .noMore();
+ check.maximumAllowedPathElements = 2;
+ check.allowedNumberOfFieldReferenceUses = 4;
+ EsqlCheckVerifier.issues(check, new File("src/test/resources/NavigatingTreeCouldBeReference.esql"))
+ .next().atLine(16).withMessage("Navigating message tree could be replaced by a reference.")
+ .noMore();
+ }
}
diff --git a/esql-plugin/.project b/esql-plugin/.project
deleted file mode 100644
index fea5af02..00000000
--- a/esql-plugin/.project
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
- esql-plugin
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- org.eclipse.m2e.core.maven2Builder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
- org.eclipse.m2e.core.maven2Nature
-
-