aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2012-07-16 22:51:56 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2012-07-16 22:51:56 +0200
commitfe4985e2127e5fc54a0a1ae3c2c4fef17789f8bd (patch)
tree5274a2a3644715bb9ca644861d4b3c1f555c6b7c /src
parentb1877a77be41695259108d2c755c87051b3f0d07 (diff)
downloadlombok-fe4985e2127e5fc54a0a1ae3c2c4fef17789f8bd.tar.gz
lombok-fe4985e2127e5fc54a0a1ae3c2c4fef17789f8bd.tar.bz2
lombok-fe4985e2127e5fc54a0a1ae3c2c4fef17789f8bd.zip
Added setting position of generated nodes in javac's @Synchronized as a 'pilot' to see if we cause any problems with this approach. It does generate nicer error messages!
Example: Using @Synchronized with named lock on a static method, naming a non-existent or instance lock. That used to error on line -1.
Diffstat (limited to 'src')
-rw-r--r--src/core/lombok/javac/handlers/HandleSynchronized.java8
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java26
2 files changed, 27 insertions, 7 deletions
diff --git a/src/core/lombok/javac/handlers/HandleSynchronized.java b/src/core/lombok/javac/handlers/HandleSynchronized.java
index 04668317..1ba8d131 100644
--- a/src/core/lombok/javac/handlers/HandleSynchronized.java
+++ b/src/core/lombok/javac/handlers/HandleSynchronized.java
@@ -78,16 +78,16 @@ public class HandleSynchronized extends JavacAnnotationHandler<Synchronized> {
lockName = isStatic ? STATIC_LOCK_NAME : INSTANCE_LOCK_NAME;
}
- TreeMaker maker = methodNode.getTreeMaker();
+ TreeMaker maker = methodNode.getTreeMaker().at(ast.pos);
if (fieldExists(lockName, methodNode) == MemberExistsResult.NOT_EXISTS) {
if (!autoMake) {
annotationNode.addError("The field " + lockName + " does not exist.");
return;
}
- JCExpression objectType = chainDots(methodNode, "java", "lang", "Object");
+ JCExpression objectType = chainDots(methodNode, ast.pos, "java", "lang", "Object");
//We use 'new Object[0];' because unlike 'new Object();', empty arrays *ARE* serializable!
- JCNewArray newObjectArray = maker.NewArray(chainDots(methodNode, "java", "lang", "Object"),
+ JCNewArray newObjectArray = maker.NewArray(chainDots(methodNode, ast.pos, "java", "lang", "Object"),
List.<JCExpression>of(maker.Literal(Javac.getCtcInt(TypeTags.class, "INT"), 0)), null);
JCVariableDecl fieldDecl = recursiveSetGeneratedBy(maker.VarDef(
maker.Modifiers(Flags.PRIVATE | Flags.FINAL | (isStatic ? Flags.STATIC : 0)),
@@ -99,7 +99,7 @@ public class HandleSynchronized extends JavacAnnotationHandler<Synchronized> {
JCExpression lockNode;
if (isStatic) {
- lockNode = chainDots(methodNode, methodNode.up().getName(), lockName);
+ lockNode = chainDots(methodNode, ast.pos, methodNode.up().getName(), lockName);
} else {
lockNode = maker.Select(maker.Ident(methodNode.toName("this")), methodNode.toName(lockName));
}
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index 437ba6cb..d2905101 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -746,6 +746,8 @@ public class JavacHandlerUtil {
* In javac, dotted access of any kind, from {@code java.lang.String} to {@code var.methodName}
* is represented by a fold-left of {@code Select} nodes with the leftmost string represented by
* a {@code Ident} node. This method generates such an expression.
+ * <p>
+ * The position of the generated node(s) will be unpositioned (-1).
*
* For example, maker.Select(maker.Select(maker.Ident(NAME[java]), NAME[lang]), NAME[String]).
*
@@ -753,12 +755,30 @@ public class JavacHandlerUtil {
* @see com.sun.tools.javac.tree.JCTree.JCFieldAccess
*/
public static JCExpression chainDots(JavacNode node, String... elems) {
+ return chainDots(node, -1, elems);
+ }
+
+ /**
+ * In javac, dotted access of any kind, from {@code java.lang.String} to {@code var.methodName}
+ * is represented by a fold-left of {@code Select} nodes with the leftmost string represented by
+ * a {@code Ident} node. This method generates such an expression.
+ * <p>
+ * The position of the generated node(s) will be equal to the {@code pos} parameter.
+ *
+ * For example, maker.Select(maker.Select(maker.Ident(NAME[java]), NAME[lang]), NAME[String]).
+ *
+ * @see com.sun.tools.javac.tree.JCTree.JCIdent
+ * @see com.sun.tools.javac.tree.JCTree.JCFieldAccess
+ */
+ public static JCExpression chainDots(JavacNode node, int pos, String... elems) {
assert elems != null;
assert elems.length > 0;
- JCExpression e = node.getTreeMaker().Ident(node.toName(elems[0]));
+ TreeMaker maker = node.getTreeMaker();
+ if (pos != -1) maker = maker.at(pos);
+ JCExpression e = maker.Ident(node.toName(elems[0]));
for (int i = 1 ; i < elems.length ; i++) {
- e = node.getTreeMaker().Select(e, node.toName(elems[i]));
+ e = maker.Select(e, node.toName(elems[i]));
}
return e;
@@ -776,7 +796,7 @@ public class JavacHandlerUtil {
* @see com.sun.tools.javac.tree.JCTree.JCFieldAccess
*/
public static JCExpression chainDotsString(JavacNode node, String elems) {
- return chainDots(node, elems.split("\\."));
+ return chainDots(node, elems.split("\\."));
}
/**