aboutsummaryrefslogtreecommitdiff
path: root/src/lombok
diff options
context:
space:
mode:
Diffstat (limited to 'src/lombok')
-rw-r--r--src/lombok/Synchronized.java4
-rw-r--r--src/lombok/eclipse/handlers/HandleCleanup.java21
-rw-r--r--src/lombok/eclipse/handlers/HandleSynchronized.java3
-rw-r--r--src/lombok/javac/handlers/HandleCleanup.java7
-rw-r--r--src/lombok/javac/handlers/HandleSynchronized.java3
5 files changed, 32 insertions, 6 deletions
diff --git a/src/lombok/Synchronized.java b/src/lombok/Synchronized.java
index f7ab900c..0c813eb7 100644
--- a/src/lombok/Synchronized.java
+++ b/src/lombok/Synchronized.java
@@ -7,4 +7,6 @@ import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
-public @interface Synchronized {}
+public @interface Synchronized {
+ String value() default "";
+}
diff --git a/src/lombok/eclipse/handlers/HandleCleanup.java b/src/lombok/eclipse/handlers/HandleCleanup.java
index fa97e76d..b5251e8a 100644
--- a/src/lombok/eclipse/handlers/HandleCleanup.java
+++ b/src/lombok/eclipse/handlers/HandleCleanup.java
@@ -16,6 +16,7 @@ import org.eclipse.jdt.internal.compiler.ast.Block;
import org.eclipse.jdt.internal.compiler.ast.CaseStatement;
import org.eclipse.jdt.internal.compiler.ast.CastExpression;
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.MemberValuePair;
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
import org.eclipse.jdt.internal.compiler.ast.Statement;
@@ -39,6 +40,11 @@ public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> {
LocalDeclaration decl = (LocalDeclaration)annotationNode.up().get();
+ if ( decl.initialization == null ) {
+ annotationNode.addError("@Cleanup variable declarations need to be initialized.");
+ return true;
+ }
+
Node ancestor = annotationNode.up().directUp();
ASTNode blockNode = ancestor.get();
@@ -110,7 +116,18 @@ public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> {
Statement[] finallyBlock = new Statement[1];
MessageSend unsafeClose = new MessageSend();
- unsafeClose.receiver = new SingleNameReference(decl.name, 0);
+ unsafeClose.sourceStart = ast.sourceStart;
+ unsafeClose.sourceEnd = ast.sourceEnd;
+ SingleNameReference receiver = new SingleNameReference(decl.name, 0);
+ unsafeClose.receiver = receiver;
+ long nameSourcePosition = (long)ast.sourceStart << 32 | ast.sourceEnd;
+ if ( ast.memberValuePairs() != null ) for ( MemberValuePair pair : ast.memberValuePairs() ) {
+ if ( pair.name != null && new String(pair.name).equals("cleanupMethod") ) {
+ nameSourcePosition = (long)pair.value.sourceStart << 32 | pair.value.sourceEnd;
+ break;
+ }
+ }
+ unsafeClose.nameSourcePosition = nameSourcePosition;
unsafeClose.selector = cleanupName.toCharArray();
finallyBlock[0] = unsafeClose;
tryStatement.finallyBlock = new Block(0);
@@ -148,7 +165,7 @@ public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> {
if ( Arrays.equals(((SingleNameReference)statement).token, varName) ) {
Node problemNode = node.getNodeFor(statement);
if ( problemNode != null ) problemNode.addWarning(
- "You're assigning a guarded variable to something else. This is a bad idea.");
+ "You're assigning an auto-cleanup variable to something else. This is a bad idea.");
}
}
}
diff --git a/src/lombok/eclipse/handlers/HandleSynchronized.java b/src/lombok/eclipse/handlers/HandleSynchronized.java
index 28e8bd1f..e1d4ed6a 100644
--- a/src/lombok/eclipse/handlers/HandleSynchronized.java
+++ b/src/lombok/eclipse/handlers/HandleSynchronized.java
@@ -48,7 +48,8 @@ public class HandleSynchronized implements EclipseAnnotationHandler<Synchronized
return true;
}
- char[] lockName = method.isStatic() ? STATIC_LOCK_NAME : INSTANCE_LOCK_NAME;
+ char[] lockName = annotation.getInstance().value().toCharArray();
+ if ( lockName.length == 0 ) lockName = method.isStatic() ? STATIC_LOCK_NAME : INSTANCE_LOCK_NAME;
if ( fieldExists(new String(lockName), methodNode) == MemberExistsResult.NOT_EXISTS ) {
FieldDeclaration fieldDecl = new FieldDeclaration(lockName, 0, -1);
diff --git a/src/lombok/javac/handlers/HandleCleanup.java b/src/lombok/javac/handlers/HandleCleanup.java
index 9a8cf516..39f2c242 100644
--- a/src/lombok/javac/handlers/HandleCleanup.java
+++ b/src/lombok/javac/handlers/HandleCleanup.java
@@ -42,6 +42,11 @@ public class HandleCleanup implements JavacAnnotationHandler<Cleanup> {
JCVariableDecl decl = (JCVariableDecl)annotationNode.up().get();
+ if ( decl.init == null ) {
+ annotationNode.addError("@Cleanup variable declarations need to be initialized.");
+ return true;
+ }
+
Node ancestor = annotationNode.up().directUp();
JCTree blockNode = ancestor.get();
@@ -109,7 +114,7 @@ public class HandleCleanup implements JavacAnnotationHandler<Cleanup> {
if ( ((JCIdent)statement).name.contentEquals(name) ) {
Node problemNode = node.getNodeFor(statement);
if ( problemNode != null ) problemNode.addWarning(
- "You're assigning a guarded variable to something else. This is a bad idea.");
+ "You're assigning an auto-cleanup variable to something else. This is a bad idea.");
}
}
}
diff --git a/src/lombok/javac/handlers/HandleSynchronized.java b/src/lombok/javac/handlers/HandleSynchronized.java
index 4acb6e27..84508171 100644
--- a/src/lombok/javac/handlers/HandleSynchronized.java
+++ b/src/lombok/javac/handlers/HandleSynchronized.java
@@ -41,7 +41,8 @@ public class HandleSynchronized implements JavacAnnotationHandler<Synchronized>
return true;
}
boolean isStatic = (method.mods.flags & Flags.STATIC) != 0;
- String lockName = isStatic ? STATIC_LOCK_NAME : INSTANCE_LOCK_NAME;
+ String lockName = annotation.getInstance().value();
+ if ( lockName.length() == 0 ) lockName = isStatic ? STATIC_LOCK_NAME : INSTANCE_LOCK_NAME;
TreeMaker maker = methodNode.getTreeMaker();