JDK 12 RFR of JDK-8146726 : Refactor AbstractProcessor to use Set.of and related methods (original) (raw)

joe darcy joe.darcy at oracle.com
Tue Nov 27 20:33:30 UTC 2018


Hello,

Re-visiting this refactoring, please review the changes for

    JDK-8146726 : Refactor AbstractProcessor to use Set.of and related methods     http://cr.openjdk.java.net/~darcy/8146726.1/

Patch below; all langtools regression tests pass with the change.

Note that by the contract of AnnotatedElement, is is okay to modify the contents of a returned array. Therefore, it is acceptable to remove the array clone step.

Thanks,

-Joe


old/src/java.compiler/share/classes/javax/annotation/processing/AbstractProcessor.java 2018-11-27 12:29:00.618001000 -0800 +++ new/src/java.compiler/share/classes/javax/annotation/processing/AbstractProcessor.java 2018-11-27 12:29:00.250001000 -0800 @@ -1,5 +1,5 @@  /*

     /** @@ -115,7 +112,17 @@                  boolean stripModulePrefixes =                          initialized && processingEnv.getSourceVersion().compareTo(SourceVersion.RELEASE_8) <= 0; -                return arrayToSet(sat.value(), stripModulePrefixes); + +        String[] supportedAnnotTypes = sat.value(); +        if (stripModulePrefixes) { +            for (int i = 0; i < supportedAnnotTypes.length; i++) { +            String s = supportedAnnotTypes[i]; +            int index = s.indexOf('/'); +            if (index != -1) +                supportedAnnotTypes[i] = s.substring(index + 1); +            } +        } +        return Set.of(supportedAnnotTypes);              }          }

@@ -194,19 +201,4 @@      protected synchronized boolean isInitialized() {          return initialized;      }

-    private static Set arrayToSet(String[] array, -                                          boolean stripModulePrefixes) { -        assert array != null; -        Set set = new HashSet<>(array.length); -        for (String s : array) { -            if (stripModulePrefixes) { -                int index = s.indexOf('/'); -                if (index != -1) -                    s = s.substring(index + 1); -            } -            set.add(s); -        } -        return Collections.unmodifiableSet(set); -    }  }



More information about the compiler-dev mailing list