diff --git a/README.md b/README.md
index 9f1ba32..c9a13a1 100644
--- a/README.md
+++ b/README.md
@@ -24,11 +24,11 @@ The code changes in a local Git working tree are inspected and not covered metho
This is useful for local development iterations before pushing the changes to a remote repository and starting a CI build.
```DOS .bat
-mvn com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1-SNAPSHOT:clean-jacoco-reports^
+mvn com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1:clean-jacoco-reports^
jacoco:prepare-agent^
surefire:test^
jacoco:report^
- com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1-SNAPSHOT:perform
+ com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1:perform
```
By also adding `jacoco:prepare-agent-integration`, `failsafe:integration-test` and `jacoco:report-integration` integration tests are also considered (method coverages of all JaCoCo reports are merged).
diff --git a/pom.xml b/pom.xml
index 4fdda7e..fcef456 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.scheible.testgapanalysis
test-gap-analysis-parent
- 1.2.1-SNAPSHOT
+ 1.2.1
pom
com.scheible::test-gap-analysis
diff --git a/test-gap-analysis-maven-plugin/pom.xml b/test-gap-analysis-maven-plugin/pom.xml
index e3a3123..0f8f60e 100644
--- a/test-gap-analysis-maven-plugin/pom.xml
+++ b/test-gap-analysis-maven-plugin/pom.xml
@@ -5,12 +5,12 @@
com.scheible.testgapanalysis
test-gap-analysis-parent
- 1.2.1-SNAPSHOT
+ 1.2.1
com.scheible.testgapanalysis
test-gap-analysis-maven-plugin
- 1.2.1-SNAPSHOT
+ 1.2.1
maven-plugin
com.scheible::test-gap-analysis maven-plugin
@@ -21,7 +21,7 @@
UTF-8
- 1.2.1-SNAPSHOT
+ 1.2.1
diff --git a/test-gap-analysis/nbactions.xml b/test-gap-analysis/nbactions.xml
index 87c87d5..2c32cbe 100644
--- a/test-gap-analysis/nbactions.xml
+++ b/test-gap-analysis/nbactions.xml
@@ -220,22 +220,22 @@
CUSTOM-Test Gap Analysis of Working Tree Changes
Test Gap Analysis of Working Tree Changes
- com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1-SNAPSHOT:clean-jacoco-reports
+ com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1:clean-jacoco-reports
jacoco:prepare-agent
surefire:test
jacoco:report
- com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1-SNAPSHOT:perform
+ com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1:perform
CUSTOM-Test Gap Analysis with Reference Commit
Test Gap Analysis with Reference Commit
- com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1-SNAPSHOT:clean-jacoco-reports
+ com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1:clean-jacoco-reports
jacoco:prepare-agent
surefire:test
jacoco:report
- com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1-SNAPSHOT:perform
+ com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1:perform
30640f01d7c116ca0d75ce9285357e5a8053009e
@@ -245,11 +245,11 @@
CUSTOM-Test Gap Analysis with Previous Tag RegEx
Test Gap Analysis with Previous Tag RegEx
- com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1-SNAPSHOT:clean-jacoco-reports
+ com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1:clean-jacoco-reports
jacoco:prepare-agent
surefire:test
jacoco:report
- com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1-SNAPSHOT:perform
+ com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1:perform
[0-9]+\.[0-9]+\.[0-9]+
@@ -259,11 +259,11 @@
CUSTOM-Debug Coverage Resolution
Debug Coverage Resolution
- com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1-SNAPSHOT:clean-jacoco-reports
+ com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1:clean-jacoco-reports
jacoco:prepare-agent
surefire:test
jacoco:report
- com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1-SNAPSHOT:debug-coverage-resolution
+ com.scheible.testgapanalysis:test-gap-analysis-maven-plugin:1.2.1:debug-coverage-resolution
diff --git a/test-gap-analysis/pom.xml b/test-gap-analysis/pom.xml
index d6c30a2..45b1003 100644
--- a/test-gap-analysis/pom.xml
+++ b/test-gap-analysis/pom.xml
@@ -5,12 +5,12 @@
com.scheible.testgapanalysis
test-gap-analysis-parent
- 1.2.1-SNAPSHOT
+ 1.2.1
com.scheible.testgapanalysis
test-gap-analysis
- 1.2.1-SNAPSHOT
+ 1.2.1
jar
com.scheible::test-gap-analysis library
@@ -30,7 +30,7 @@
1.15
5.13.1.202206130422-r
- 3.24.2
+ 3.24.4
0.8.8
diff --git a/test-gap-analysis/src/main/java/com/scheible/testgapanalysis/parser/JavaParser.java b/test-gap-analysis/src/main/java/com/scheible/testgapanalysis/parser/JavaParser.java
index 03afb09..4321c35 100644
--- a/test-gap-analysis/src/main/java/com/scheible/testgapanalysis/parser/JavaParser.java
+++ b/test-gap-analysis/src/main/java/com/scheible/testgapanalysis/parser/JavaParser.java
@@ -2,6 +2,7 @@
import java.util.Collections;
import java.util.Set;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.slf4j.Logger;
@@ -19,6 +20,9 @@
*/
public class JavaParser {
+ private static final Pattern INSTANCEOF_WITH_FINAL_WORKAROUND_PATTERN = Pattern
+ .compile("\\sinstanceof\\s+?final\\s");
+
protected final Logger logger = LoggerFactory.getLogger(getClass());
public Set getMethods(String code, String path) {
@@ -26,6 +30,9 @@ public Set getMethods(String code, String path) {
configuration.setLanguageLevel(LanguageLevel.BLEEDING_EDGE);
com.github.javaparser.JavaParser javaParser = new com.github.javaparser.JavaParser(configuration);
+ // needed as long https://github.com/javaparser/javaparser/issues/2445#issuecomment-964188096 is not fixed
+ code = INSTANCEOF_WITH_FINAL_WORKAROUND_PATTERN.matcher(code).replaceAll(" instanceof ");
+
ParseResult parserResult = javaParser.parse(code);
if (!parserResult.isSuccessful()) {
logger.error("Parsing methods of '{}' failed cause: {}", path, parserResult.getProblems().stream()
diff --git a/test-gap-analysis/src/test/java/com/scheible/testgapanalysis/parser/JavaParserTest.java b/test-gap-analysis/src/test/java/com/scheible/testgapanalysis/parser/JavaParserTest.java
index 751cee9..fe120d2 100644
--- a/test-gap-analysis/src/test/java/com/scheible/testgapanalysis/parser/JavaParserTest.java
+++ b/test-gap-analysis/src/test/java/com/scheible/testgapanalysis/parser/JavaParserTest.java
@@ -145,6 +145,34 @@ public void testRecordParsing() {
});
}
+ @Test
+ public void testEnhancedInstanceofParsing() {
+ // enhanced instanceof requires Java 16, test-gap source code is Java 8 --> parse from string
+ assertThat(new JavaParser().getMethods("class Test {\n" + //
+ " void doIt() {\n" + //
+ " Object object = \":-)\";\n" + //
+ " if (object instanceof String string) {\n" + //
+ " }\n" + //
+ " }\n" + //
+ "}", "path")).first().satisfies(pm -> {
+ assertThat(pm.getName()).isEqualTo("doIt");
+ });
+ }
+
+ @Test
+ public void testEnhancedInstanceofWithFinalParsing() {
+ // enhanced instanceof requires Java 16, test-gap source code is Java 8 --> parse from string
+ assertThat(new JavaParser().getMethods("class Test {\n" + //
+ " void doIt() {\n" + //
+ " Object object = \":-)\";\n" + //
+ " if (object instanceof final String string) {\n" + //
+ " }\n" + //
+ " }\n" + //
+ "}", "path")).first().satisfies(pm -> {
+ assertThat(pm.getName()).isEqualTo("doIt");
+ });
+ }
+
public static class MethodMasking { // #debug
public String doIt(String arg1, boolean isDebugMode) {