From 66d4709855d57ae5703ab15fdf70d6ddce2d677d Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 24 Nov 2009 05:38:54 +0100 Subject: Added more thorough support for detecting we're running as an annotation processor on an unsupported platform, even giving useful suggestions about what you're doing wrong when we detect you're trying to do this on eclipse. Fixes ticket #53 --- .../DisableCheckedExceptionsAgent.java | 28 ++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'experimental/src/lombok/javac/disableCheckedExceptions/DisableCheckedExceptionsAgent.java') diff --git a/experimental/src/lombok/javac/disableCheckedExceptions/DisableCheckedExceptionsAgent.java b/experimental/src/lombok/javac/disableCheckedExceptions/DisableCheckedExceptionsAgent.java index 7c020a65..d31fd44b 100644 --- a/experimental/src/lombok/javac/disableCheckedExceptions/DisableCheckedExceptionsAgent.java +++ b/experimental/src/lombok/javac/disableCheckedExceptions/DisableCheckedExceptionsAgent.java @@ -30,6 +30,7 @@ import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; import javax.annotation.processing.SupportedSourceVersion; import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; import javax.tools.Diagnostic.Kind; @@ -39,24 +40,37 @@ import lombok.patcher.ScriptManager; import lombok.patcher.inject.LiveInjector; import lombok.patcher.scripts.ScriptBuilder; -import com.sun.tools.javac.processing.JavacProcessingEnvironment; - @SupportedAnnotationTypes("*") @SupportedSourceVersion(SourceVersion.RELEASE_6) public class DisableCheckedExceptionsAgent extends AbstractProcessor { + private String errorToShow; + /** Inject an agent if we're on a sun-esque JVM. */ @Override public void init(ProcessingEnvironment procEnv) { super.init(procEnv); - if (!(procEnv instanceof JavacProcessingEnvironment)) { - procEnv.getMessager().printMessage(Kind.WARNING, "You aren't using a compiler based around javac v1.6, so lombok will not work properly."); - this.processingEnv = null; + String className = procEnv.getClass().getName(); + if (className.startsWith("org.eclipse.jdt.")) { + errorToShow = "This version of disableCheckedExceptions is not compatible with eclipse. javac only; sorry."; + procEnv.getMessager().printMessage(Kind.WARNING, errorToShow); + } else if (!procEnv.getClass().getName().equals("com.sun.tools.javac.processing.JavacProcessingEnvironment")) { + procEnv.getMessager().printMessage(Kind.WARNING, "You aren't using a compiler based around javac v1.6, so disableCheckedExceptions will not work.\n" + + "Your processor class is: " + className); + } else { + new LiveInjector().inject(LiveInjector.findPathJar(DisableCheckedExceptionsAgent.class)); } - - new LiveInjector().inject(LiveInjector.findPathJar(DisableCheckedExceptionsAgent.class)); } /** Does nothing - we just wanted the init method so we can inject an agent. */ @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { + if (errorToShow != null) { + if (errorToShow != null) { + Set rootElements = roundEnv.getRootElements(); + if (!rootElements.isEmpty()) { + processingEnv.getMessager().printMessage(Kind.WARNING, errorToShow, rootElements.iterator().next()); + errorToShow = null; + } + } + } return false; } -- cgit