aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/eclipse/handlers
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-07-01 03:36:52 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-07-01 03:36:52 +0200
commit43992ff596cd3beb2b6b3f4cfaa686671f06fc2a (patch)
tree4128617005eca9f5ec235a2236702fdd83067f6c /src/lombok/eclipse/handlers
parent23ba6c2628f893678924d66382f962557514f66b (diff)
downloadlombok-43992ff596cd3beb2b6b3f4cfaa686671f06fc2a.tar.gz
lombok-43992ff596cd3beb2b6b3f4cfaa686671f06fc2a.tar.bz2
lombok-43992ff596cd3beb2b6b3f4cfaa686671f06fc2a.zip
Pretty big fix for reparse() - now uses rebuild(), which also received a pretty big fix in making the loop detection algorithm far more robust. Still not sure what was the problem, but the robustificationization helped.
Diffstat (limited to 'src/lombok/eclipse/handlers')
-rw-r--r--src/lombok/eclipse/handlers/HandleData.java12
-rw-r--r--src/lombok/eclipse/handlers/HandleSetter.java3
-rw-r--r--src/lombok/eclipse/handlers/PKG.java58
3 files changed, 55 insertions, 18 deletions
diff --git a/src/lombok/eclipse/handlers/HandleData.java b/src/lombok/eclipse/handlers/HandleData.java
index c17757c9..84db0df1 100644
--- a/src/lombok/eclipse/handlers/HandleData.java
+++ b/src/lombok/eclipse/handlers/HandleData.java
@@ -19,7 +19,7 @@ import lombok.core.AST.Kind;
import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseAnnotationHandler;
import lombok.eclipse.EclipseAST.Node;
-import lombok.eclipse.handlers.PKG.MethodExistsResult;
+import lombok.eclipse.handlers.PKG.MemberExistsResult;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.AllocationExpression;
@@ -98,31 +98,31 @@ public class HandleData implements EclipseAnnotationHandler<Data> {
new HandleSetter().generateSetterForField(child, annotationNode.get());
}
- if ( methodExists("toString", typeNode) == MethodExistsResult.NOT_EXISTS ) {
+ if ( methodExists("toString", typeNode) == MemberExistsResult.NOT_EXISTS ) {
MethodDeclaration toString = createToString(typeNode, nodesForConstructorAndToString, ast);
injectMethod(typeNode, toString);
}
- if ( constructorExists(typeNode) == MethodExistsResult.NOT_EXISTS ) {
+ if ( constructorExists(typeNode) == MemberExistsResult.NOT_EXISTS ) {
ConstructorDeclaration constructor = createConstructor(
ann.staticConstructor().length() == 0, typeNode, nodesForConstructorAndToString, ast);
injectMethod(typeNode, constructor);
}
if ( ann.staticConstructor().length() > 0 ) {
- if ( methodExists("of", typeNode) == MethodExistsResult.NOT_EXISTS ) {
+ if ( methodExists("of", typeNode) == MemberExistsResult.NOT_EXISTS ) {
MethodDeclaration staticConstructor = createStaticConstructor(
ann.staticConstructor(), typeNode, nodesForConstructorAndToString, ast);
injectMethod(typeNode, staticConstructor);
}
}
- if ( methodExists("equals", typeNode) == MethodExistsResult.NOT_EXISTS ) {
+ if ( methodExists("equals", typeNode) == MemberExistsResult.NOT_EXISTS ) {
MethodDeclaration equals = createEquals(typeNode, nodesForEquality, ast);
injectMethod(typeNode, equals);
}
- if ( methodExists("hashCode", typeNode) == MethodExistsResult.NOT_EXISTS ) {
+ if ( methodExists("hashCode", typeNode) == MemberExistsResult.NOT_EXISTS ) {
MethodDeclaration hashCode = createHashCode(typeNode, nodesForEquality, ast);
injectMethod(typeNode, hashCode);
}
diff --git a/src/lombok/eclipse/handlers/HandleSetter.java b/src/lombok/eclipse/handlers/HandleSetter.java
index 28332bdd..57dabc03 100644
--- a/src/lombok/eclipse/handlers/HandleSetter.java
+++ b/src/lombok/eclipse/handlers/HandleSetter.java
@@ -103,9 +103,8 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> {
method.typeParameters = null;
method.scope = parent.scope == null ? null : new MethodScope(parent.scope, method, false);
method.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG;
- FieldReference thisX = new FieldReference(("this." + new String(field.name)).toCharArray(), pos);
+ FieldReference thisX = new FieldReference(field.name, pos);
thisX.receiver = new ThisReference(ast.sourceStart, ast.sourceEnd);
- thisX.token = field.name;
Assignment assignment = new Assignment(thisX, new SingleNameReference(field.name, pos), (int)pos);
method.bodyStart = method.declarationSourceStart = method.sourceStart = ast.sourceStart;
method.bodyEnd = method.declarationSourceEnd = method.sourceEnd = ast.sourceEnd;
diff --git a/src/lombok/eclipse/handlers/PKG.java b/src/lombok/eclipse/handlers/PKG.java
index e9d12b62..13492b28 100644
--- a/src/lombok/eclipse/handlers/PKG.java
+++ b/src/lombok/eclipse/handlers/PKG.java
@@ -9,6 +9,7 @@ import lombok.eclipse.EclipseAST;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
class PKG {
@@ -41,11 +42,32 @@ class PKG {
return string.contentEquals(sb);
}
- enum MethodExistsResult {
+ enum MemberExistsResult {
NOT_EXISTS, EXISTS_BY_USER, EXISTS_BY_LOMBOK;
}
- static MethodExistsResult methodExists(String methodName, EclipseAST.Node node) {
+ static MemberExistsResult fieldExists(String fieldName, EclipseAST.Node node) {
+ while ( node != null && !(node.get() instanceof TypeDeclaration) ) {
+ node = node.up();
+ }
+
+ if ( node != null && node.get() instanceof TypeDeclaration ) {
+ TypeDeclaration typeDecl = (TypeDeclaration)node.get();
+ if ( typeDecl.fields != null ) for ( FieldDeclaration def : typeDecl.fields ) {
+ char[] fName = def.name;
+ if ( fName == null ) continue;
+ if ( fieldName.equals(new String(fName)) ) {
+ EclipseAST.Node existing = node.getNodeFor(def);
+ if ( existing == null || !existing.isHandled() ) return MemberExistsResult.EXISTS_BY_USER;
+ return MemberExistsResult.EXISTS_BY_LOMBOK;
+ }
+ }
+ }
+
+ return MemberExistsResult.NOT_EXISTS;
+ }
+
+ static MemberExistsResult methodExists(String methodName, EclipseAST.Node node) {
while ( node != null && !(node.get() instanceof TypeDeclaration) ) {
node = node.up();
}
@@ -53,20 +75,20 @@ class PKG {
if ( node != null && node.get() instanceof TypeDeclaration ) {
TypeDeclaration typeDecl = (TypeDeclaration)node.get();
if ( typeDecl.methods != null ) for ( AbstractMethodDeclaration def : typeDecl.methods ) {
- char[] mName = ((AbstractMethodDeclaration)def).selector;
+ char[] mName = def.selector;
if ( mName == null ) continue;
if ( methodName.equals(new String(mName)) ) {
EclipseAST.Node existing = node.getNodeFor(def);
- if ( existing == null || !existing.isHandled() ) return MethodExistsResult.EXISTS_BY_USER;
- return MethodExistsResult.EXISTS_BY_LOMBOK;
+ if ( existing == null || !existing.isHandled() ) return MemberExistsResult.EXISTS_BY_USER;
+ return MemberExistsResult.EXISTS_BY_LOMBOK;
}
}
}
- return MethodExistsResult.NOT_EXISTS;
+ return MemberExistsResult.NOT_EXISTS;
}
- static MethodExistsResult constructorExists(EclipseAST.Node node) {
+ static MemberExistsResult constructorExists(EclipseAST.Node node) {
while ( node != null && !(node.get() instanceof TypeDeclaration) ) {
node = node.up();
}
@@ -77,13 +99,13 @@ class PKG {
if ( def instanceof ConstructorDeclaration ) {
if ( (def.bits & ASTNode.IsDefaultConstructor) != 0 ) continue;
EclipseAST.Node existing = node.getNodeFor(def);
- if ( existing == null || !existing.isHandled() ) return MethodExistsResult.EXISTS_BY_USER;
- return MethodExistsResult.EXISTS_BY_LOMBOK;
+ if ( existing == null || !existing.isHandled() ) return MemberExistsResult.EXISTS_BY_USER;
+ return MemberExistsResult.EXISTS_BY_LOMBOK;
}
}
}
- return MethodExistsResult.NOT_EXISTS;
+ return MemberExistsResult.NOT_EXISTS;
}
static EclipseAST.Node getExistingLombokConstructor(EclipseAST.Node node) {
@@ -123,6 +145,22 @@ class PKG {
return null;
}
+ static void injectField(EclipseAST.Node type, FieldDeclaration field) {
+ TypeDeclaration parent = (TypeDeclaration) type.get();
+
+ if ( parent.fields == null ) {
+ parent.fields = new FieldDeclaration[1];
+ parent.fields[0] = field;
+ } else {
+ FieldDeclaration[] newArray = new FieldDeclaration[parent.fields.length + 1];
+ System.arraycopy(parent.fields, 0, newArray, 0, parent.fields.length);
+ newArray[parent.fields.length] = field;
+ parent.fields = newArray;
+ }
+
+ type.add(field, Kind.FIELD).recursiveSetHandled();
+ }
+
static void injectMethod(EclipseAST.Node type, AbstractMethodDeclaration method) {
TypeDeclaration parent = (TypeDeclaration) type.get();