diff options
-rw-r--r-- | src/core/lombok/ConfigurationKeys.java | 7 | ||||
-rw-r--r-- | src/core/lombok/core/configuration/ConfigurationApp.java | 3 | ||||
-rw-r--r-- | src/core/lombok/core/configuration/ConfigurationKeysLoader.java | 50 | ||||
-rw-r--r-- | src/core/lombok/eclipse/HandlerLibrary.java | 10 | ||||
-rw-r--r-- | src/core/lombok/javac/HandlerLibrary.java | 7 |
5 files changed, 57 insertions, 20 deletions
diff --git a/src/core/lombok/ConfigurationKeys.java b/src/core/lombok/ConfigurationKeys.java index 022af237..6fd87e25 100644 --- a/src/core/lombok/ConfigurationKeys.java +++ b/src/core/lombok/ConfigurationKeys.java @@ -30,13 +30,6 @@ import lombok.core.configuration.ConfigurationKey; public class ConfigurationKeys { private ConfigurationKeys() {} - /** - * Makes sure all {@link ConfigurationKey}s in this class are loaded. - * - * (Calling the method ensures this class is initialized by the class loader; this is enough to initialize all configuration keys). - */ - public static void ensureKeysLoaded() {} - // ##### main package features ##### // ----- *ArgsConstructor ----- diff --git a/src/core/lombok/core/configuration/ConfigurationApp.java b/src/core/lombok/core/configuration/ConfigurationApp.java index 35ab37af..8694af6a 100644 --- a/src/core/lombok/core/configuration/ConfigurationApp.java +++ b/src/core/lombok/core/configuration/ConfigurationApp.java @@ -26,7 +26,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import lombok.ConfigurationKeys; import lombok.core.LombokApp; import org.mangosdk.spi.ProviderFor; @@ -89,7 +88,7 @@ public class ConfigurationApp extends LombokApp { return 1; } - ConfigurationKeys.ensureKeysLoaded(); + ConfigurationKeysLoader.LoaderLoader.loadAllConfigurationKeys(); if (args.generate) { printConfiguration(System.out, args.verbose); diff --git a/src/core/lombok/core/configuration/ConfigurationKeysLoader.java b/src/core/lombok/core/configuration/ConfigurationKeysLoader.java new file mode 100644 index 00000000..7fdbb4da --- /dev/null +++ b/src/core/lombok/core/configuration/ConfigurationKeysLoader.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2014 The Project Lombok Authors. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.core.configuration; + +import java.io.IOException; +import java.util.Iterator; + +import lombok.ConfigurationKeys; +import lombok.core.SpiLoadUtil; + +public interface ConfigurationKeysLoader { + public class LoaderLoader { + private LoaderLoader() {} + + public static void loadAllConfigurationKeys() { + try { + Class.forName(ConfigurationKeys.class.getName()); + } catch (Throwable ignore) {} + try { + Iterator<ConfigurationKeysLoader> iterator = SpiLoadUtil.findServices(ConfigurationKeysLoader.class, ConfigurationKeysLoader.class.getClassLoader()).iterator(); + while (iterator.hasNext()) { + try { + iterator.next(); + } catch (Exception ignore) {} + } + } catch (IOException e) { + throw new RuntimeException("Can't load config keys; services file issue.", e); + } + } + } +} diff --git a/src/core/lombok/eclipse/HandlerLibrary.java b/src/core/lombok/eclipse/HandlerLibrary.java index 1eb3c13a..ad9c87b9 100644 --- a/src/core/lombok/eclipse/HandlerLibrary.java +++ b/src/core/lombok/eclipse/HandlerLibrary.java @@ -35,10 +35,10 @@ import java.util.SortedSet; import java.util.TreeSet; import java.util.WeakHashMap; -import lombok.ConfigurationKeys; import lombok.Lombok; import lombok.core.AnnotationValues; import lombok.core.AnnotationValues.AnnotationValueDecodeFail; +import lombok.core.configuration.ConfigurationKeysLoader; import lombok.core.HandlerPriority; import lombok.core.SpiLoadUtil; import lombok.core.TypeLibrary; @@ -55,15 +55,13 @@ import org.eclipse.jdt.internal.compiler.ast.TypeReference; * building an AnnotationValues instance. */ public class HandlerLibrary { - static { - ConfigurationKeys.ensureKeysLoaded(); - } - /** * Creates a new HandlerLibrary. Errors will be reported to the Eclipse Error log. * You probably want to use {@link #load()} instead. */ - public HandlerLibrary() {} + public HandlerLibrary() { + ConfigurationKeysLoader.LoaderLoader.loadAllConfigurationKeys(); + } private TypeLibrary typeLibrary = new TypeLibrary(); diff --git a/src/core/lombok/javac/HandlerLibrary.java b/src/core/lombok/javac/HandlerLibrary.java index e28033c9..0905170b 100644 --- a/src/core/lombok/javac/HandlerLibrary.java +++ b/src/core/lombok/javac/HandlerLibrary.java @@ -35,12 +35,12 @@ import java.util.WeakHashMap; import javax.annotation.processing.Messager; import javax.tools.Diagnostic; -import lombok.ConfigurationKeys; import lombok.core.HandlerPriority; import lombok.core.SpiLoadUtil; import lombok.core.TypeLibrary; import lombok.core.TypeResolver; import lombok.core.AnnotationValues.AnnotationValueDecodeFail; +import lombok.core.configuration.ConfigurationKeysLoader; import lombok.javac.handlers.JavacHandlerUtil; import com.sun.tools.javac.tree.JCTree; @@ -54,10 +54,6 @@ import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; * building an AnnotationValues instance. */ public class HandlerLibrary { - static { - ConfigurationKeys.ensureKeysLoaded(); - } - private final TypeLibrary typeLibrary = new TypeLibrary(); private final Map<String, AnnotationHandlerContainer<?>> annotationHandlers = new HashMap<String, AnnotationHandlerContainer<?>>(); private final Collection<VisitorContainer> visitorHandlers = new ArrayList<VisitorContainer>(); @@ -68,6 +64,7 @@ public class HandlerLibrary { * You probably want to use {@link #load(Messager)} instead. */ public HandlerLibrary(Messager messager) { + ConfigurationKeysLoader.LoaderLoader.loadAllConfigurationKeys(); this.messager = messager; } |