JDK 12 RFR of JDK-8146726 : Refactor AbstractProcessor to use Set.of and related methods
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<String> 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.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<String> arrayToSet(String[] array,
> - boolean stripModulePrefixes) {
> - assert array != null;
> - Set<String> 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