aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--buildScripts/ivy.xml2
-rw-r--r--src/core/lombok/core/PrintAST.java7
-rw-r--r--src/core/lombok/eclipse/EclipseASTVisitor.java43
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java28
-rw-r--r--src/core/lombok/eclipse/handlers/HandlePrintAST.java2
5 files changed, 41 insertions, 41 deletions
diff --git a/buildScripts/ivy.xml b/buildScripts/ivy.xml
index 334a38d9..de19afbf 100644
--- a/buildScripts/ivy.xml
+++ b/buildScripts/ivy.xml
@@ -21,7 +21,7 @@
<dependency org="org.slf4j" name="slf4j-api" rev="1.6.1" conf="test->default; contrib->sources"/>
<dependency org="com.googlecode.jarjar" name="jarjar" rev="1.1" conf="build->default" />
- <dependency org="org.apache.ant" name="ant" rev="1.8.0" conf="build->default; contrib->sources" />
+ <dependency org="org.apache.ant" name="ant" rev="1.8.1" conf="build->default; contrib->sources" />
<dependency org="projectlombok.org" name="spi" rev="0.2.4" conf="build" />
<dependency org="projectlombok.org" name="ant-googlecode" rev="0.0.2" conf="build" />
<dependency org="com.jcraft" name="jsch" rev="0.1.42" conf="build->default" />
diff --git a/src/core/lombok/core/PrintAST.java b/src/core/lombok/core/PrintAST.java
index 70383003..93680de0 100644
--- a/src/core/lombok/core/PrintAST.java
+++ b/src/core/lombok/core/PrintAST.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 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
@@ -48,4 +48,9 @@ public @interface PrintAST {
* its node structure (e.g. node classname) is printed, and this process is repeated for all children.
*/
boolean printContent() default false;
+
+ /**
+ * if {@code true} prints the start and end position of each node.
+ */
+ boolean printPositions() default false;
}
diff --git a/src/core/lombok/eclipse/EclipseASTVisitor.java b/src/core/lombok/eclipse/EclipseASTVisitor.java
index c51a2e87..e73729e2 100644
--- a/src/core/lombok/eclipse/EclipseASTVisitor.java
+++ b/src/core/lombok/eclipse/EclipseASTVisitor.java
@@ -113,6 +113,7 @@ public interface EclipseASTVisitor {
private int disablePrinting = 0;
private int indent = 0;
private boolean printClassNames = false;
+ private final boolean printPositions;
public boolean deferUntilPostDiet() {
return false;
@@ -123,7 +124,7 @@ public interface EclipseASTVisitor {
* instead of a tree listing of every AST node inside it.
*/
public Printer(boolean printContent) {
- this(printContent, System.out);
+ this(printContent, System.out, false);
}
/**
@@ -133,9 +134,10 @@ public interface EclipseASTVisitor {
*
* @see java.io.PrintStream#flush()
*/
- public Printer(boolean printContent, PrintStream out) {
+ public Printer(boolean printContent, PrintStream out, boolean printPositions) {
this.printContent = printContent;
this.out = out;
+ this.printPositions = printPositions;
}
private void forcePrint(String text, Object... params) {
@@ -188,7 +190,7 @@ public interface EclipseASTVisitor {
out.println("---------------------------------------------------------");
out.println(node.isCompleteParse() ? "COMPLETE" : "incomplete");
- print("<CUD %s%s>", node.getFileName(), isGenerated(unit) ? " (GENERATED)" : "");
+ print("<CUD %s%s%s>", node.getFileName(), isGenerated(unit) ? " (GENERATED)" : "", position(node));
indent++;
}
@@ -198,7 +200,7 @@ public interface EclipseASTVisitor {
}
public void visitType(EclipseNode node, TypeDeclaration type) {
- print("<TYPE %s%s>", str(type.name), isGenerated(type) ? " (GENERATED)" : "");
+ print("<TYPE %s%s%s>", str(type.name), isGenerated(type) ? " (GENERATED)" : "", position(node));
indent++;
if (printContent) {
print("%s", type);
@@ -207,7 +209,7 @@ public interface EclipseASTVisitor {
}
public void visitAnnotationOnType(TypeDeclaration type, EclipseNode node, Annotation annotation) {
- forcePrint("<ANNOTATION%s: %s />", isGenerated(annotation) ? " (GENERATED)" : "", annotation);
+ forcePrint("<ANNOTATION%s: %s%s />", isGenerated(annotation) ? " (GENERATED)" : "", annotation, position(node));
}
public void endVisitType(EclipseNode node, TypeDeclaration type) {
@@ -219,10 +221,10 @@ public interface EclipseASTVisitor {
public void visitInitializer(EclipseNode node, Initializer initializer) {
Block block = initializer.block;
boolean s = (block != null && block.statements != null);
- print("<%s INITIALIZER: %s%s>",
+ print("<%s INITIALIZER: %s%s%s>",
(initializer.modifiers & Modifier.STATIC) != 0 ? "static" : "instance",
s ? "filled" : "blank",
- isGenerated(initializer) ? " (GENERATED)" : "");
+ isGenerated(initializer) ? " (GENERATED)" : "", position(node));
indent++;
if (printContent) {
if (initializer.block != null) print("%s", initializer.block);
@@ -237,8 +239,8 @@ public interface EclipseASTVisitor {
}
public void visitField(EclipseNode node, FieldDeclaration field) {
- print("<FIELD%s %s %s = %s>", isGenerated(field) ? " (GENERATED)" : "",
- str(field.type), str(field.name), field.initialization);
+ print("<FIELD%s %s %s = %s%s>", isGenerated(field) ? " (GENERATED)" : "",
+ str(field.type), str(field.name), field.initialization, position(node));
indent++;
if (printContent) {
if (field.initialization != null) print("%s", field.initialization);
@@ -247,7 +249,7 @@ public interface EclipseASTVisitor {
}
public void visitAnnotationOnField(FieldDeclaration field, EclipseNode node, Annotation annotation) {
- forcePrint("<ANNOTATION%s: %s />", isGenerated(annotation) ? " (GENERATED)" : "", annotation);
+ forcePrint("<ANNOTATION%s: %s%s />", isGenerated(annotation) ? " (GENERATED)" : "", annotation, position(node));
}
public void endVisitField(EclipseNode node, FieldDeclaration field) {
@@ -258,8 +260,8 @@ public interface EclipseASTVisitor {
public void visitMethod(EclipseNode node, AbstractMethodDeclaration method) {
String type = method instanceof ConstructorDeclaration ? "CONSTRUCTOR" : "METHOD";
- print("<%s %s: %s%s>", type, str(method.selector), method.statements != null ? "filled" : "blank",
- isGenerated(method) ? " (GENERATED)" : "");
+ print("<%s %s: %s%s%s>", type, str(method.selector), method.statements != null ? "filled" : "blank",
+ isGenerated(method) ? " (GENERATED)" : "", position(node));
indent++;
if (printContent) {
if (method.statements != null) print("%s", method);
@@ -268,7 +270,7 @@ public interface EclipseASTVisitor {
}
public void visitAnnotationOnMethod(AbstractMethodDeclaration method, EclipseNode node, Annotation annotation) {
- forcePrint("<ANNOTATION%s: %s />", isGenerated(method) ? " (GENERATED)" : "", annotation);
+ forcePrint("<ANNOTATION%s: %s%s />", isGenerated(method) ? " (GENERATED)" : "", annotation, position(node));
}
public void endVisitMethod(EclipseNode node, AbstractMethodDeclaration method) {
@@ -279,12 +281,12 @@ public interface EclipseASTVisitor {
}
public void visitMethodArgument(EclipseNode node, Argument arg, AbstractMethodDeclaration method) {
- print("<METHODARG%s %s %s = %s>", isGenerated(arg) ? " (GENERATED)" : "", str(arg.type), str(arg.name), arg.initialization);
+ print("<METHODARG%s %s %s = %s%s>", isGenerated(arg) ? " (GENERATED)" : "", str(arg.type), str(arg.name), arg.initialization, position(node));
indent++;
}
public void visitAnnotationOnMethodArgument(Argument arg, AbstractMethodDeclaration method, EclipseNode node, Annotation annotation) {
- print("<ANNOTATION%s: %s />", isGenerated(annotation) ? " (GENERATED)" : "", annotation);
+ print("<ANNOTATION%s: %s%s />", isGenerated(annotation) ? " (GENERATED)" : "", annotation, position(node));
}
public void endVisitMethodArgument(EclipseNode node, Argument arg, AbstractMethodDeclaration method) {
@@ -293,7 +295,7 @@ public interface EclipseASTVisitor {
}
public void visitLocal(EclipseNode node, LocalDeclaration local) {
- print("<LOCAL%s %s %s = %s>", isGenerated(local) ? " (GENERATED)" : "", str(local.type), str(local.name), local.initialization);
+ print("<LOCAL%s %s %s = %s%s>", isGenerated(local) ? " (GENERATED)" : "", str(local.type), str(local.name), local.initialization, position(node));
indent++;
}
@@ -307,7 +309,7 @@ public interface EclipseASTVisitor {
}
public void visitStatement(EclipseNode node, Statement statement) {
- print("<%s%s>", statement.getClass(), isGenerated(statement) ? " (GENERATED)" : "");
+ print("<%s%s%s>", statement.getClass(), isGenerated(statement) ? " (GENERATED)" : "", position(node));
indent++;
print("%s", statement);
}
@@ -316,5 +318,12 @@ public interface EclipseASTVisitor {
indent--;
print("</%s>", statement.getClass());
}
+
+ String position(EclipseNode node) {
+ if (!printPositions) return "";
+ int start = node.get().sourceStart();
+ int end = node.get().sourceEnd();
+ return String.format(" [%d, %d]", start, end);
+ }
}
}
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index b0b88656..74512cc8 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -40,14 +40,14 @@ import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
import lombok.Lombok;
-import lombok.core.AnnotationValues;
-import lombok.core.TransformationsUtil;
import lombok.core.AST.Kind;
+import lombok.core.AnnotationValues;
import lombok.core.AnnotationValues.AnnotationValue;
+import lombok.core.TransformationsUtil;
+import lombok.core.TypeResolver;
import lombok.eclipse.EclipseAST;
import lombok.eclipse.EclipseNode;
import lombok.experimental.Accessors;
-import lombok.core.TypeResolver;
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
@@ -62,7 +62,6 @@ import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer;
import org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference;
import org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference;
import org.eclipse.jdt.internal.compiler.ast.CastExpression;
-import org.eclipse.jdt.internal.compiler.ast.Clinit;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
import org.eclipse.jdt.internal.compiler.ast.EqualExpression;
@@ -1215,24 +1214,11 @@ public class EclipseHandlerUtil {
}
}
}
- int insertionPoint;
- for (insertionPoint = 0; insertionPoint < parent.methods.length; insertionPoint++) {
- AbstractMethodDeclaration current = parent.methods[insertionPoint];
- if (current instanceof Clinit) continue;
- if (method instanceof ConstructorDeclaration) {
- if (current instanceof ConstructorDeclaration) continue;
- break;
- }
- if (isGenerated(current)) continue;
- break;
- }
+ //We insert the method in the last position of the methods registered to the type
+ //When changing this behavior, this may trigger issue #155 and #377
AbstractMethodDeclaration[] newArray = new AbstractMethodDeclaration[parent.methods.length + 1];
- System.arraycopy(parent.methods, 0, newArray, 0, insertionPoint);
- if (insertionPoint <= parent.methods.length) {
- System.arraycopy(parent.methods, insertionPoint, newArray, insertionPoint + 1, parent.methods.length - insertionPoint);
- }
-
- newArray[insertionPoint] = method;
+ System.arraycopy(parent.methods, 0, newArray, 0, parent.methods.length);
+ newArray[parent.methods.length] = method;
parent.methods = newArray;
}
diff --git a/src/core/lombok/eclipse/handlers/HandlePrintAST.java b/src/core/lombok/eclipse/handlers/HandlePrintAST.java
index ec7b472a..a9678f0c 100644
--- a/src/core/lombok/eclipse/handlers/HandlePrintAST.java
+++ b/src/core/lombok/eclipse/handlers/HandlePrintAST.java
@@ -51,6 +51,6 @@ public class HandlePrintAST extends EclipseAnnotationHandler<PrintAST> {
Lombok.sneakyThrow(e);
}
- annotationNode.up().traverse(new EclipseASTVisitor.Printer(annotation.getInstance().printContent(), stream));
+ annotationNode.up().traverse(new EclipseASTVisitor.Printer(annotation.getInstance().printContent(), stream, annotation.getInstance().printPositions()));
}
}