From 6bf2b9299d2f1bcc00b8a0f253aae8fd4fcb6baa Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Wed, 11 Jul 2012 00:49:00 +0200 Subject: Made lombok more stable in netbeans based on some smart observations by Jan Lahoda of team Netbeans. --- src/core/lombok/javac/handlers/HandleCleanup.java | 8 +++++--- src/core/lombok/javac/handlers/HandleSynchronized.java | 4 +++- src/core/lombok/javac/handlers/JavacHandlerUtil.java | 11 +++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/core/lombok/javac/handlers/HandleCleanup.java b/src/core/lombok/javac/handlers/HandleCleanup.java index fc74e319..29862e61 100644 --- a/src/core/lombok/javac/handlers/HandleCleanup.java +++ b/src/core/lombok/javac/handlers/HandleCleanup.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2011 The Project Lombok Authors. + * Copyright (C) 2009-2012 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 @@ -23,8 +23,8 @@ package lombok.javac.handlers; import static lombok.javac.handlers.JavacHandlerUtil.*; import lombok.Cleanup; -import lombok.core.AnnotationValues; import lombok.core.AST.Kind; +import lombok.core.AnnotationValues; import lombok.javac.Javac; import lombok.javac.JavacAnnotationHandler; import lombok.javac.JavacNode; @@ -33,7 +33,6 @@ import org.mangosdk.spi.ProviderFor; import com.sun.tools.javac.code.TypeTags; import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.tree.TreeMaker; import com.sun.tools.javac.tree.JCTree.JCAnnotation; import com.sun.tools.javac.tree.JCTree.JCAssign; import com.sun.tools.javac.tree.JCTree.JCBinary; @@ -50,6 +49,7 @@ import com.sun.tools.javac.tree.JCTree.JCMethodInvocation; import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.tree.JCTree.JCTypeCast; import com.sun.tools.javac.tree.JCTree.JCVariableDecl; +import com.sun.tools.javac.tree.TreeMaker; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; @@ -60,6 +60,8 @@ import com.sun.tools.javac.util.Name; @ProviderFor(JavacAnnotationHandler.class) public class HandleCleanup extends JavacAnnotationHandler { @Override public void handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { + if (inNetbeansEditor(annotationNode)) return; + deleteAnnotationIfNeccessary(annotationNode, Cleanup.class); String cleanupName = annotation.getInstance().value(); if (cleanupName.length() == 0) { diff --git a/src/core/lombok/javac/handlers/HandleSynchronized.java b/src/core/lombok/javac/handlers/HandleSynchronized.java index 7a9a49ff..04668317 100644 --- a/src/core/lombok/javac/handlers/HandleSynchronized.java +++ b/src/core/lombok/javac/handlers/HandleSynchronized.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2011 The Project Lombok Authors. + * Copyright (C) 2009-2012 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 @@ -52,6 +52,8 @@ public class HandleSynchronized extends JavacAnnotationHandler { private static final String STATIC_LOCK_NAME = "$LOCK"; @Override public void handle(AnnotationValues annotation, JCAnnotation ast, JavacNode annotationNode) { + if (inNetbeansEditor(annotationNode)) return; + deleteAnnotationIfNeccessary(annotationNode, Synchronized.class); JavacNode methodNode = annotationNode.up(); diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index 6dc97fd4..308e0325 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -68,6 +68,7 @@ import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Name; +import com.sun.tools.javac.util.Options; /** * Container for static utility methods useful to handlers written for javac. @@ -92,6 +93,16 @@ public class JavacHandlerUtil { private static Map> generatedNodes = new WeakHashMap>(); + /** + * Contributed by Jan Lahoda; many lombok transformations should not be run (or a lite version should be run) when the netbeans editor + * is running javac on the open source file to find inline errors and such. As class files are compiled separately this does not affect + * actual runtime behaviour or file output of the netbeans IDE. + */ + public static boolean inNetbeansEditor(JavacNode node) { + Options options = Options.instance(node.getContext()); + return (options.keySet().contains("ide") && !options.keySet().contains("backgroundCompilation")); + } + public static JCTree getGeneratedBy(JCTree node) { synchronized (generatedNodes) { WeakReference ref = generatedNodes.get(node); -- cgit