aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/eclipse/EclipseAST.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-06-20 23:46:17 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-06-21 00:10:58 +0200
commit255bd5907176cb5d2c4fb1cf6a9b48b14af0b4ba (patch)
tree347c4b1cf5b34b3975cc00e26a42c75ee1295b76 /src/lombok/eclipse/EclipseAST.java
parent2e8e43a12e21151ff470a2729373b4af4980d113 (diff)
downloadlombok-255bd5907176cb5d2c4fb1cf6a9b48b14af0b4ba.tar.gz
lombok-255bd5907176cb5d2c4fb1cf6a9b48b14af0b4ba.tar.bz2
lombok-255bd5907176cb5d2c4fb1cf6a9b48b14af0b4ba.zip
Due to a java bug, constants in enums don't work, so instead the default access level for @Getter and @Setter have now just been hardcoded in GetterHandler and SetterHandler.
Added ability to look up the Node object for any given AST object on Node itself, as you don't usually have the AST object. Added toString() method generating to @Data, and this required some fancy footwork in finding if we've already generated methods, and editing a generated method to fill in binding and type resolutions. HandleGetter and HandleSetter have been updated to use these features. Exceptions caused by lombok handlers show up in the eclipse error log, but now, if they are related to a CompilationUnit, also as a problem (error) on the CUD - those error log entries are easy to miss! Our ASTs can now be appended to. When you generate a new AST node, you should add it to the AST, obviously. Getter/Setter have been updated to use this.
Diffstat (limited to 'src/lombok/eclipse/EclipseAST.java')
-rw-r--r--src/lombok/eclipse/EclipseAST.java70
1 files changed, 51 insertions, 19 deletions
diff --git a/src/lombok/eclipse/EclipseAST.java b/src/lombok/eclipse/EclipseAST.java
index 6c4ce211..850fb8dc 100644
--- a/src/lombok/eclipse/EclipseAST.java
+++ b/src/lombok/eclipse/EclipseAST.java
@@ -70,21 +70,19 @@ public class EclipseAST extends AST<ASTNode> {
private class ParseProblem {
final boolean isWarning;
final String message;
- final Node node;
final int sourceStart;
final int sourceEnd;
- public ParseProblem(boolean isWarning, String message, Node node, int sourceStart, int sourceEnd) {
+ public ParseProblem(boolean isWarning, String message, int sourceStart, int sourceEnd) {
this.isWarning = isWarning;
this.message = message;
- this.node = node;
this.sourceStart = sourceStart;
this.sourceEnd = sourceEnd;
}
void addToCompilationResult() {
- addProblemToCompilationResult(getFileName(), (CompilationUnitDeclaration) top().get(),
- isWarning, message, node.get(), sourceStart, sourceEnd);
+ addProblemToCompilationResult((CompilationUnitDeclaration) top().get(),
+ isWarning, message, sourceStart, sourceEnd);
}
}
@@ -103,9 +101,11 @@ public class EclipseAST extends AST<ASTNode> {
propagateProblems();
}
- static void addProblemToCompilationResult(String fileName, CompilationUnitDeclaration ast,
- boolean isWarning, String message, ASTNode node, int sourceStart, int sourceEnd) {
- char[] fileNameArray = fileName.toCharArray();
+ static void addProblemToCompilationResult(CompilationUnitDeclaration ast,
+ boolean isWarning, String message, int sourceStart, int sourceEnd) {
+ if ( ast.compilationResult == null ) return;
+ char[] fileNameArray = ast.getFileName();
+ if ( fileNameArray == null ) fileNameArray = "(unknown).java".toCharArray();
int lineNumber = 0;
int columnNumber = 1;
CompilationResult result = ast.compilationResult;
@@ -218,7 +218,7 @@ public class EclipseAST extends AST<ASTNode> {
}
public void addError(String message, int sourceStart, int sourceEnd) {
- addProblem(new ParseProblem(false, message, this, sourceStart, sourceEnd));
+ addProblem(new ParseProblem(false, message, sourceStart, sourceEnd));
}
@Override public void addWarning(String message) {
@@ -226,7 +226,7 @@ public class EclipseAST extends AST<ASTNode> {
}
public void addWarning(String message, int sourceStart, int sourceEnd) {
- addProblem(new ParseProblem(true, message, this, sourceStart, sourceEnd));
+ addProblem(new ParseProblem(true, message, sourceStart, sourceEnd));
}
/** {@inheritDoc} */
@@ -244,6 +244,11 @@ public class EclipseAST extends AST<ASTNode> {
}
/** {@inheritDoc} */
+ @Override public Node getNodeFor(ASTNode obj) {
+ return (Node) super.getNodeFor(obj);
+ }
+
+ /** {@inheritDoc} */
public Node directUp() {
return (Node) super.directUp();
}
@@ -300,6 +305,31 @@ public class EclipseAST extends AST<ASTNode> {
return (unit.bits & ASTNode.HasAllMethodBodies) > 0;
}
+ @Override protected Node buildTree(ASTNode node, Kind kind) {
+ switch ( kind ) {
+ case COMPILATION_UNIT:
+ return buildCompilationUnit((CompilationUnitDeclaration) node);
+ case TYPE:
+ return buildType((TypeDeclaration) node);
+ case FIELD:
+ return buildField((FieldDeclaration) node);
+ case INITIALIZER:
+ return buildInitializer((Initializer) node);
+ case METHOD:
+ return buildMethod((AbstractMethodDeclaration) node);
+ case ARGUMENT:
+ return buildLocal((Argument) node, kind);
+ case LOCAL:
+ return buildLocal((LocalDeclaration) node, kind);
+ case STATEMENT:
+ return buildStatement((Statement) node);
+ case ANNOTATION:
+ return buildAnnotation((Annotation) node);
+ default:
+ throw new AssertionError("Did not expect to arrive here: " + kind);
+ }
+ }
+
private Node buildCompilationUnit(CompilationUnitDeclaration top) {
Collection<Node> children = buildTypes(top.types);
return putInMap(new Node(top, children, Kind.COMPILATION_UNIT));
@@ -373,30 +403,32 @@ public class EclipseAST extends AST<ASTNode> {
if ( children == null ) return Collections.emptyList();
List<Node> childNodes = new ArrayList<Node>();
for ( LocalDeclaration local : children ) {
- addIfNotNull(childNodes, buildLocal(local));
+ addIfNotNull(childNodes, buildLocal(local, Kind.ARGUMENT));
}
return childNodes;
}
- private Node buildLocal(LocalDeclaration local) {
+ private Node buildLocal(LocalDeclaration local, Kind kind) {
if ( alreadyHandled(local) ) return null;
List<Node> childNodes = new ArrayList<Node>();
addIfNotNull(childNodes, buildStatement(local.initialization));
childNodes.addAll(buildAnnotations(local.annotations));
- return putInMap(new Node(local, childNodes, Kind.LOCAL));
+ return putInMap(new Node(local, childNodes, kind));
}
private Collection<Node> buildAnnotations(Annotation[] annotations) {
if ( annotations == null ) return Collections.emptyList();
List<Node> elements = new ArrayList<Node>();
- for ( Annotation an : annotations ) {
- if ( an == null ) continue;
- if ( alreadyHandled(an) ) continue;
- elements.add(putInMap(new Node(an, null, Kind.ANNOTATION)));
- }
+ for ( Annotation an : annotations ) addIfNotNull(elements, buildAnnotation(an));
return elements;
}
+ private Node buildAnnotation(Annotation annotation) {
+ if ( annotation == null ) return null;
+ if ( alreadyHandled(annotation) ) return null;
+ return putInMap(new Node(annotation, null, Kind.ANNOTATION));
+ }
+
private Collection<Node> buildStatements(Statement[] children) {
if ( children == null ) return Collections.emptyList();
List<Node> childNodes = new ArrayList<Node>();
@@ -409,7 +441,7 @@ public class EclipseAST extends AST<ASTNode> {
if ( child == null || alreadyHandled(child) ) return null;
if ( child instanceof TypeDeclaration ) return buildType((TypeDeclaration)child);
- if ( child instanceof LocalDeclaration ) return buildLocal((LocalDeclaration)child);
+ if ( child instanceof LocalDeclaration ) return buildLocal((LocalDeclaration)child, Kind.LOCAL);
//We drill down because LocalDeclarations and TypeDeclarations can occur anywhere, even in, say,
//an if block, or even the expression on an assert statement!