mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 08:18:29 +00:00
[configuration] added a service-loader based way to load ConfigurationKeys, so that third party additions can add their own.
This commit is contained in:
1 parent
bc1f91af3a
commit
a016e623de
5 files changed
+57
-20
No files matched your search
@@ -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 -----
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user