aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/eclipse/handlers
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-07-01 20:16:26 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-07-01 20:16:26 +0200
commitefe3931cf3d9134d7d8e5adf792b05a47ce2c423 (patch)
tree8ed8d2aa39ec902bf5601487d86ec7333cc06267 /src/lombok/eclipse/handlers
parent194c990f64165e0422b1f48a62cf1f77ccd52e43 (diff)
downloadlombok-efe3931cf3d9134d7d8e5adf792b05a47ce2c423.tar.gz
lombok-efe3931cf3d9134d7d8e5adf792b05a47ce2c423.tar.bz2
lombok-efe3931cf3d9134d7d8e5adf792b05a47ce2c423.zip
Added ability to @Synchronized to explicitly name the lock object.
Spruced up @Cleanup's position settings and also forced initialization, because the error appears in a screwed up place if you don't, and we can't seem to move it.
Diffstat (limited to 'src/lombok/eclipse/handlers')
-rw-r--r--src/lombok/eclipse/handlers/HandleCleanup.java21
-rw-r--r--src/lombok/eclipse/handlers/HandleSynchronized.java3
2 files changed, 21 insertions, 3 deletions
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);