diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-11-24 05:38:54 +0100 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-11-24 05:38:54 +0100 |
commit | 66d4709855d57ae5703ab15fdf70d6ddce2d677d (patch) | |
tree | 9c5aca3914a66425e5e2a2fafcd2fda87e89ae1b /experimental/src/lombok/javac/disableCheckedExceptions/DisableCheckedExceptionsAgent.java | |
parent | 45de32ff6ddbe20b8d386f343ef291c57c5fae74 (diff) | |
download | lombok-66d4709855d57ae5703ab15fdf70d6ddce2d677d.tar.gz lombok-66d4709855d57ae5703ab15fdf70d6ddce2d677d.tar.bz2 lombok-66d4709855d57ae5703ab15fdf70d6ddce2d677d.zip |
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
Diffstat (limited to 'experimental/src/lombok/javac/disableCheckedExceptions/DisableCheckedExceptionsAgent.java')
-rw-r--r-- | experimental/src/lombok/javac/disableCheckedExceptions/DisableCheckedExceptionsAgent.java | 28 |
1 files changed, 21 insertions, 7 deletions
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<? extends TypeElement> annotations, RoundEnvironment roundEnv) { + if (errorToShow != null) { + if (errorToShow != null) { + Set<? extends Element> rootElements = roundEnv.getRootElements(); + if (!rootElements.isEmpty()) { + processingEnv.getMessager().printMessage(Kind.WARNING, errorToShow, rootElements.iterator().next()); + errorToShow = null; + } + } + } return false; } |