Skip to content

Commit 0bd1cc0

Browse files
Do not always skip CompilationParticipant for non-ECJ (#4514)
While Javac honors annotation processors, various CompilationParticipant (such as PDE's DSAnnotationCompilationParticipant) don't pass a compiler-level annotation processor to the compiler, being no-op in compilation, and are then expected to proceed upon completion of the compilation, even with Javac. This patch refines the condition for a CompilationParticipant to participate (or more precisely the other way round, it refines the conditions for a CompilationParticipant to not processAnnotations)
1 parent cb8a23e commit 0bd1cc0

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -885,22 +885,40 @@ protected CompilationParticipantResult[] notifyParticipants(SourceFile[] unitsAb
885885
protected void processAnnotations(CompilationParticipantResult[] results) {
886886
boolean hasAnnotationProcessor = false;
887887
for (int i = 0, l = this.javaBuilder.participants.length; !hasAnnotationProcessor && i < l; i++)
888-
hasAnnotationProcessor = this.javaBuilder.participants[i].isAnnotationProcessor();
888+
hasAnnotationProcessor |= requiresProcessAnnotation(this.javaBuilder.participants[i]);
889889
if (!hasAnnotationProcessor) return;
890890

891891
boolean foundAnnotations = this.filesWithAnnotations != null && this.filesWithAnnotations.size() > 0;
892892
for (int i = results.length; --i >= 0;) {
893893
results[i].reset(foundAnnotations ? this.filesWithAnnotations.get(results[i].sourceFile) : null);
894894
}
895895

896+
// even if no files have annotations, must still tell every annotation processor in case the file used to have them
897+
for (CompilationParticipant participant : this.javaBuilder.participants)
898+
if (requiresProcessAnnotation(participant))
899+
participant.processAnnotations(results);
900+
processAnnotationResults(results);
901+
}
902+
903+
private boolean requiresProcessAnnotation(CompilationParticipant participant) {
904+
if (!participant.isAnnotationProcessor()) {
905+
return false;
906+
}
896907
boolean isEcjUsed = Compiler.class.equals(this.compiler.getClass());
897-
if (isEcjUsed) {
898-
// even if no files have annotations, must still tell every annotation processor in case the file used to have them
899-
for (CompilationParticipant participant : this.javaBuilder.participants)
900-
if (participant.isAnnotationProcessor())
901-
participant.processAnnotations(results);
908+
if (isEcjUsed) { // ECJ doesn't honor the annotations settings
909+
// so force specific processing
910+
return true;
902911
}
903-
processAnnotationResults(results);
912+
var processorPaths = participant.getAnnotationProcessorPaths(this.javaBuilder.javaProject, this.compilationGroup == CompilationGroup.TEST);
913+
if (processorPaths == null || processorPaths.length == 0) {
914+
// the participant is processing annotation but doesn't
915+
// provide a compiler-level annotation processor, so we
916+
// force specific processing
917+
return true;
918+
}
919+
// The annotation processors were passed to compiler and most likely used
920+
// no need for specific handling
921+
return false;
904922
}
905923

906924
protected void recordParticipantResult(CompilationParticipantResult result) {

0 commit comments

Comments
 (0)