Skip to content

Commit 1c948fa

Browse files
committed
Discrepancy in annotation processing, between full and incremental
builds #4617
1 parent cb0ce53 commit 1c948fa

File tree

8 files changed

+37
-4
lines changed

8 files changed

+37
-4
lines changed
2.66 KB
Binary file not shown.
424 Bytes
Binary file not shown.

org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java8ElementProcessor.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"org.eclipse.jdt.compiler.apt.tests.annotations.IFoo", "org.eclipse.jdt.compiler.apt.tests.annotations.IFooContainer",
5959
"org.eclipse.jdt.compiler.apt.tests.annotations.Goo", "org.eclipse.jdt.compiler.apt.tests.annotations.GooNonContainer",
6060
"org.eclipse.jdt.compiler.apt.tests.annotations.FooNonContainer", "targets.filer8.PackageAnnot",
61-
"java.lang.Deprecated"})
61+
"java.lang.Deprecated", "org.eclipse.jdt.compiler.apt.tests.annotations.GenClass"})
6262

6363
@SupportedSourceVersion(SourceVersion.RELEASE_8)
6464
public class Java8ElementProcessor extends BaseProcessor {
@@ -161,6 +161,7 @@ public void testAll() throws AssertionFailedError {
161161
testBug526288();
162162
testEnumConstArguments();
163163
testBug544288();
164+
testGH4617();
164165
}
165166

166167
public void testLambdaSpecifics() {
@@ -1070,6 +1071,17 @@ public void testBug544288() {
10701071
Element asElement = _typeUtils.asElement(asType);
10711072
verifyAnnotations(asElement, new String[]{"@Deprecated()"});
10721073
}
1074+
public void testGH4617() {
1075+
TypeElement type = _elementUtils.getTypeElement("targets.GH4617.ParentClass");
1076+
List<? extends Element> enclosedElements = type.getEnclosedElements();
1077+
List<ExecutableElement> methodsIn = ElementFilter.methodsIn(enclosedElements);
1078+
assertEquals("Incorrect number of methods", 3, methodsIn.size());
1079+
StringBuilder builder = new StringBuilder();
1080+
for (ExecutableElement executableElement : methodsIn) {
1081+
builder.append(executableElement.getSimpleName().toString()).append(',');
1082+
}
1083+
assertEquals("Incorrect order received", "gamma,alpha,beta,", builder.toString());
1084+
}
10731085
private void createPackageBinary() throws IOException {
10741086
String path = packageName.replace('.', '/');
10751087
ClassLoader loader = getClass().getClassLoader();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package targets.GH4617;
2+
@org.eclipse.jdt.compiler.apt.tests.annotations.GenClass(clazz="p.q.R", method="foo")
3+
public abstract class ParentClass {
4+
public abstract int gamma();
5+
public abstract byte alpha();
6+
public abstract int beta();
7+
}

org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java8ElementsTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,12 @@ public void testBug544288() throws Exception {
413413
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
414414
internalTestWithBinary(compiler, JAVA8_ANNOTATION_PROC, "testBug544288", null, "bug544288", "9");
415415
}
416+
public void testGH4617() throws Exception {
417+
if (!canRunJava9())
418+
return;
419+
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
420+
internalTestWithBinary(compiler, JAVA8_ANNOTATION_PROC, "testGH4617", null, "GH4617", "9");
421+
}
416422
private void internalTest(JavaCompiler compiler, String processor, String testMethod) throws IOException {
417423
internalTest(compiler, processor, testMethod, null);
418424
}

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/apt/model/TypeElementImpl.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ private int determineSourceStart(ElementImpl e) {
7777
case METHOD :
7878
ExecutableElementImpl executableElementImpl = (ExecutableElementImpl) e;
7979
Binding binding = executableElementImpl._binding;
80-
if (binding instanceof MethodBinding) {
81-
MethodBinding methodBinding = (MethodBinding) binding;
82-
return methodBinding.sourceStart();
80+
if(binding instanceof MethodBinding bmd) {
81+
if (bmd.declaringClass.isBinaryBinding()) {
82+
return bmd.order;
83+
}
84+
return bmd.sourceStart();
8385
}
8486
break;
8587
case ENUM_CONSTANT :
@@ -129,6 +131,8 @@ protected AnnotationBinding[] getAnnotationBindings()
129131
@Override
130132
public List<? extends Element> getEnclosedElements() {
131133
ReferenceBinding binding = (ReferenceBinding)this._binding;
134+
long bkup = binding.tagBits;
135+
binding.tagBits |= TagBits.AreMethodsSorted;
132136
List<Element> enclosed = new ArrayList<>(binding.fieldCount() + binding.methods().length + binding.memberTypes().length);
133137
for (MethodBinding method : binding.methods()) {
134138
ExecutableElement executable = new ExecutableElementImpl(this._env, method);
@@ -141,6 +145,7 @@ public List<? extends Element> getEnclosedElements() {
141145
enclosed.add(variable);
142146
}
143147
}
148+
binding.tagBits = bkup;
144149
if (binding.isRecord()) {
145150
RecordComponentBinding[] components = binding.components();
146151
for (RecordComponentBinding comp : components) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,7 @@ private IBinaryMethod[] createMethods(IBinaryMethod[] iMethods, IBinaryType bina
11521152
if (hasRestrictedAccess)
11531153
method.modifiers |= ExtraCompilerModifiers.AccRestrictedAccess;
11541154
methods1[i] = method;
1155+
method.order = i;
11551156
}
11561157
this.methods = methods1;
11571158
return iMethods;
@@ -1164,6 +1165,7 @@ private IBinaryMethod[] createMethods(IBinaryMethod[] iMethods, IBinaryType bina
11641165
method.modifiers |= ExtraCompilerModifiers.AccRestrictedAccess;
11651166
mappedBinaryMethods[index] = iMethods[i];
11661167
methods1[index++] = method;
1168+
method.order = i;
11671169
}
11681170
}
11691171
this.methods = methods1;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public static byte flowBitFromAnnotationTagBit(long tagBit) {
9494

9595
/** Store parameter names from MethodParameters attribute (incl. applicable default). */
9696
public char[][] parameterNames = Binding.NO_PARAMETER_NAMES;
97+
public int order;
9798

9899
protected MethodBinding() {
99100
// for creating problem or synthetic method

0 commit comments

Comments
 (0)