aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok
diff options
context:
space:
mode:
authorRoel Spilker <r.spilker@gmail.com>2011-05-03 02:26:15 +0200
committerRoel Spilker <r.spilker@gmail.com>2011-05-03 02:26:15 +0200
commitb93a58298556aedaeef9e3d5fa4e53bc9b0ebe59 (patch)
tree5b9aa50af1f0b8648d8083bfe9f95e4f0ac4b618 /src/core/lombok
parente5e35213780a87c813b892d5efc1288125980baf (diff)
parent12e4f36a2f5aae5b17266fb15376c82d74b7bf95 (diff)
downloadlombok-b93a58298556aedaeef9e3d5fa4e53bc9b0ebe59.tar.gz
lombok-b93a58298556aedaeef9e3d5fa4e53bc9b0ebe59.tar.bz2
lombok-b93a58298556aedaeef9e3d5fa4e53bc9b0ebe59.zip
Merge branch 'master' of git@github.com:rzwitserloot/lombok
Diffstat (limited to 'src/core/lombok')
-rw-r--r--src/core/lombok/eclipse/Eclipse.java71
-rw-r--r--src/core/lombok/eclipse/HandlerLibrary.java2
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java21
-rw-r--r--src/core/lombok/eclipse/handlers/HandleCleanup.java43
-rw-r--r--src/core/lombok/javac/handlers/HandleCleanup.java8
5 files changed, 115 insertions, 30 deletions
diff --git a/src/core/lombok/eclipse/Eclipse.java b/src/core/lombok/eclipse/Eclipse.java
index ddba726a..8910bb3e 100644
--- a/src/core/lombok/eclipse/Eclipse.java
+++ b/src/core/lombok/eclipse/Eclipse.java
@@ -1,5 +1,5 @@
/*
- * Copyright © 2009 Reinier Zwitserloot and Roel Spilker.
+ * Copyright © 2009-2011 Reinier Zwitserloot and Roel Spilker.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -89,46 +89,85 @@ public class Eclipse {
/**
* Generates an error in the Eclipse error log. Note that most people never look at it!
+ *
+ * @param cud The {@code CompilationUnitDeclaration} where the error occurred.
+ * An error will be generated on line 0 linking to the error log entry. Can be {@code null}.
+ * @param message Human readable description of the problem.
+ * @param error The associated exception. Can be {@code null}.
*/
- public static void error(CompilationUnitDeclaration cud, String message) {
- error(cud, message, DEFAULT_BUNDLE, null);
+ public static void error(CompilationUnitDeclaration cud, String message, Throwable error) {
+ error(cud, message, null, error);
}
/**
* Generates an error in the Eclipse error log. Note that most people never look at it!
+ *
+ * @param cud The {@code CompilationUnitDeclaration} where the error occurred.
+ * An error will be generated on line 0 linking to the error log entry. Can be {@code null}.
+ * @param message Human readable description of the problem.
+ * @param bundleName Can be {@code null} to default to {@code org.eclipse.jdt.core} which is usually right.
+ * @param error The associated exception. Can be {@code null}.
*/
- public static void error(CompilationUnitDeclaration cud, String message, Throwable error) {
- error(cud, message, DEFAULT_BUNDLE, error);
+ public static void error(CompilationUnitDeclaration cud, String message, String bundleName, Throwable error) {
+ if (bundleName == null) bundleName = DEFAULT_BUNDLE;
+ try {
+ new EclipseWorkspaceLogger().error(message, bundleName, error);
+ } catch (NoClassDefFoundError e) { //standalone ecj does not jave Platform, ILog, IStatus, and friends.
+ new TerminalLogger().error(message, bundleName, error);
+ }
+ if (cud != null) EclipseAST.addProblemToCompilationResult(cud, false, message + " - See error log.", 0, 0);
}
/**
- * Generates an error in the Eclipse error log. Note that most people never look at it!
+ * Generates a warning in the Eclipse error log. Note that most people never look at it!
+ *
+ * @param cud The {@code CompilationUnitDeclaration} where the error occurred.
+ * An error will be generated on line 0 linking to the error log entry. Can be {@code null}.
+ * @param message Human readable description of the problem.
+ * @param error The associated exception. Can be {@code null}.
*/
- public static void error(CompilationUnitDeclaration cud, String message, String bundleName) {
- error(cud, message, bundleName, null);
+ public static void warning(String message, Throwable error) {
+ warning(message, null, error);
}
/**
- * Generates an error in the Eclipse error log. Note that most people never look at it!
+ * Generates a warning in the Eclipse error log. Note that most people never look at it!
+ *
+ * @param message Human readable description of the problem.
+ * @param bundleName Can be {@code null} to default to {@code org.eclipse.jdt.core} which is usually right.
+ * @param error The associated exception. Can be {@code null}.
*/
- public static void error(CompilationUnitDeclaration cud, String message, String bundleName, Throwable error) {
+ public static void warning(String message, String bundleName, Throwable error) {
+ if (bundleName == null) bundleName = DEFAULT_BUNDLE;
try {
- new EclipseWorkspaceLogger().error(message, bundleName, error);
- } catch (NoClassDefFoundError e) { //standalone ecj does not jave Platform, ILog, IStatus, and friends.
- new TerminalLogger().error(message, bundleName, error);
+ new EclipseWorkspaceLogger().warning(message, bundleName, error);
+ } catch (NoClassDefFoundError e) { //standalone ecj does not jave Platform, ILog, IStatus, and friends.
+ new TerminalLogger().warning(message, bundleName, error);
}
- if (cud != null) EclipseAST.addProblemToCompilationResult(cud, false, message + " - See error log.", 0, 0);
}
private static class TerminalLogger {
void error(String message, String bundleName, Throwable error) {
System.err.println(message);
- error.printStackTrace();
+ if (error != null) error.printStackTrace();
+ }
+
+ void warning(String message, String bundleName, Throwable error) {
+ System.err.println(message);
+ if (error != null) error.printStackTrace();
}
}
private static class EclipseWorkspaceLogger {
void error(String message, String bundleName, Throwable error) {
+ msg(IStatus.ERROR, message, bundleName, error);
+ }
+
+ void warning(String message, String bundleName, Throwable error) {
+ msg(IStatus.WARNING, message, bundleName, error);
+ }
+
+ private void msg(int msgType, String message, String bundleName, Throwable error) {
Bundle bundle = Platform.getBundle(bundleName);
if (bundle == null) {
System.err.printf("Can't find bundle %s while trying to report error:\n%s\n", bundleName, message);
@@ -137,7 +176,7 @@ public class Eclipse {
ILog log = Platform.getLog(bundle);
- log.log(new Status(IStatus.ERROR, bundleName, message, error));
+ log.log(new Status(msgType, bundleName, message, error));
}
}
diff --git a/src/core/lombok/eclipse/HandlerLibrary.java b/src/core/lombok/eclipse/HandlerLibrary.java
index df4681f0..ba7f891a 100644
--- a/src/core/lombok/eclipse/HandlerLibrary.java
+++ b/src/core/lombok/eclipse/HandlerLibrary.java
@@ -103,7 +103,7 @@ public class HandlerLibrary {
SpiLoadUtil.findAnnotationClass(handler.getClass(), EclipseAnnotationHandler.class);
AnnotationHandlerContainer<?> container = new AnnotationHandlerContainer(handler, annotationClass);
if (lib.annotationHandlers.put(container.annotationClass.getName(), container) != null) {
- Eclipse.error(null, "Duplicate handlers for annotation type: " + container.annotationClass.getName());
+ Eclipse.error(null, "Duplicate handlers for annotation type: " + container.annotationClass.getName(), null);
}
lib.typeLibrary.addType(container.annotationClass.getName());
} catch (Throwable t) {
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index a2867c39..4d397a3c 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -506,6 +506,27 @@ public class EclipseHandlerUtil {
method.annotations = createSuppressWarningsAll(method, method.annotations);
TypeDeclaration parent = (TypeDeclaration) type.get();
+ if (parent.scope != null && method.scope == null) {
+ // We think this means heisenbug #164 is about to happen later in some other worker thread.
+ // To improve our ability to figure out what the heck is going on, let's generate a log so we can ask those who stumble on this about it,
+ // and thus see a far more useful stack trace.
+ boolean report = true;
+ for (StackTraceElement elem : Thread.currentThread().getStackTrace()) {
+ // We intentionally hook into the middle of ClassScope filling in BlockScopes for PatchDelegate,
+ // meaning that will trigger a false positive. Detect it and do not report the occurence of #164 if so.
+ if ("lombok.eclipse.agent.PatchDelegate".equals(elem.getClassName())) {
+ report = false;
+ break;
+ }
+ }
+
+ if (report) {
+ Eclipse.warning("We believe you may have just stumbled on lombok issue #164. Please " +
+ "report the stack trace associated with this message at:\n" +
+ "http://code.google.com/p/projectlombok/issues/detail?id=164", new Throwable());
+ }
+ }
+
if (parent.methods == null) {
parent.methods = new AbstractMethodDeclaration[1];
parent.methods[0] = method;
diff --git a/src/core/lombok/eclipse/handlers/HandleCleanup.java b/src/core/lombok/eclipse/handlers/HandleCleanup.java
index 964653bc..9a63ce47 100644
--- a/src/core/lombok/eclipse/handlers/HandleCleanup.java
+++ b/src/core/lombok/eclipse/handlers/HandleCleanup.java
@@ -42,6 +42,7 @@ import org.eclipse.jdt.internal.compiler.ast.CastExpression;
import org.eclipse.jdt.internal.compiler.ast.EqualExpression;
import org.eclipse.jdt.internal.compiler.ast.Expression;
import org.eclipse.jdt.internal.compiler.ast.IfStatement;
+import org.eclipse.jdt.internal.compiler.ast.IntLiteral;
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
import org.eclipse.jdt.internal.compiler.ast.MemberValuePair;
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
@@ -174,16 +175,7 @@ public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> {
NullLiteral nullLiteral = new NullLiteral(pS, pE);
Eclipse.setGeneratedBy(nullLiteral, ast);
- MessageSend preventNullAnalysis = new MessageSend();
- Eclipse.setGeneratedBy(preventNullAnalysis, ast);
-
- preventNullAnalysis.receiver = createNameReference("lombok.Lombok", ast);
- preventNullAnalysis.selector = "preventNullAnalysis".toCharArray();
-
- preventNullAnalysis.arguments = new Expression[] { varName };
- preventNullAnalysis.nameSourcePosition = p;
- preventNullAnalysis.sourceStart = pS;
- preventNullAnalysis.sourceEnd = preventNullAnalysis.statementEnd = pE;
+ MessageSend preventNullAnalysis = preventNullAnalysis(ast, varName);
EqualExpression equalExpression = new EqualExpression(preventNullAnalysis, nullLiteral, OperatorIds.NOT_EQUAL);
equalExpression.sourceStart = pS; equalExpression.sourceEnd = pE;
@@ -195,8 +187,6 @@ public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> {
Eclipse.setGeneratedBy(closeBlock, ast);
IfStatement ifStatement = new IfStatement(equalExpression, closeBlock, 0, 0);
Eclipse.setGeneratedBy(ifStatement, ast);
-
-
finallyBlock[0] = ifStatement;
tryStatement.finallyBlock = new Block(0);
@@ -219,6 +209,35 @@ public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> {
return true;
}
+ private MessageSend preventNullAnalysis(Annotation ast, Expression expr) {
+ MessageSend singletonList = new MessageSend();
+ Eclipse.setGeneratedBy(singletonList, ast);
+
+ int pS = ast.sourceStart, pE = ast.sourceEnd;
+ long p = (long)pS << 32 | pE;
+
+ singletonList.receiver = createNameReference("java.util.Collections", ast);
+ singletonList.selector = "singletonList".toCharArray();
+
+ singletonList.arguments = new Expression[] { expr };
+ singletonList.nameSourcePosition = p;
+ singletonList.sourceStart = pS;
+ singletonList.sourceEnd = singletonList.statementEnd = pE;
+
+ MessageSend preventNullAnalysis = new MessageSend();
+ Eclipse.setGeneratedBy(preventNullAnalysis, ast);
+
+ preventNullAnalysis.receiver = singletonList;
+ preventNullAnalysis.selector = "get".toCharArray();
+
+ preventNullAnalysis.arguments = new Expression[] { new IntLiteral(new char[] { '0' }, pS, pE) };
+ preventNullAnalysis.nameSourcePosition = p;
+ preventNullAnalysis.sourceStart = pS;
+ preventNullAnalysis.sourceEnd = singletonList.statementEnd = pE;
+
+ return preventNullAnalysis;
+ }
+
private void doAssignmentCheck(EclipseNode node, Statement[] tryBlock, char[] varName) {
for (Statement statement : tryBlock) doAssignmentCheck0(node, statement, varName);
}
diff --git a/src/core/lombok/javac/handlers/HandleCleanup.java b/src/core/lombok/javac/handlers/HandleCleanup.java
index 9e2fddf6..b681ab28 100644
--- a/src/core/lombok/javac/handlers/HandleCleanup.java
+++ b/src/core/lombok/javac/handlers/HandleCleanup.java
@@ -117,7 +117,7 @@ public class HandleCleanup implements JavacAnnotationHandler<Cleanup> {
List<JCStatement> cleanupCall = List.<JCStatement>of(maker.Exec(
maker.Apply(List.<JCExpression>nil(), cleanupMethod, List.<JCExpression>nil())));
- JCMethodInvocation preventNullAnalysis = maker.Apply(List.<JCExpression>nil(), JavacHandlerUtil.chainDotsString(maker, annotationNode, "lombok.Lombok.preventNullAnalysis"), List.<JCExpression>of(maker.Ident(decl.name)));
+ JCMethodInvocation preventNullAnalysis = preventNullAnalysis(maker, annotationNode, maker.Ident(decl.name));
JCBinary isNull = maker.Binary(Javac.getCTCint(JCTree.class, "NE"), preventNullAnalysis, maker.Literal(Javac.getCTCint(TypeTags.class, "BOT"), null));
JCIf ifNotNullCleanup = maker.If(isNull, maker.Block(0, cleanupCall), null);
@@ -139,6 +139,12 @@ public class HandleCleanup implements JavacAnnotationHandler<Cleanup> {
return true;
}
+ private JCMethodInvocation preventNullAnalysis(TreeMaker maker, JavacNode node, JCExpression expression) {
+ JCMethodInvocation singletonList = maker.Apply(List.<JCExpression>nil(), JavacHandlerUtil.chainDotsString(maker, node, "java.util.Collections.singletonList"), List.of(expression));
+ JCMethodInvocation cleanedExpr = maker.Apply(List.<JCExpression>nil(), maker.Select(singletonList, node.toName("get")) , List.<JCExpression>of(maker.Literal(TypeTags.INT, 0)));
+ return cleanedExpr;
+ }
+
private void doAssignmentCheck(JavacNode node, List<JCStatement> statements, Name name) {
for (JCStatement statement : statements) doAssignmentCheck0(node, statement, name);
}