< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java

Print this page
rev 2973 : JDK-8058150

@@ -31,10 +31,11 @@
 import java.io.StringWriter;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.*;
 import java.util.regex.*;
+import java.util.stream.Collectors;
 
 import javax.annotation.processing.*;
 import javax.lang.model.SourceVersion;
 import javax.lang.model.element.*;
 import javax.lang.model.util.*;

@@ -55,10 +56,12 @@
 import com.sun.tools.javac.comp.Env;
 import com.sun.tools.javac.file.JavacFileManager;
 import com.sun.tools.javac.main.JavaCompiler;
 import com.sun.tools.javac.model.JavacElements;
 import com.sun.tools.javac.model.JavacTypes;
+import com.sun.tools.javac.platform.PlatformProvider;
+import com.sun.tools.javac.platform.PlatformProvider.PluginInfo;
 import com.sun.tools.javac.tree.*;
 import com.sun.tools.javac.tree.JCTree.*;
 import com.sun.tools.javac.util.Abort;
 import com.sun.tools.javac.util.Assert;
 import com.sun.tools.javac.util.ClientCodeException;

@@ -280,11 +283,45 @@
                  */
                 processorIterator = handleServiceLoaderUnavailability("proc.cant.create.loader",
                         processorClassLoaderException);
             }
         }
-        discoveredProcs = new DiscoveredProcessors(processorIterator);
+        PlatformProvider platformProvider = context.get(PlatformProvider.class);
+        java.util.List<Processor> platformProcessors = Collections.emptyList();
+        if (platformProvider != null) {
+            platformProcessors = platformProvider.getAnnotationProcessors()
+                                                 .stream()
+                                                 .map(ap -> ap.getPlugin())
+                                                 .collect(Collectors.toList());
+        }
+        discoveredProcs = new DiscoveredProcessors(new JoiningIterator(List.of(processorIterator, platformProcessors.iterator())));
+    }
+
+    private static final class JoiningIterator implements Iterator<Processor> {
+        private List<Iterator<? extends Processor>> delegateTo;
+
+        public JoiningIterator(List<Iterator<? extends Processor>> delegateTo) {
+            this.delegateTo = delegateTo;
+        }
+
+        @Override
+        public boolean hasNext() {
+            while (delegateTo.nonEmpty() && !delegateTo.head.hasNext())
+                delegateTo = delegateTo.tail;
+
+            return delegateTo.nonEmpty();
+        }
+
+        @Override
+        public Processor next() {
+            if (delegateTo.isEmpty()) {
+                throw new NoSuchElementException();
+            }
+
+            return delegateTo.head.next();
+        }
+
     }
 
     /**
      * Returns an empty processor iterator if no processors are on the
      * relevant path, otherwise if processors are present, logs an

@@ -479,10 +516,18 @@
                 }
                 tempOptions.put(candidateKey, candidateValue);
             }
         }
 
+        PlatformProvider platformProvider = context.get(PlatformProvider.class);
+
+        if (platformProvider != null) {
+            for (PluginInfo<Processor> ap : platformProvider.getAnnotationProcessors()) {
+                tempOptions.putAll(ap.getOptions());
+            }
+        }
+
         return Collections.unmodifiableMap(tempOptions);
     }
 
     private Set<String> initUnmatchedProcessorOptions() {
         Set<String> unmatchedProcessorOptions = new HashSet<>();
< prev index next >