Skip to content

Commit a9f1280

Browse files
2023-06->2023-09 Seems to have broke dependency graph management in our project (#1698)
* Add test for reproducing #1654 * Fix to make that test pass --------- Co-authored-by: Stephan Herrmann <[email protected]>
1 parent f64cfac commit a9f1280

File tree

2 files changed

+87
-3
lines changed

2 files changed

+87
-3
lines changed

org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/AnnotationProcessingCompilerToolTest.java

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2022 IBM Corporation and others.
2+
* Copyright (c) 2000, 2022-2023 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
1010
*
1111
* Contributors:
1212
* Salesforce - copied and adapted from org.eclipse.jdt.core.tests.compiler.regression.BatchCompilerTest
13+
* SSI Schaefer IT Solutions GmbH - add test_github1654()
1314
*******************************************************************************/
1415
package org.eclipse.jdt.apt.tests;
1516

@@ -109,6 +110,84 @@ public void test_github844() throws IOException {
109110
// @formatter:on
110111
}
111112

113+
public void test_github1654() throws IOException {
114+
// @formatter:off
115+
runTest(
116+
true /* shouldCompileOK */,
117+
new String [] { /* sourceFiles */
118+
"X.java", """
119+
package p1;
120+
import org.eclipse.jdt.apt.tests.external.annotations.batch.BatchGen;
121+
@BatchGen
122+
public class X {
123+
}
124+
""",
125+
"Anno.java", """
126+
package p1;
127+
public @interface Anno {
128+
public static final String V = "V";
129+
String v() default "";
130+
}
131+
""",
132+
"Breaks.java", """
133+
package p2;
134+
import p1.Anno;
135+
import p1.gen.Class1;
136+
@Anno (v = Anno.V)
137+
public class Breaks {
138+
public Class1 c1;
139+
};
140+
""",
141+
"Works1.java", """
142+
package p2;
143+
import p1.Anno;
144+
import p1.gen.Class1;
145+
@Anno // (v = Anno.V)
146+
public class Works1 {
147+
public Class1 c1;
148+
};
149+
""",
150+
"Works2.java", """
151+
package p2;
152+
import p1.Anno;
153+
// import p1.gen.Class1;
154+
@Anno(v = Anno.V)
155+
public class Works2 {
156+
// public Class1 c1;
157+
public p1.gen.Class1 c1;
158+
};
159+
""",
160+
},
161+
null /* standardJavaFileManager */,
162+
Arrays.asList(
163+
"-d", OUTPUT_DIR,
164+
"-source", "1.6",
165+
"-g", "-preserveAllLocals",
166+
"-cp", OUTPUT_DIR + File.pathSeparator + _extJar.getAbsolutePath() ,
167+
"-s", OUTPUT_DIR + File.separator + "src-gen",
168+
"-processorpath", _extJar.getAbsolutePath(),
169+
"-XprintProcessorInfo",
170+
// TODO: after fixing the issue, enable and update expected output of:
171+
// "-XprintRounds",
172+
"-proceedOnError"
173+
) /* options */,
174+
new String[] { /* compileFileNames */
175+
"X.java",
176+
"Anno.java",
177+
"Breaks.java",
178+
"Works1.java",
179+
"Works2.java"
180+
},
181+
"Discovered processor service org.eclipse.jdt.apt.tests.external.annotations.batch.BatchGenProcessor\n" +
182+
" supporting [org.eclipse.jdt.apt.tests.external.annotations.batch.BatchGen]\n" +
183+
" in jar:" + Path.of(_extJar.getCanonicalPath()).toUri().toURL().toString() + "!/\n" +
184+
"Processor org.eclipse.jdt.apt.tests.external.annotations.batch.BatchGenProcessor matches [org.eclipse.jdt.apt.tests.external.annotations.batch.BatchGen] and returns true\n" +
185+
"Processor org.eclipse.jdt.apt.tests.external.annotations.batch.BatchGenProcessor matches [] and returns false\n",
186+
"" /* expectedErrOutputString */,
187+
true /* shouldFlushOutputDirectory */ );
188+
// @formatter:on
189+
}
190+
112191
protected static class CompilerInvocationTestsArguments {
113192
StandardJavaFileManager standardJavaFileManager;
114193
List<String> options;

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,13 @@ void connectTypeHierarchy() {
412412
void integrateAnnotationsInHierarchy() {
413413
// Only now that all hierarchy information is built we're ready for ...
414414
// ... integrating annotations
415-
for (int i = 0, length = this.topLevelTypes.length; i < length; i++)
416-
this.topLevelTypes[i].scope.referenceType().updateSupertypesWithAnnotations(Collections.emptyMap());
415+
try {
416+
this.environment.suppressImportErrors = true;
417+
for (int i = 0, length = this.topLevelTypes.length; i < length; i++)
418+
this.topLevelTypes[i].scope.referenceType().updateSupertypesWithAnnotations(Collections.emptyMap());
419+
} finally {
420+
this.environment.suppressImportErrors = false;
421+
}
417422
// ... checking on permitted types
418423
connectPermittedTypes();
419424
for (int i = 0, length = this.topLevelTypes.length; i < length; i++)

0 commit comments

Comments
 (0)