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 --- src/lombok/javac/apt/Processor.java | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/lombok/javac/apt/Processor.java') diff --git a/src/lombok/javac/apt/Processor.java b/src/lombok/javac/apt/Processor.java index 1ff1ee88..9c851762 100644 --- a/src/lombok/javac/apt/Processor.java +++ b/src/lombok/javac/apt/Processor.java @@ -64,26 +64,46 @@ import com.sun.tools.javac.tree.JCTree.JCVariableDecl; @SupportedAnnotationTypes("*") @SupportedSourceVersion(SourceVersion.RELEASE_6) public class Processor extends AbstractProcessor { + private ProcessingEnvironment rawProcessingEnv; private JavacProcessingEnvironment processingEnv; private HandlerLibrary handlers; private Trees trees; + private String errorToShow; /** {@inheritDoc} */ @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.rawProcessingEnv = procEnv; + String className = procEnv.getClass().getName(); + if (className.startsWith("org.eclipse.jdt.")) { + errorToShow = "You should not install lombok.jar as an annotation processor in eclipse. Instead, run lombok.jar as a java application and follow the instructions."; + procEnv.getMessager().printMessage(Kind.WARNING, errorToShow); this.processingEnv = null; + } 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 lombok will not work properly.\n" + + "Your processor class is: " + className); + this.processingEnv = null; + this.errorToShow = null; } else { this.processingEnv = (JavacProcessingEnvironment) procEnv; handlers = HandlerLibrary.load(procEnv.getMessager()); trees = Trees.instance(procEnv); + this.errorToShow = null; } } /** {@inheritDoc} */ @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { - if (processingEnv == null) return false; + if (processingEnv == null) { + if (errorToShow != null) { + Set rootElements = roundEnv.getRootElements(); + if (!rootElements.isEmpty()) { + rawProcessingEnv.getMessager().printMessage(Kind.WARNING, errorToShow, rootElements.iterator().next()); + errorToShow = null; + } + } + return false; + } IdentityHashMap units = new IdentityHashMap(); for (Element element : roundEnv.getRootElements()) { -- cgit