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

Jonathan Gibbons jonathan.gibbons at oracle.com
Tue Nov 27 20:51:57 UTC 2018


Looks OK to me

-- Jon

On 11/27/2018 12:33 PM, joe darcy wrote:

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 @@  /* - * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -80,10 +80,7 @@ */ public Set getSupportedOptions() { SupportedOptions so = this.getClass().getAnnotation(SupportedOptions.class); -        if  (so == null) -            return Collections.emptySet(); -        else -            return arrayToSet(so.value(), false); +    return (so == null) ? Collections.emptySet() : Set.of(so.value()); } /** @@ -115,7 +112,17 @@ boolean stripModulePrefixes = initialized && processingEnv.getSourceVersion().compareTo(SourceVersion.RELEASE8) <= 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