Repository navigation
SONARJAVA-7300 Decouple the Sonar Java frontend from Eclipse JDT core - #6485
aurelien-coet-sonarsource wants to merge 4 commits into
Conversation
d50bf37 to
80b9ad3
Compare
|
/pvf |
| public abstract class JParserConfig { | ||
|
|
||
| public static final JavaVersion MAXIMUM_SUPPORTED_JAVA_VERSION = new JavaVersionImpl(JavaVersionImpl.MAX_SUPPORTED, true); | ||
| public abstract class JParserConfig implements JavaParser { |
There was a problem hiding this comment.
⚠️ Cross-Repo: SE repo test helper no longer compiles: JParser/JParserConfig API moved
Fix here and in SonarSource/sonar-java-symbolic-execution
Breaks in: SonarSource/sonar-java-symbolic-execution - java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/utils/JParserTestUtils.java - JParserTestUtils.parse
This breaks SonarSource/sonar-java-symbolic-execution, in java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/utils/JParserTestUtils.java (JParserTestUtils.parse).
That helper imports org.sonar.java.model.JParser and org.sonar.java.model.JParserConfig. It builds its parser with JParserConfig.Mode.FILE_BY_FILE.create(...).astParser(), passes it to JParser.parse(ASTParser, version, unitName, source), and reads JParserConfig.MAXIMUM_SUPPORTED_JAVA_VERSION. This PR changes all of that:
JParsermoves toorg.sonar.java.jdtas a package-privatefinal classwith a package-privateparse.JParserConfigmoves toorg.sonar.java.jdt, losesMode, and itsastParser()becomes package-private.MAXIMUM_SUPPORTED_JAVA_VERSIONmoves toorg.sonar.java.JavaParsers.
Once the SE repo bumps to this frontend, the helper no longer compiles, and neither does any SE test that depends on it. The same pair of APIs came up in earlier reviews (JParser.parse SE dependency, astParser SE dependency). The PR's goal is to decouple the frontend from JDT, so the move is intended and the consumer has to migrate. The replacement already exists: JavaParsers.Mode.FILE_BY_FILE.create(version, classpath).parse(unitName, source).
Here: Record in the release or migration notes that org.sonar.java.model.JParser/JParserConfig were removed, and name JavaParsers.MAXIMUM_SUPPORTED_JAVA_VERSION and JavaParsers.Mode.X.create(...).parse(unitName, source) as the replacements. Coordinate the release with sonar-java-symbolic-execution.
There: In JParserTestUtils.parse, drop the JParserConfig/JParser/ASTParser imports and call the new JavaParsers/JavaParser API.
In SonarSource/sonar-java-symbolic-execution - java-symbolic-execution/java-symbolic-execution-plugin/src/test/java/org/sonar/java/se/utils/JParserTestUtils.java:
import org.sonar.java.JavaParsers;
public static CompilationUnitTree parse(String unitName, String source, List<File> classpath) {
return JavaParsers.Mode.FILE_BY_FILE
.create(JavaParsers.MAXIMUM_SUPPORTED_JAVA_VERSION, classpath)
.parse(unitName, source);
}
Was this helpful? React with 👍 / 👎
| JProblem p1 = new JProblem("message1", ProblemKind.UNDEFINED_TYPE); | ||
| assertFalse(p1.equals(null)); | ||
| assertTrue(p1.equals(p1)); | ||
| assertNotEquals(null, p1); |
There was a problem hiding this comment.
💡 Quality: assertNotEquals(null, p1) no longer calls JProblem.equals(null)
JUnit 5's assertNotEquals(unexpected, actual) uses AssertionUtils.objectsAreEqual, which returns obj2 == null when the first argument is null and never calls p1.equals(null). The old assertFalse(p1.equals(null)) was the only check that reached the !(o instanceof JProblem that) → return false branch in JProblem.equals (JProblem.java:82-83). Every other comparison in the test passes a JProblem. That branch is now untested, and coverage on the moved JProblem class drops. Since this commit is meant to fix the quality gate, that matters. Put the receiver first so equals actually runs on it.
AssertJ calls p1.equals(null), so the null/non-instance branch is still exercised:
assertThat(p1).isNotEqualTo(null);
- Apply fix
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎
|
📊 Performance Validation complete |
a82afa6 to
6273e83
Compare
6273e83 to
dd81463
Compare
Code Review
|
| Auto-apply | Compact | Unblock |
|
|
|
Was this helpful? React with 👍 / 👎 | Gitar
|




Summary by Gitar
JParser,JSema,JWarning,JSymbolMetadata,JTypeSymbol) fromorg.sonar.java.modelinto neworg.sonar.java.jdtpackageJParserandJProblemvisibility; madeKeywordThisandKeywordSuperpublicJavaParserandJavaParsersinterfaces andParseResultclass, replacingJParserConfig.ModeandJParserConfig.ResultJavaParser.parse(unitName, source)for parsing a single fileJProbleminjdtpackage withProblemKind-based classification, replacing the nestedJProblem.Typeenum*SymbolOrUnknownhelper methods inJSemaand routed tree symbol assignment throughsetSymbol/setSymbolTypeSymbol.MethodSymbol.annotationElementDefaultValue()so default values no longer depend on JDT bindingsJUtilstoSemanticUtilsandJSymbolMetadataNullabilityHelpertoNullabilityHelper, with nullability data moved toNullabilityDataImplSemanticUtils.directSuperTypesto use the symbol API, so interfaces no longer report a superclassThis will update automatically on new commits.