From f9264b78e47262cd285e9c219954a5c5120cb25e Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Wed, 23 Dec 2009 03:34:15 +0100 Subject: HandlerLibrary now uses the proper context. --- src/core/lombok/core/SpiLoadUtil.java | 6 ++++-- src/core/lombok/eclipse/HandlerLibrary.java | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/core/lombok') diff --git a/src/core/lombok/core/SpiLoadUtil.java b/src/core/lombok/core/SpiLoadUtil.java index c068bf61..143cba13 100644 --- a/src/core/lombok/core/SpiLoadUtil.java +++ b/src/core/lombok/core/SpiLoadUtil.java @@ -90,7 +90,8 @@ public class SpiLoadUtil { * @param loader The classloader object to use to both the spi discovery files, as well as the loader to use * to make the returned instances. */ - public static Iterable findServices(final Class target, final ClassLoader loader) throws IOException { + public static Iterable findServices(final Class target, ClassLoader loader) throws IOException { + if (loader == null) loader = ClassLoader.getSystemClassLoader(); Enumeration resources = loader.getResources("META-INF/services/" + target.getName()); final Set entries = new LinkedHashSet(); while (resources.hasMoreElements()) { @@ -99,6 +100,7 @@ public class SpiLoadUtil { } final Iterator names = entries.iterator(); + final ClassLoader fLoader = loader; return new Iterable () { @Override public Iterator iterator() { return new Iterator() { @@ -108,7 +110,7 @@ public class SpiLoadUtil { @Override public C next() { try { - return target.cast(Class.forName(names.next(), true, loader).newInstance()); + return target.cast(Class.forName(names.next(), true, fLoader).newInstance()); } catch (Throwable t) { throw Lombok.sneakyThrow(t); } diff --git a/src/core/lombok/eclipse/HandlerLibrary.java b/src/core/lombok/eclipse/HandlerLibrary.java index 36c41504..1be01459 100644 --- a/src/core/lombok/eclipse/HandlerLibrary.java +++ b/src/core/lombok/eclipse/HandlerLibrary.java @@ -96,7 +96,7 @@ public class HandlerLibrary { /** Uses SPI Discovery to find implementations of {@link EclipseAnnotationHandler}. */ @SuppressWarnings("unchecked") private static void loadAnnotationHandlers(HandlerLibrary lib) { try { - for (EclipseAnnotationHandler handler : SpiLoadUtil.findServices(EclipseAnnotationHandler.class)) { + for (EclipseAnnotationHandler handler : SpiLoadUtil.findServices(EclipseAnnotationHandler.class, EclipseAnnotationHandler.class.getClassLoader())) { try { Class annotationClass = SpiLoadUtil.findAnnotationClass(handler.getClass(), EclipseAnnotationHandler.class); @@ -117,7 +117,7 @@ public class HandlerLibrary { /** Uses SPI Discovery to find implementations of {@link EclipseASTVisitor}. */ private static void loadVisitorHandlers(HandlerLibrary lib) { try { - for (EclipseASTVisitor visitor : SpiLoadUtil.findServices(EclipseASTVisitor.class)) { + for (EclipseASTVisitor visitor : SpiLoadUtil.findServices(EclipseASTVisitor.class, EclipseASTVisitor.class.getClassLoader())) { lib.visitorHandlers.add(visitor); } } catch (Throwable t) { -- cgit