< prev index next >

src/java.compiler/share/classes/javax/annotation/processing/AbstractProcessor.java

Print this page

        

@@ -78,14 +78,13 @@
      * @return the options recognized by this processor, or an empty
      * set if none
      */
     public Set<String> getSupportedOptions() {
         SupportedOptions so = this.getClass().getAnnotation(SupportedOptions.class);
-        if  (so == null)
-            return Collections.emptySet();
-        else
-            return arrayToSet(so.value(), false);
+        return (so == null) ?
+            Set.of() :
+            arrayToSet(so.value(), false, "option value", "@SupportedOptions");
     }
 
     /**
      * If the processor class is annotated with {@link
      * SupportedAnnotationTypes}, return an unmodifiable set with the

@@ -108,16 +107,17 @@
                 if (initialized)
                     processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING,
                                                              "No SupportedAnnotationTypes annotation " +
                                                              "found on " + this.getClass().getName() +
                                                              ", returning an empty set.");
-                return Collections.emptySet();
+                return Set.of();
             } else {
                 boolean stripModulePrefixes =
                         initialized &&
                         processingEnv.getSourceVersion().compareTo(SourceVersion.RELEASE_8) <= 0;
-                return arrayToSet(sat.value(), stripModulePrefixes);
+                return arrayToSet(sat.value(),stripModulePrefixes,
+                                  "annotation type", "@SupportedAnnotationTypes");
             }
         }
 
     /**
      * If the processor class is annotated with {@link

@@ -193,20 +193,30 @@
      */
     protected synchronized boolean isInitialized() {
         return initialized;
     }
 
-    private static Set<String> arrayToSet(String[] array,
-                                          boolean stripModulePrefixes) {
+    private Set<String> arrayToSet(String[] array,
+                                          boolean stripModulePrefixes,
+                                   String contentType,
+                                   String annotationName) {
         assert array != null;
-        Set<String> set = new HashSet<>(array.length);
+        Set<String> set = new HashSet<>();
         for (String s : array) {
             if (stripModulePrefixes) {
                 int index = s.indexOf('/');
                 if (index != -1)
                     s = s.substring(index + 1);
             }
-            set.add(s);
+            boolean added = set.add(s);
+            if (!added && initialized) {
+                processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING,
+                                                         "Duplicate " + contentType  +
+                                                         " ``" + s  + "'' for processor " +
+                                                         this.getClass().getName() +
+                                                         " in its " + annotationName  +
+                                                         "annotation.");            
+            }
         }
         return Collections.unmodifiableSet(set);
     }
 }
< prev index next >