Skip to content

Commit ba15e28

Browse files
committed
Attempt skipping extra analysis when problems are not requested
1 parent c8f8d92 commit ba15e28

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

org.eclipse.jdt.core.javac/src/org/eclipse/jdt/core/dom/JavacCompilationUnitResolver.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ public void finished(TaskEvent e) {
614614
problemConverter.registerUnit(e.getSourceFile(), u);
615615
}
616616

617-
if (e.getKind() == TaskEvent.Kind.ANALYZE && Options.instance(context).isSet(Option.XLINT)) {
617+
if (e.getKind() == TaskEvent.Kind.ANALYZE && Options.instance(context).get(Option.XLINT_CUSTOM).contains("all")) {
618618
final JavaFileObject file = e.getSourceFile();
619619
final CompilationUnit dom = filesToUnits.get(file);
620620
if (dom == null) {
@@ -698,12 +698,10 @@ public Void visitClass(ClassTree node, Void p) {
698698
JavacUtils.configureJavacContext(context, compilerOptions, javaProject, JavacUtils.isTest(javaProject, sourceUnits), ignoreModule);
699699
Options javacOptions = Options.instance(context);
700700
javacOptions.put("allowStringFolding", Boolean.FALSE.toString()); // we need to keep strings as authored
701-
if ((focalPoint >= 0 || !resolveBindings) && (flags & ICompilationUnit.FORCE_PROBLEM_DETECTION) == 0) {
702-
// most likely no need for linting
701+
if (focalPoint >= 0 || (flags & ICompilationUnit.FORCE_PROBLEM_DETECTION) == 0) {
702+
// most likely no need for more linting
703703
// resolveBindings still seems requested for tests
704-
javacOptions.remove(Option.XLINT.primaryName);
705-
javacOptions.put(Option.XLINT_CUSTOM, "none");
706-
javacOptions.remove(Option.XDOCLINT.primaryName);
704+
javacOptions.put(Option.XLINT_CUSTOM, "raw");
707705
javacOptions.put(Option.XDOCLINT_CUSTOM, "none");
708706
}
709707
javacOptions.put(Option.PROC, ProcessorConfig.isAnnotationProcessingEnabled(javaProject) ? "only" : "none");

org.eclipse.jdt.core.tests.javac/src/org/eclipse/jdt/core/tests/javac/CachingClassReaderTests.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,57 @@
3535
import org.eclipse.jdt.core.dom.ASTParser;
3636
import org.eclipse.jdt.core.dom.CompilationUnit;
3737
import org.eclipse.jdt.core.dom.JavacCompilationUnitResolver;
38+
import org.junit.Ignore;
3839
import org.junit.Test;
3940

4041
public class CachingClassReaderTests {
4142

43+
@Ignore // currently ignored https://github.com/eclipse-jdtls/eclipse-jdt-core-incubator/issues/1827
44+
@Test
45+
public void testInnerAnonymousWithTypeParams() throws Exception {
46+
Path dir = Files.createTempDirectory(getClass().getName());
47+
Path sourceFile = dir.resolve("A.java");
48+
Files.write(sourceFile, """
49+
class A<K, V> {
50+
java.util.function.Function<K, V> m() {
51+
return new java.util.function.Function<>() {
52+
@Override
53+
public V apply(K k) {
54+
return null;
55+
}
56+
};
57+
}
58+
}
59+
""".getBytes());
60+
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
61+
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
62+
Iterable<? extends JavaFileObject> compilationUnits1 = fileManager.getJavaFileObjectsFromPaths(List.of(sourceFile));
63+
CharArrayWriter writer = new CharArrayWriter(2000);
64+
assertTrue(new String(writer.toCharArray()), compiler.getTask(writer, fileManager, null, List.of("--release", "17"), null, compilationUnits1).call());
65+
Path Bclass = dir.resolve("A.class");
66+
assertTrue(Files.exists(Bclass));
67+
68+
String source = """
69+
class I {
70+
A<String, String> a = new A<>();
71+
}
72+
""";
73+
// What we really want to test is calling CachingClassSymbolClassReader multiple times for A$B
74+
// but as we prefer avoiding references to internal Javac types in tests, we just load the AST multiple times.
75+
for (int i = 0; i < 2; i++) {
76+
ASTParser parser = ASTParser.newParser(AST.getJLSLatest());
77+
parser.setSource(source.toCharArray());
78+
parser.setUnitName("I.java");
79+
parser.setEnvironment(new String[] { dir.toString() }, null, null, true);
80+
parser.setResolveBindings(true);
81+
try (var _ = withoutLoggedError()) {
82+
var node = (CompilationUnit)parser.createAST(new NullProgressMonitor());
83+
assertArrayEquals(new IProblem[0], node.getProblems());
84+
node.getAST().resolveWellKnownType("A$1");
85+
}
86+
}
87+
}
88+
4289
@Test
4390
public void testIntersectionType() throws Exception {
4491
Path dir = Files.createTempDirectory(getClass().getName());

0 commit comments

Comments
 (0)