aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/eclipse/handlers
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-10-16 09:32:36 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-10-16 09:32:36 +0200
commitb5c8b725655d2ad8a715cfb1fbbdf25dbdcd4ceb (patch)
tree571d13cd7028a6b7d1ebfe84180a4328a20c42d7 /src/lombok/eclipse/handlers
parent8629a651a66aa5fba9e0ada7df00803528b0e34f (diff)
downloadlombok-b5c8b725655d2ad8a715cfb1fbbdf25dbdcd4ceb.tar.gz
lombok-b5c8b725655d2ad8a715cfb1fbbdf25dbdcd4ceb.tar.bz2
lombok-b5c8b725655d2ad8a715cfb1fbbdf25dbdcd4ceb.zip
Fixed issue #24 by refactoring the AST.Node class - taken it out, and in the process fixed a lot of type annoyance by adding more generics.
Also changed coding style from for/while/if/switch/catch/do ( expr ) {} to for (expr) {}, hence the changes _everywhere_.
Diffstat (limited to 'src/lombok/eclipse/handlers')
-rw-r--r--src/lombok/eclipse/handlers/HandleCleanup.java62
-rw-r--r--src/lombok/eclipse/handlers/HandleData.java43
-rw-r--r--src/lombok/eclipse/handlers/HandleEqualsAndHashCode.java141
-rw-r--r--src/lombok/eclipse/handlers/HandleGetter.java29
-rw-r--r--src/lombok/eclipse/handlers/HandlePrintAST.java10
-rw-r--r--src/lombok/eclipse/handlers/HandleSetter.java28
-rw-r--r--src/lombok/eclipse/handlers/HandleSneakyThrows.java34
-rw-r--r--src/lombok/eclipse/handlers/HandleSynchronized.java20
-rw-r--r--src/lombok/eclipse/handlers/HandleToString.java96
-rw-r--r--src/lombok/eclipse/handlers/PKG.java139
10 files changed, 302 insertions, 300 deletions
diff --git a/src/lombok/eclipse/handlers/HandleCleanup.java b/src/lombok/eclipse/handlers/HandleCleanup.java
index 07c921ab..9cb23067 100644
--- a/src/lombok/eclipse/handlers/HandleCleanup.java
+++ b/src/lombok/eclipse/handlers/HandleCleanup.java
@@ -28,7 +28,7 @@ import lombok.core.AnnotationValues;
import lombok.core.AST.Kind;
import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseAnnotationHandler;
-import lombok.eclipse.EclipseAST.Node;
+import lombok.eclipse.EclipseNode;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
@@ -51,37 +51,37 @@ import org.mangosdk.spi.ProviderFor;
*/
@ProviderFor(EclipseAnnotationHandler.class)
public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> {
- public boolean handle(AnnotationValues<Cleanup> annotation, Annotation ast, Node annotationNode) {
+ public boolean handle(AnnotationValues<Cleanup> annotation, Annotation ast, EclipseNode annotationNode) {
String cleanupName = annotation.getInstance().value();
- if ( cleanupName.length() == 0 ) {
+ if (cleanupName.length() == 0) {
annotationNode.addError("cleanupName cannot be the empty string.");
return true;
}
- if ( annotationNode.up().getKind() != Kind.LOCAL ) {
+ if (annotationNode.up().getKind() != Kind.LOCAL) {
annotationNode.addError("@Cleanup is legal only on local variable declarations.");
return true;
}
LocalDeclaration decl = (LocalDeclaration)annotationNode.up().get();
- if ( decl.initialization == null ) {
+ if (decl.initialization == null) {
annotationNode.addError("@Cleanup variable declarations need to be initialized.");
return true;
}
- Node ancestor = annotationNode.up().directUp();
+ EclipseNode ancestor = annotationNode.up().directUp();
ASTNode blockNode = ancestor.get();
final boolean isSwitch;
final Statement[] statements;
- if ( blockNode instanceof AbstractMethodDeclaration ) {
+ if (blockNode instanceof AbstractMethodDeclaration) {
isSwitch = false;
statements = ((AbstractMethodDeclaration)blockNode).statements;
- } else if ( blockNode instanceof Block ) {
+ } else if (blockNode instanceof Block) {
isSwitch = false;
statements = ((Block)blockNode).statements;
- } else if ( blockNode instanceof SwitchStatement ) {
+ } else if (blockNode instanceof SwitchStatement) {
isSwitch = true;
statements = ((SwitchStatement)blockNode).statements;
} else {
@@ -89,17 +89,17 @@ public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> {
return true;
}
- if ( statements == null ) {
+ if (statements == null) {
annotationNode.addError("LOMBOK BUG: Parent block does not contain any statements.");
return true;
}
int start = 0;
- for ( ; start < statements.length ; start++ ) {
- if ( statements[start] == decl ) break;
+ for (; start < statements.length ; start++) {
+ if (statements[start] == decl) break;
}
- if ( start == statements.length ) {
+ if (start == statements.length) {
annotationNode.addError("LOMBOK BUG: Can't find this local variable declaration inside its parent.");
return true;
}
@@ -107,10 +107,10 @@ public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> {
start++; //We start with try{} *AFTER* the var declaration.
int end;
- if ( isSwitch ) {
+ if (isSwitch) {
end = start + 1;
- for ( ; end < statements.length ; end++ ) {
- if ( statements[end] instanceof CaseStatement ) {
+ for (; end < statements.length ; end++) {
+ if (statements[end] instanceof CaseStatement) {
break;
}
}
@@ -149,8 +149,8 @@ public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> {
Eclipse.setGeneratedBy(receiver, ast);
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("value") ) {
+ if (ast.memberValuePairs() != null) for (MemberValuePair pair : ast.memberValuePairs()) {
+ if (pair.name != null && new String(pair.name).equals("value")) {
nameSourcePosition = (long)pair.value.sourceStart << 32 | pair.value.sourceEnd;
break;
}
@@ -165,11 +165,11 @@ public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> {
tryStatement.catchArguments = null;
tryStatement.catchBlocks = null;
- if ( blockNode instanceof AbstractMethodDeclaration ) {
+ if (blockNode instanceof AbstractMethodDeclaration) {
((AbstractMethodDeclaration)blockNode).statements = newStatements;
- } else if ( blockNode instanceof Block ) {
+ } else if (blockNode instanceof Block) {
((Block)blockNode).statements = newStatements;
- } else if ( blockNode instanceof SwitchStatement ) {
+ } else if (blockNode instanceof SwitchStatement) {
((SwitchStatement)blockNode).statements = newStatements;
}
@@ -178,21 +178,21 @@ public class HandleCleanup implements EclipseAnnotationHandler<Cleanup> {
return true;
}
- private void doAssignmentCheck(Node node, Statement[] tryBlock, char[] varName) {
- for ( Statement statement : tryBlock ) doAssignmentCheck0(node, statement, varName);
+ private void doAssignmentCheck(EclipseNode node, Statement[] tryBlock, char[] varName) {
+ for (Statement statement : tryBlock) doAssignmentCheck0(node, statement, varName);
}
- private void doAssignmentCheck0(Node node, Statement statement, char[] varName) {
- if ( statement instanceof Assignment )
+ private void doAssignmentCheck0(EclipseNode node, Statement statement, char[] varName) {
+ if (statement instanceof Assignment)
doAssignmentCheck0(node, ((Assignment)statement).expression, varName);
- else if ( statement instanceof LocalDeclaration )
+ else if (statement instanceof LocalDeclaration)
doAssignmentCheck0(node, ((LocalDeclaration)statement).initialization, varName);
- else if ( statement instanceof CastExpression )
+ else if (statement instanceof CastExpression)
doAssignmentCheck0(node, ((CastExpression)statement).expression, varName);
- else if ( statement instanceof SingleNameReference ) {
- if ( Arrays.equals(((SingleNameReference)statement).token, varName) ) {
- Node problemNode = node.getNodeFor(statement);
- if ( problemNode != null ) problemNode.addWarning(
+ else if (statement instanceof SingleNameReference) {
+ if (Arrays.equals(((SingleNameReference)statement).token, varName)) {
+ EclipseNode problemNode = node.getNodeFor(statement);
+ if (problemNode != null) problemNode.addWarning(
"You're assigning an auto-cleanup variable to something else. This is a bad idea.");
}
}
diff --git a/src/lombok/eclipse/handlers/HandleData.java b/src/lombok/eclipse/handlers/HandleData.java
index 2761c20b..d760e1c6 100644
--- a/src/lombok/eclipse/handlers/HandleData.java
+++ b/src/lombok/eclipse/handlers/HandleData.java
@@ -36,7 +36,7 @@ import lombok.core.TransformationsUtil;
import lombok.core.AST.Kind;
import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseAnnotationHandler;
-import lombok.eclipse.EclipseAST.Node;
+import lombok.eclipse.EclipseNode;
import lombok.eclipse.handlers.PKG.MemberExistsResult;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
@@ -68,32 +68,32 @@ import org.mangosdk.spi.ProviderFor;
*/
@ProviderFor(EclipseAnnotationHandler.class)
public class HandleData implements EclipseAnnotationHandler<Data> {
- public boolean handle(AnnotationValues<Data> annotation, Annotation ast, Node annotationNode) {
+ public boolean handle(AnnotationValues<Data> annotation, Annotation ast, EclipseNode annotationNode) {
Data ann = annotation.getInstance();
- Node typeNode = annotationNode.up();
+ EclipseNode typeNode = annotationNode.up();
TypeDeclaration typeDecl = null;
- if ( typeNode.get() instanceof TypeDeclaration ) typeDecl = (TypeDeclaration) typeNode.get();
+ if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get();
int modifiers = typeDecl == null ? 0 : typeDecl.modifiers;
boolean notAClass = (modifiers &
(ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation | ClassFileConstants.AccEnum)) != 0;
- if ( typeDecl == null || notAClass ) {
+ if (typeDecl == null || notAClass) {
annotationNode.addError("@Data is only supported on a class.");
return false;
}
- List<Node> nodesForConstructor = new ArrayList<Node>();
- for ( Node child : typeNode.down() ) {
- if ( child.getKind() != Kind.FIELD ) continue;
+ List<EclipseNode> nodesForConstructor = new ArrayList<EclipseNode>();
+ for (EclipseNode child : typeNode.down()) {
+ if (child.getKind() != Kind.FIELD) continue;
FieldDeclaration fieldDecl = (FieldDeclaration) child.get();
//Skip static fields.
- if ( (fieldDecl.modifiers & ClassFileConstants.AccStatic) != 0 ) continue;
+ if ((fieldDecl.modifiers & ClassFileConstants.AccStatic) != 0) continue;
boolean isFinal = (fieldDecl.modifiers & ClassFileConstants.AccFinal) != 0;
boolean isNonNull = findAnnotations(fieldDecl, TransformationsUtil.NON_NULL_PATTERN).length != 0;
- if ( (isFinal || isNonNull) && fieldDecl.initialization == null ) nodesForConstructor.add(child);
+ if ((isFinal || isNonNull) && fieldDecl.initialization == null) nodesForConstructor.add(child);
new HandleGetter().generateGetterForField(child, annotationNode.get());
- if ( !isFinal ) new HandleSetter().generateSetterForField(child, annotationNode.get());
+ if (!isFinal) new HandleSetter().generateSetterForField(child, annotationNode.get());
}
new HandleToString().generateToStringForType(typeNode, annotationNode);
@@ -102,17 +102,17 @@ public class HandleData implements EclipseAnnotationHandler<Data> {
//Careful: Generate the public static constructor (if there is one) LAST, so that any attempt to
//'find callers' on the annotation node will find callers of the constructor, which is by far the
//most useful of the many methods built by @Data. This trick won't work for the non-static constructor,
- //for whatever reason, though you can find callers of that one by focussing on the class name itself
+ //for whatever reason, though you can find callers of that one by focusing on the class name itself
//and hitting 'find callers'.
- if ( constructorExists(typeNode) == MemberExistsResult.NOT_EXISTS ) {
+ if (constructorExists(typeNode) == MemberExistsResult.NOT_EXISTS) {
ConstructorDeclaration constructor = createConstructor(
ann.staticConstructor().length() == 0, typeNode, nodesForConstructor, ast);
injectMethod(typeNode, constructor);
}
- if ( ann.staticConstructor().length() > 0 ) {
- if ( methodExists("of", typeNode) == MemberExistsResult.NOT_EXISTS ) {
+ if (ann.staticConstructor().length() > 0) {
+ if (methodExists("of", typeNode) == MemberExistsResult.NOT_EXISTS) {
MethodDeclaration staticConstructor = createStaticConstructor(
ann.staticConstructor(), typeNode, nodesForConstructor, ast);
injectMethod(typeNode, staticConstructor);
@@ -122,7 +122,8 @@ public class HandleData implements EclipseAnnotationHandler<Data> {
return false;
}
- private ConstructorDeclaration createConstructor(boolean isPublic, Node type, Collection<Node> fields, ASTNode source) {
+ private ConstructorDeclaration createConstructor(boolean isPublic,
+ EclipseNode type, Collection<EclipseNode> fields, ASTNode source) {
long p = (long)source.sourceStart << 32 | source.sourceEnd;
ConstructorDeclaration constructor = new ConstructorDeclaration(
@@ -145,7 +146,7 @@ public class HandleData implements EclipseAnnotationHandler<Data> {
List<Statement> assigns = new ArrayList<Statement>();
List<Statement> nullChecks = new ArrayList<Statement>();
- for ( Node fieldNode : fields ) {
+ for (EclipseNode fieldNode : fields) {
FieldDeclaration field = (FieldDeclaration) fieldNode.get();
FieldReference thisX = new FieldReference(("this." + new String(field.name)).toCharArray(), p);
Eclipse.setGeneratedBy(thisX, source);
@@ -178,7 +179,7 @@ public class HandleData implements EclipseAnnotationHandler<Data> {
return constructor;
}
- private MethodDeclaration createStaticConstructor(String name, Node type, Collection<Node> fields, ASTNode source) {
+ private MethodDeclaration createStaticConstructor(String name, EclipseNode type, Collection<EclipseNode> fields, ASTNode source) {
int pS = source.sourceStart, pE = source.sourceEnd;
long p = (long)pS << 32 | pE;
@@ -188,10 +189,10 @@ public class HandleData implements EclipseAnnotationHandler<Data> {
constructor.modifiers = PKG.toModifier(AccessLevel.PUBLIC) | Modifier.STATIC;
TypeDeclaration typeDecl = (TypeDeclaration) type.get();
- if ( typeDecl.typeParameters != null && typeDecl.typeParameters.length > 0 ) {
+ if (typeDecl.typeParameters != null && typeDecl.typeParameters.length > 0) {
TypeReference[] refs = new TypeReference[typeDecl.typeParameters.length];
int idx = 0;
- for ( TypeParameter param : typeDecl.typeParameters ) {
+ for (TypeParameter param : typeDecl.typeParameters) {
TypeReference typeRef = new SingleTypeReference(param.name, (long)param.sourceStart << 32 | param.sourceEnd);
Eclipse.setGeneratedBy(typeRef, source);
refs[idx++] = typeRef;
@@ -214,7 +215,7 @@ public class HandleData implements EclipseAnnotationHandler<Data> {
Eclipse.setGeneratedBy(statement, source);
statement.type = copyType(constructor.returnType, source);
- for ( Node fieldNode : fields ) {
+ for (EclipseNode fieldNode : fields) {
FieldDeclaration field = (FieldDeclaration) fieldNode.get();
long fieldPos = (((long)field.sourceStart) << 32) | field.sourceEnd;
SingleNameReference nameRef = new SingleNameReference(field.name, fieldPos);
diff --git a/src/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
index 209c095c..847ea7d1 100644
--- a/src/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
+++ b/src/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
@@ -81,7 +81,7 @@ import lombok.core.AnnotationValues;
import lombok.core.AST.Kind;
import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseAnnotationHandler;
-import lombok.eclipse.EclipseAST.Node;
+import lombok.eclipse.EclipseNode;
/**
* Handles the <code>EqualsAndHashCode</code> annotation for eclipse.
@@ -91,23 +91,23 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
private static final Set<String> BUILT_IN_TYPES = Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(
"byte", "short", "int", "long", "char", "boolean", "double", "float")));
- private void checkForBogusFieldNames(Node type, AnnotationValues<EqualsAndHashCode> annotation) {
- if ( annotation.isExplicit("exclude") ) {
- for ( int i : createListOfNonExistentFields(Arrays.asList(annotation.getInstance().exclude()), type, true, true) ) {
+ private void checkForBogusFieldNames(EclipseNode type, AnnotationValues<EqualsAndHashCode> annotation) {
+ if (annotation.isExplicit("exclude")) {
+ for (int i : createListOfNonExistentFields(Arrays.asList(annotation.getInstance().exclude()), type, true, true)) {
annotation.setWarning("exclude", "This field does not exist, or would have been excluded anyway.", i);
}
}
- if ( annotation.isExplicit("of") ) {
- for ( int i : createListOfNonExistentFields(Arrays.asList(annotation.getInstance().of()), type, false, false) ) {
+ if (annotation.isExplicit("of")) {
+ for (int i : createListOfNonExistentFields(Arrays.asList(annotation.getInstance().of()), type, false, false)) {
annotation.setWarning("of", "This field does not exist.", i);
}
}
}
- public void generateEqualsAndHashCodeForType(Node typeNode, Node errorNode) {
- for ( Node child : typeNode.down() ) {
- if ( child.getKind() == Kind.ANNOTATION ) {
- if ( Eclipse.annotationTypeMatches(EqualsAndHashCode.class, child) ) {
+ public void generateEqualsAndHashCodeForType(EclipseNode typeNode, EclipseNode errorNode) {
+ for (EclipseNode child : typeNode.down()) {
+ if (child.getKind() == Kind.ANNOTATION) {
+ if (Eclipse.annotationTypeMatches(EqualsAndHashCode.class, child)) {
//The annotation will make it happen, so we can skip it.
return;
}
@@ -117,20 +117,21 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
generateMethods(typeNode, errorNode, null, null, null, false);
}
- @Override public boolean handle(AnnotationValues<EqualsAndHashCode> annotation, Annotation ast, Node annotationNode) {
+ @Override public boolean handle(AnnotationValues<EqualsAndHashCode> annotation,
+ Annotation ast, EclipseNode annotationNode) {
EqualsAndHashCode ann = annotation.getInstance();
List<String> excludes = Arrays.asList(ann.exclude());
List<String> includes = Arrays.asList(ann.of());
- Node typeNode = annotationNode.up();
+ EclipseNode typeNode = annotationNode.up();
checkForBogusFieldNames(typeNode, annotation);
Boolean callSuper = ann.callSuper();
- if ( !annotation.isExplicit("callSuper") ) callSuper = null;
- if ( !annotation.isExplicit("exclude") ) excludes = null;
- if ( !annotation.isExplicit("of") ) includes = null;
+ if (!annotation.isExplicit("callSuper")) callSuper = null;
+ if (!annotation.isExplicit("exclude")) excludes = null;
+ if (!annotation.isExplicit("of")) includes = null;
- if ( excludes != null && includes != null ) {
+ if (excludes != null && includes != null) {
excludes = null;
annotation.setWarning("exclude", "exclude and of are mutually exclusive; the 'exclude' parameter will be ignored.");
}
@@ -138,70 +139,70 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
return generateMethods(typeNode, annotationNode, excludes, includes, callSuper, true);
}
- public boolean generateMethods(Node typeNode, Node errorNode, List<String> excludes, List<String> includes,
+ public boolean generateMethods(EclipseNode typeNode, EclipseNode errorNode, List<String> excludes, List<String> includes,
Boolean callSuper, boolean whineIfExists) {
assert excludes == null || includes == null;
TypeDeclaration typeDecl = null;
- if ( typeNode.get() instanceof TypeDeclaration ) typeDecl = (TypeDeclaration) typeNode.get();
+ if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get();
int modifiers = typeDecl == null ? 0 : typeDecl.modifiers;
boolean notAClass = (modifiers &
(ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation | ClassFileConstants.AccEnum)) != 0;
- if ( typeDecl == null || notAClass ) {
+ if (typeDecl == null || notAClass) {
errorNode.addError("@EqualsAndHashCode is only supported on a class.");
return false;
}
boolean implicitCallSuper = callSuper == null;
- if ( callSuper == null ) {
+ if (callSuper == null) {
try {
callSuper = ((Boolean)EqualsAndHashCode.class.getMethod("callSuper").getDefaultValue()).booleanValue();
- } catch ( Exception ignore ) {}
+ } catch (Exception ignore) {}
}
boolean isDirectDescendantOfObject = true;
- if ( typeDecl.superclass != null ) {
+ if (typeDecl.superclass != null) {
String p = typeDecl.superclass.toString();
isDirectDescendantOfObject = p.equals("Object") || p.equals("java.lang.Object");
}
- if ( isDirectDescendantOfObject && callSuper ) {
+ if (isDirectDescendantOfObject && callSuper) {
errorNode.addError("Generating equals/hashCode with a supercall to java.lang.Object is pointless.");
return true;
}
- if ( !isDirectDescendantOfObject && !callSuper && implicitCallSuper ) {
+ if (!isDirectDescendantOfObject && !callSuper && implicitCallSuper) {
errorNode.addWarning("Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@EqualsAndHashCode(callSuper=false)' to your type.");
}
- List<Node> nodesForEquality = new ArrayList<Node>();
- if ( includes != null ) {
- for ( Node child : typeNode.down() ) {
- if ( child.getKind() != Kind.FIELD ) continue;
+ List<EclipseNode> nodesForEquality = new ArrayList<EclipseNode>();
+ if (includes != null) {
+ for (EclipseNode child : typeNode.down()) {
+ if (child.getKind() != Kind.FIELD) continue;
FieldDeclaration fieldDecl = (FieldDeclaration) child.get();
- if ( includes.contains(new String(fieldDecl.name)) ) nodesForEquality.add(child);
+ if (includes.contains(new String(fieldDecl.name))) nodesForEquality.add(child);
}
} else {
- for ( Node child : typeNode.down() ) {
- if ( child.getKind() != Kind.FIELD ) continue;
+ for (EclipseNode child : typeNode.down()) {
+ if (child.getKind() != Kind.FIELD) continue;
FieldDeclaration fieldDecl = (FieldDeclaration) child.get();
//Skip static fields.
- if ( (fieldDecl.modifiers & ClassFileConstants.AccStatic) != 0 ) continue;
+ if ((fieldDecl.modifiers & ClassFileConstants.AccStatic) != 0) continue;
//Skip transient fields.
- if ( (fieldDecl.modifiers & ClassFileConstants.AccTransient) != 0 ) continue;
+ if ((fieldDecl.modifiers & ClassFileConstants.AccTransient) != 0) continue;
//Skip excluded fields.
- if ( excludes != null && excludes.contains(new String(fieldDecl.name)) ) continue;
+ if (excludes != null && excludes.contains(new String(fieldDecl.name))) continue;
//Skip fields that start with $.
- if ( fieldDecl.name.length > 0 && fieldDecl.name[0] == '$' ) continue;
+ if (fieldDecl.name.length > 0 && fieldDecl.name[0] == '$') continue;
nodesForEquality.add(child);
}
}
- switch ( methodExists("hashCode", typeNode) ) {
+ switch (methodExists("hashCode", typeNode)) {
case NOT_EXISTS:
MethodDeclaration hashCode = createHashCode(typeNode, nodesForEquality, callSuper, errorNode.get());
injectMethod(typeNode, hashCode);
@@ -210,13 +211,13 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
break;
default:
case EXISTS_BY_USER:
- if ( whineIfExists ) {
+ if (whineIfExists) {
errorNode.addWarning("Not generating hashCode(): A method with that name already exists");
}
break;
}
- switch ( methodExists("equals", typeNode) ) {
+ switch (methodExists("equals", typeNode)) {
case NOT_EXISTS:
MethodDeclaration equals = createEquals(typeNode, nodesForEquality, callSuper, errorNode.get());
injectMethod(typeNode, equals);
@@ -225,7 +226,7 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
break;
default:
case EXISTS_BY_USER:
- if ( whineIfExists ) {
+ if (whineIfExists) {
errorNode.addWarning("Not generating equals(Object other): A method with that name already exists");
}
break;
@@ -234,7 +235,7 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
return true;
}
- private MethodDeclaration createHashCode(Node type, Collection<Node> fields, boolean callSuper, ASTNode source) {
+ private MethodDeclaration createHashCode(EclipseNode type, Collection<EclipseNode> fields, boolean callSuper, ASTNode source) {
int pS = source.sourceStart, pE = source.sourceEnd;
long p = (long)pS << 32 | pE;
@@ -263,7 +264,7 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
/* final int PRIME = 31; */ {
/* Without fields, PRIME isn't used, and that would trigger a 'local variable not used' warning. */
- if ( !isEmpty || callSuper ) {
+ if (!isEmpty || callSuper) {
LocalDeclaration primeDecl = new LocalDeclaration(PRIME, pS, pE);
Eclipse.setGeneratedBy(primeDecl, source);
primeDecl.modifiers |= Modifier.FINAL;
@@ -287,7 +288,7 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
statements.add(resultDecl);
}
- if ( callSuper ) {
+ if (callSuper) {
MessageSend callToSuper = new MessageSend();
Eclipse.setGeneratedBy(callToSuper, source);
callToSuper.sourceStart = pS; callToSuper.sourceEnd = pE;
@@ -298,11 +299,11 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
}
int tempCounter = 0;
- for ( Node field : fields ) {
+ for (EclipseNode field : fields) {
FieldDeclaration f = (FieldDeclaration) field.get();
char[] token = f.type.getLastToken();
- if ( f.type.dimensions() == 0 && token != null ) {
- if ( Arrays.equals(TypeConstants.FLOAT, token) ) {
+ if (f.type.dimensions() == 0 && token != null) {
+ if (Arrays.equals(TypeConstants.FLOAT, token)) {
/* Float.floatToIntBits(fieldName) */
MessageSend floatToIntBits = new MessageSend();
floatToIntBits.sourceStart = pS; floatToIntBits.sourceEnd = pE;
@@ -311,7 +312,7 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
floatToIntBits.selector = "floatToIntBits".toCharArray();
floatToIntBits.arguments = new Expression[] { generateFieldReference(f.name, source) };
intoResult.add(floatToIntBits);
- } else if ( Arrays.equals(TypeConstants.DOUBLE, token) ) {
+ } else if (Arrays.equals(TypeConstants.DOUBLE, token)) {
/* longToIntForHashCode(Double.doubleToLongBits(fieldName)) */
MessageSend doubleToLongBits = new MessageSend();
doubleToLongBits.sourceStart = pS; doubleToLongBits.sourceEnd = pE;
@@ -333,7 +334,7 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
SingleNameReference copy2 = new SingleNameReference(tempName, p);
Eclipse.setGeneratedBy(copy2, source);
intoResult.add(longToIntForHashCode(copy1, copy2, source));
- } else if ( Arrays.equals(TypeConstants.BOOLEAN, token) ) {
+ } else if (Arrays.equals(TypeConstants.BOOLEAN, token)) {
/* booleanField ? 1231 : 1237 */
IntLiteral int1231 = new IntLiteral("1231".toCharArray(), pS, pE);
Eclipse.setGeneratedBy(int1231, source);
@@ -343,9 +344,9 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
generateFieldReference(f.name, source), int1231, int1237);
Eclipse.setGeneratedBy(int1231or1237, source);
intoResult.add(int1231or1237);
- } else if ( Arrays.equals(TypeConstants.LONG, token) ) {
+ } else if (Arrays.equals(TypeConstants.LONG, token)) {
intoResult.add(longToIntForHashCode(generateFieldReference(f.name, source), generateFieldReference(f.name, source), source));
- } else if ( BUILT_IN_TYPES.contains(new String(token)) ) {
+ } else if (BUILT_IN_TYPES.contains(new String(token))) {
intoResult.add(generateFieldReference(f.name, source));
} else /* objects */ {
/* this.fieldName == null ? 0 : this.fieldName.hashCode() */
@@ -366,13 +367,13 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
Eclipse.setGeneratedBy(nullOrHashCode, source);
intoResult.add(nullOrHashCode);
}
- } else if ( f.type.dimensions() > 0 && token != null ) {
+ } else if (f.type.dimensions() > 0 && token != null) {
/* Arrays.deepHashCode(array) //just hashCode for simple arrays */
MessageSend arraysHashCodeCall = new MessageSend();
arraysHashCodeCall.sourceStart = pS; arraysHashCodeCall.sourceEnd = pE;
Eclipse.setGeneratedBy(arraysHashCodeCall, source);
arraysHashCodeCall.receiver = generateQualifiedNameRef(source, TypeConstants.JAVA, TypeConstants.UTIL, "Arrays".toCharArray());
- if ( f.type.dimensions() > 1 || !BUILT_IN_TYPES.contains(new String(token)) ) {
+ if (f.type.dimensions() > 1 || !BUILT_IN_TYPES.contains(new String(token))) {
arraysHashCodeCall.selector = "deepHashCode".toCharArray();
} else {
arraysHashCodeCall.selector = "hashCode".toCharArray();
@@ -384,7 +385,7 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
/* fold each intoResult entry into:
result = result * PRIME + (item); */ {
- for ( Expression ex : intoResult ) {
+ for (Expression ex : intoResult) {
SingleNameReference resultRef = new SingleNameReference(RESULT, p);
Eclipse.setGeneratedBy(resultRef, source);
SingleNameReference primeRef = new SingleNameReference(PRIME, p);
@@ -415,7 +416,7 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
return method;
}
- private MethodDeclaration createEquals(Node type, Collection<Node> fields, boolean callSuper, ASTNode source) {
+ private MethodDeclaration createEquals(EclipseNode type, Collection<EclipseNode> fields, boolean callSuper, ASTNode source) {
int pS = source.sourceStart; int pE = source.sourceEnd;
long p = (long)pS << 32 | pE;
@@ -441,7 +442,7 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
List<Statement> statements = new ArrayList<Statement>();
- /* if ( o == this ) return true; */ {
+ /* if (o == this) return true; */ {
SingleNameReference oRef = new SingleNameReference(new char[] { 'o' }, p);
Eclipse.setGeneratedBy(oRef, source);
ThisReference thisRef = new ThisReference(pS, pE);
@@ -458,7 +459,7 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
statements.add(ifOtherEqualsThis);
}
- /* if ( o == null ) return false; */ {
+ /* if (o == null) return false; */ {
SingleNameReference oRef = new SingleNameReference(new char[] { 'o' }, p);
Eclipse.setGeneratedBy(oRef, source);
NullLiteral nullLiteral = new NullLiteral(pS, pE);
@@ -475,7 +476,7 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
statements.add(ifOtherEqualsNull);
}
- /* if ( o.getClass() != getClass() ) return false; */ {
+ /* if (o.getClass() != getClass()) return false; */ {
MessageSend otherGetClass = new MessageSend();
otherGetClass.sourceStart = pS; otherGetClass.sourceEnd = pE;
Eclipse.setGeneratedBy(otherGetClass, source);
@@ -501,8 +502,8 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
char[] otherN = "other".toCharArray();
- /* if ( !super.equals(o) ) return false; */
- if ( callSuper ) {
+ /* if (!super.equals(o)) return false; */
+ if (callSuper) {
MessageSend callToSuper = new MessageSend();
callToSuper.sourceStart = pS; callToSuper.sourceEnd = pE;
Eclipse.setGeneratedBy(callToSuper, source);
@@ -525,19 +526,19 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
TypeDeclaration typeDecl = (TypeDeclaration)type.get();
/* MyType<?> other = (MyType<?>) o; */ {
- if ( !fields.isEmpty() ) {
+ if (!fields.isEmpty()) {
LocalDeclaration other = new LocalDeclaration(otherN, pS, pE);
Eclipse.setGeneratedBy(other, source);
char[] typeName = typeDecl.name;
Expression targetType;
- if ( typeDecl.typeParameters == null || typeDecl.typeParameters.length == 0 ) {
+ if (typeDecl.typeParameters == null || typeDecl.typeParameters.length == 0) {
targetType = new SingleNameReference(((TypeDeclaration)type.get()).name, p);
Eclipse.setGeneratedBy(targetType, source);
other.type = new SingleTypeReference(typeName, p);
Eclipse.setGeneratedBy(other.type, source);
} else {
TypeReference[] typeArgs = new TypeReference[typeDecl.typeParameters.length];
- for ( int i = 0 ; i < typeArgs.length ; i++ ) {
+ for (int i = 0; i < typeArgs.length; i++) {
typeArgs[i] = new Wildcard(Wildcard.UNBOUND);
typeArgs[i].sourceStart = pS; typeArgs[i].sourceEnd = pE;
Eclipse.setGeneratedBy(typeArgs[i], source);
@@ -555,15 +556,15 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
}
}
- for ( Node field : fields ) {
+ for (EclipseNode field : fields) {
FieldDeclaration f = (FieldDeclaration) field.get();
char[] token = f.type.getLastToken();
- if ( f.type.dimensions() == 0 && token != null ) {
- if ( Arrays.equals(TypeConstants.FLOAT, token) ) {
+ if (f.type.dimensions() == 0 && token != null) {
+ if (Arrays.equals(TypeConstants.FLOAT, token)) {
statements.add(generateCompareFloatOrDouble(otherN, "Float".toCharArray(), f.name, source));
- } else if ( Arrays.equals(TypeConstants.DOUBLE, token) ) {
+ } else if (Arrays.equals(TypeConstants.DOUBLE, token)) {
statements.add(generateCompareFloatOrDouble(otherN, "Double".toCharArray(), f.name, source));
- } else if ( BUILT_IN_TYPES.contains(new String(token)) ) {
+ } else if (BUILT_IN_TYPES.contains(new String(token))) {
NameReference fieldRef = new SingleNameReference(f.name, p);
Eclipse.setGeneratedBy(fieldRef, source);
EqualExpression fieldsNotEqual = new EqualExpression(fieldRef,
@@ -608,12 +609,12 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
Eclipse.setGeneratedBy(ifStatement, source);
statements.add(ifStatement);
}
- } else if ( f.type.dimensions() > 0 && token != null ) {
+ } else if (f.type.dimensions() > 0 && token != null) {
MessageSend arraysEqualCall = new MessageSend();
arraysEqualCall.sourceStart = pS; arraysEqualCall.sourceEnd = pE;
Eclipse.setGeneratedBy(arraysEqualCall, source);
arraysEqualCall.receiver = generateQualifiedNameRef(source, TypeConstants.JAVA, TypeConstants.UTIL, "Arrays".toCharArray());
- if ( f.type.dimensions() > 1 || !BUILT_IN_TYPES.contains(new String(token)) ) {
+ if (f.type.dimensions() > 1 || !BUILT_IN_TYPES.contains(new String(token))) {
arraysEqualCall.selector = "deepEquals".toCharArray();
} else {
arraysEqualCall.selector = "equals".toCharArray();
@@ -648,7 +649,7 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
private IfStatement generateCompareFloatOrDouble(char[] otherN, char[] floatOrDouble, char[] fieldName, ASTNode source) {
int pS = source.sourceStart, pE = source.sourceEnd;
long p = (long)pS << 32 | pE;
- /* if ( Float.compare(fieldName, other.fieldName) != 0 ) return false */
+ /* if (Float.compare(fieldName, other.fieldName) != 0) return false */
MessageSend floatCompare = new MessageSend();
floatCompare.sourceStart = pS; floatCompare.sourceEnd = pE;
Eclipse.setGeneratedBy(floatCompare, source);
@@ -707,7 +708,7 @@ public class HandleEqualsAndHashCode implements EclipseAnnotationHandler<EqualsA
NameReference ref;
- if ( varNames.length > 1 ) ref = new QualifiedNameReference(varNames, new long[varNames.length], pS, pE);
+ if (varNames.length > 1) ref = new QualifiedNameReference(varNames, new long[varNames.length], pS, pE);
else ref = new SingleNameReference(varNames[0], p);
Eclipse.setGeneratedBy(ref, source);
return ref;
diff --git a/src/lombok/eclipse/handlers/HandleGetter.java b/src/lombok/eclipse/handlers/HandleGetter.java
index 9760fe01..ad9f59f7 100644
--- a/src/lombok/eclipse/handlers/HandleGetter.java
+++ b/src/lombok/eclipse/handlers/HandleGetter.java
@@ -30,7 +30,7 @@ import lombok.core.TransformationsUtil;
import lombok.core.AST.Kind;
import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseAnnotationHandler;
-import lombok.eclipse.EclipseAST.Node;
+import lombok.eclipse.EclipseNode;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
@@ -62,10 +62,10 @@ public class HandleGetter implements EclipseAnnotationHandler<Getter> {
* If not, the getter is still generated if it isn't already there, though there will not
* be a warning if its already there. The default access level is used.
*/
- public void generateGetterForField(Node fieldNode, ASTNode pos) {
- for ( Node child : fieldNode.down() ) {
- if ( child.getKind() == Kind.ANNOTATION ) {
- if ( annotationTypeMatches(Getter.class, child) ) {
+ public void generateGetterForField(EclipseNode fieldNode, ASTNode pos) {
+ for (EclipseNode child : fieldNode.down()) {
+ if (child.getKind() == Kind.ANNOTATION) {
+ if (annotationTypeMatches(Getter.class, child)) {
//The annotation will make it happen, so we can skip it.
return;
}
@@ -75,16 +75,17 @@ public class HandleGetter implements EclipseAnnotationHandler<Getter> {
createGetterForField(AccessLevel.PUBLIC, fieldNode, fieldNode, pos, false);
}
- public boolean handle(AnnotationValues<Getter> annotation, Annotation ast, Node annotationNode) {
- Node fieldNode = annotationNode.up();
+ public boolean handle(AnnotationValues<Getter> annotation, Annotation ast, EclipseNode annotationNode) {
+ EclipseNode fieldNode = annotationNode.up();
AccessLevel level = annotation.getInstance().value();
- if ( level == AccessLevel.NONE ) return true;
+ if (level == AccessLevel.NONE) return true;
return createGetterForField(level, fieldNode, annotationNode, annotationNode.get(), true);
}
- private boolean createGetterForField(AccessLevel level, Node fieldNode, Node errorNode, ASTNode source, boolean whineIfExists) {
- if ( fieldNode.getKind() != Kind.FIELD ) {
+ private boolean createGetterForField(AccessLevel level,
+ EclipseNode fieldNode, EclipseNode errorNode, ASTNode source, boolean whineIfExists) {
+ if (fieldNode.getKind() != Kind.FIELD) {
errorNode.addError("@Getter is only supported on a field.");
return true;
}
@@ -97,14 +98,14 @@ public class HandleGetter implements EclipseAnnotationHandler<Getter> {
int modifier = toModifier(level) | (field.modifiers & ClassFileConstants.AccStatic);
- for ( String altName : TransformationsUtil.toAllGetterNames(fieldName, isBoolean) ) {
- switch ( methodExists(altName, fieldNode) ) {
+ for (String altName : TransformationsUtil.toAllGetterNames(fieldName, isBoolean)) {
+ switch (methodExists(altName, fieldNode)) {
case EXISTS_BY_LOMBOK:
return true;
case EXISTS_BY_USER:
- if ( whineIfExists ) {
+ if (whineIfExists) {
String altNameExpl = "";
- if ( !altName.equals(getterName) ) altNameExpl = String.format(" (%s)", altName);
+ if (!altName.equals(getterName)) altNameExpl = String.format(" (%s)", altName);
errorNode.addWarning(
String.format("Not generating %s(): A method with that name already exists%s", getterName, altNameExpl));
}
diff --git a/src/lombok/eclipse/handlers/HandlePrintAST.java b/src/lombok/eclipse/handlers/HandlePrintAST.java
index 2f2b38d4..3e1df93d 100644
--- a/src/lombok/eclipse/handlers/HandlePrintAST.java
+++ b/src/lombok/eclipse/handlers/HandlePrintAST.java
@@ -33,21 +33,21 @@ import lombok.core.AnnotationValues;
import lombok.core.PrintAST;
import lombok.eclipse.EclipseASTVisitor;
import lombok.eclipse.EclipseAnnotationHandler;
-import lombok.eclipse.EclipseAST.Node;
+import lombok.eclipse.EclipseNode;
/**
* Handles the <code>lombok.core.PrintAST</code> annotation for eclipse.
*/
@ProviderFor(EclipseAnnotationHandler.class)
public class HandlePrintAST implements EclipseAnnotationHandler<PrintAST> {
- public boolean handle(AnnotationValues<PrintAST> annotation, Annotation ast, Node annotationNode) {
- if ( !annotationNode.isCompleteParse() ) return false;
+ public boolean handle(AnnotationValues<PrintAST> annotation, Annotation ast, EclipseNode annotationNode) {
+ if (!annotationNode.isCompleteParse()) return false;
PrintStream stream = System.out;
String fileName = annotation.getInstance().outfile();
- if ( fileName.length() > 0 ) try {
+ if (fileName.length() > 0) try {
stream = new PrintStream(new File(fileName));
- } catch ( FileNotFoundException e ) {
+ } catch (FileNotFoundException e) {
Lombok.sneakyThrow(e);
}
diff --git a/src/lombok/eclipse/handlers/HandleSetter.java b/src/lombok/eclipse/handlers/HandleSetter.java
index f804eefc..0ef3c44b 100644
--- a/src/lombok/eclipse/handlers/HandleSetter.java
+++ b/src/lombok/eclipse/handlers/HandleSetter.java
@@ -33,7 +33,7 @@ import lombok.core.TransformationsUtil;
import lombok.core.AST.Kind;
import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseAnnotationHandler;
-import lombok.eclipse.EclipseAST.Node;
+import lombok.eclipse.EclipseNode;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
@@ -69,10 +69,10 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> {
* If not, the setter is still generated if it isn't already there, though there will not
* be a warning if its already there. The default access level is used.
*/
- public void generateSetterForField(Node fieldNode, ASTNode pos) {
- for ( Node child : fieldNode.down() ) {
- if ( child.getKind() == Kind.ANNOTATION ) {
- if ( annotationTypeMatches(Setter.class, child) ) {
+ public void generateSetterForField(EclipseNode fieldNode, ASTNode pos) {
+ for (EclipseNode child : fieldNode.down()) {
+ if (child.getKind() == Kind.ANNOTATION) {
+ if (annotationTypeMatches(Setter.class, child)) {
//The annotation will make it happen, so we can skip it.
return;
}
@@ -82,17 +82,18 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> {
createSetterForField(AccessLevel.PUBLIC, fieldNode, fieldNode, pos, false);
}
- public boolean handle(AnnotationValues<Setter> annotation, Annotation ast, Node annotationNode) {
- Node fieldNode = annotationNode.up();
- if ( fieldNode.getKind() != Kind.FIELD ) return false;
+ public boolean handle(AnnotationValues<Setter> annotation, Annotation ast, EclipseNode annotationNode) {
+ EclipseNode fieldNode = annotationNode.up();
+ if (fieldNode.getKind() != Kind.FIELD) return false;
AccessLevel level = annotation.getInstance().value();
- if ( level == AccessLevel.NONE ) return true;
+ if (level == AccessLevel.NONE) return true;
return createSetterForField(level, fieldNode, annotationNode, annotationNode.get(), true);
}
- private boolean createSetterForField(AccessLevel level, Node fieldNode, Node errorNode, ASTNode pos, boolean whineIfExists) {
- if ( fieldNode.getKind() != Kind.FIELD ) {
+ private boolean createSetterForField(AccessLevel level,
+ EclipseNode fieldNode, EclipseNode errorNode, ASTNode pos, boolean whineIfExists) {
+ if (fieldNode.getKind() != Kind.FIELD) {
errorNode.addError("@Setter is only supported on a field.");
return true;
}
@@ -102,11 +103,11 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> {
int modifier = toModifier(level) | (field.modifiers & ClassFileConstants.AccStatic);
- switch ( methodExists(setterName, fieldNode) ) {
+ switch (methodExists(setterName, fieldNode)) {
case EXISTS_BY_LOMBOK:
return true;
case EXISTS_BY_USER:
- if ( whineIfExists ) errorNode.addWarning(
+ if (whineIfExists) errorNode.addWarning(
String.format("Not generating %s(%s %s): A method with that name already exists",
setterName, field.type, new String(field.name)));
return true;
@@ -115,7 +116,6 @@ public class HandleSetter implements EclipseAnnotationHandler<Setter> {
//continue with creating the setter
}
-
MethodDeclaration method = generateSetter((TypeDeclaration) fieldNode.up().get(), field, setterName, modifier, pos);
injectMethod(fieldNode.up(), method);
diff --git a/src/lombok/eclipse/handlers/HandleSneakyThrows.java b/src/lombok/eclipse/handlers/HandleSneakyThrows.java
index 75dad780..5cb5dca7 100644
--- a/src/lombok/eclipse/handlers/HandleSneakyThrows.java
+++ b/src/lombok/eclipse/handlers/HandleSneakyThrows.java
@@ -29,7 +29,7 @@ import lombok.SneakyThrows;
import lombok.core.AnnotationValues;
import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseAnnotationHandler;
-import lombok.eclipse.EclipseAST.Node;
+import lombok.eclipse.EclipseNode;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
@@ -69,35 +69,35 @@ public class HandleSneakyThrows implements EclipseAnnotationHandler<SneakyThrows
}
}
- @Override public boolean handle(AnnotationValues<SneakyThrows> annotation, Annotation source, Node annotationNode) {
+ @Override public boolean handle(AnnotationValues<SneakyThrows> annotation, Annotation source, EclipseNode annotationNode) {
List<String> exceptionNames = annotation.getRawExpressions("value");
List<DeclaredException> exceptions = new ArrayList<DeclaredException>();
MemberValuePair[] memberValuePairs = source.memberValuePairs();
- if ( memberValuePairs == null || memberValuePairs.length == 0 ) {
+ if (memberValuePairs == null || memberValuePairs.length == 0) {
exceptions.add(new DeclaredException("java.lang.Throwable", source));
} else {
Expression arrayOrSingle = memberValuePairs[0].value;
final Expression[] exceptionNameNodes;
- if ( arrayOrSingle instanceof ArrayInitializer ) {
+ if (arrayOrSingle instanceof ArrayInitializer) {
exceptionNameNodes = ((ArrayInitializer)arrayOrSingle).expressions;
} else exceptionNameNodes = new Expression[] { arrayOrSingle };
- if ( exceptionNames.size() != exceptionNameNodes.length ) {
+ if (exceptionNames.size() != exceptionNameNodes.length) {
annotationNode.addError(
"LOMBOK BUG: The number of exception classes in the annotation isn't the same pre- and post- guessing.");
}
int idx = 0;
- for ( String exceptionName : exceptionNames ) {
- if ( exceptionName.endsWith(".class") ) exceptionName = exceptionName.substring(0, exceptionName.length() - 6);
+ for (String exceptionName : exceptionNames) {
+ if (exceptionName.endsWith(".class")) exceptionName = exceptionName.substring(0, exceptionName.length() - 6);
exceptions.add(new DeclaredException(exceptionName, exceptionNameNodes[idx++]));
}
}
- Node owner = annotationNode.up();
- switch ( owner.getKind() ) {
+ EclipseNode owner = annotationNode.up();
+ switch (owner.getKind()) {
// case FIELD:
// return handleField(annotationNode, (FieldDeclaration)owner.get(), exceptions);
case METHOD:
@@ -109,7 +109,7 @@ public class HandleSneakyThrows implements EclipseAnnotationHandler<SneakyThrows
}
// private boolean handleField(Node annotation, FieldDeclaration field, List<DeclaredException> exceptions) {
-// if ( field.initialization == null ) {
+// if (field.initialization == null) {
// annotation.addError("@SneakyThrows can only be used on fields with an initialization statement.");
// return true;
// }
@@ -119,7 +119,7 @@ public class HandleSneakyThrows implements EclipseAnnotationHandler<SneakyThrows
// new SingleNameReference(field.name, 0), expression, 0)};
// field.initialization = null;
//
-// for ( DeclaredException exception : exceptions ) {
+// for (DeclaredException exception : exceptions) {
// content = new Statement[] { buildTryCatchBlock(content, exception) };
// }
//
@@ -140,17 +140,17 @@ public class HandleSneakyThrows implements EclipseAnnotationHandler<SneakyThrows
// return true;
// }
- private boolean handleMethod(Node annotation, AbstractMethodDeclaration method, List<DeclaredException> exceptions) {
- if ( method.isAbstract() ) {
+ private boolean handleMethod(EclipseNode annotation, AbstractMethodDeclaration method, List<DeclaredException> exceptions) {
+ if (method.isAbstract()) {
annotation.addError("@SneakyThrows can only be used on concrete methods.");
return true;
}
- if ( method.statements == null ) return false;
+ if (method.statements == null) return false;
Statement[] contents = method.statements;
- for ( DeclaredException exception : exceptions ) {
+ for (DeclaredException exception : exceptions) {
contents = new Statement[] { buildTryCatchBlock(contents, exception, exception.node) };
}
@@ -171,7 +171,7 @@ public class HandleSneakyThrows implements EclipseAnnotationHandler<SneakyThrows
Eclipse.setGeneratedBy(tryStatement.tryBlock, source);
tryStatement.tryBlock.statements = contents;
TypeReference typeReference;
- if ( exception.exceptionName.indexOf('.') == -1 ) {
+ if (exception.exceptionName.indexOf('.') == -1) {
typeReference = new SingleTypeReference(exception.exceptionName.toCharArray(), p);
typeReference.statementEnd = pE;
} else {
@@ -179,7 +179,7 @@ public class HandleSneakyThrows implements EclipseAnnotationHandler<SneakyThrows
char[][] elems = new char[x.length][];
long[] poss = new long[x.length];
int start = pS;
- for ( int i = 0 ; i < x.length ; i++ ) {
+ for (int i = 0; i < x.length; i++) {
elems[i] = x[i].trim().toCharArray();
int end = start + x[i].length();
poss[i] = (long)start << 32 | end;
diff --git a/src/lombok/eclipse/handlers/HandleSynchronized.java b/src/lombok/eclipse/handlers/HandleSynchronized.java
index 7a573198..5f1d0864 100644
--- a/src/lombok/eclipse/handlers/HandleSynchronized.java
+++ b/src/lombok/eclipse/handlers/HandleSynchronized.java
@@ -30,7 +30,7 @@ import lombok.core.AnnotationValues;
import lombok.core.AST.Kind;
import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseAnnotationHandler;
-import lombok.eclipse.EclipseAST.Node;
+import lombok.eclipse.EclipseNode;
import lombok.eclipse.handlers.PKG.MemberExistsResult;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
@@ -57,31 +57,31 @@ public class HandleSynchronized implements EclipseAnnotationHandler<Synchronized
private static final char[] INSTANCE_LOCK_NAME = "$lock".toCharArray();
private static final char[] STATIC_LOCK_NAME = "$LOCK".toCharArray();
- @Override public boolean handle(AnnotationValues<Synchronized> annotation, Annotation source, Node annotationNode) {
+ @Override public boolean handle(AnnotationValues<Synchronized> annotation, Annotation source, EclipseNode annotationNode) {
int p1 = source.sourceStart -1;
int p2 = source.sourceStart -2;
long pos = (((long)p1) << 32) | p2;
- Node methodNode = annotationNode.up();
- if ( methodNode == null || methodNode.getKind() != Kind.METHOD || !(methodNode.get() instanceof MethodDeclaration) ) {
+ EclipseNode methodNode = annotationNode.up();
+ if (methodNode == null || methodNode.getKind() != Kind.METHOD || !(methodNode.get() instanceof MethodDeclaration)) {
annotationNode.addError("@Synchronized is legal only on methods.");
return true;
}
MethodDeclaration method = (MethodDeclaration)methodNode.get();
- if ( method.isAbstract() ) {
+ if (method.isAbstract()) {
annotationNode.addError("@Synchronized is legal only on concrete methods.");
return true;
}
char[] lockName = annotation.getInstance().value().toCharArray();
boolean autoMake = false;
- if ( lockName.length == 0 ) {
+ if (lockName.length == 0) {
autoMake = true;
lockName = method.isStatic() ? STATIC_LOCK_NAME : INSTANCE_LOCK_NAME;
}
- if ( fieldExists(new String(lockName), methodNode) == MemberExistsResult.NOT_EXISTS ) {
- if ( !autoMake ) {
+ if (fieldExists(new String(lockName), methodNode) == MemberExistsResult.NOT_EXISTS) {
+ if (!autoMake) {
annotationNode.addError("The field " + new String(lockName) + " does not exist.");
return true;
}
@@ -104,13 +104,13 @@ public class HandleSynchronized implements EclipseAnnotationHandler<Synchronized
injectField(annotationNode.up().up(), fieldDecl);
}
- if ( method.statements == null ) return false;
+ if (method.statements == null) return false;
Block block = new Block(0);
Eclipse.setGeneratedBy(block, source);
block.statements = method.statements;
Expression lockVariable;
- if ( method.isStatic() ) lockVariable = new QualifiedNameReference(new char[][] {
+ if (method.isStatic()) lockVariable = new QualifiedNameReference(new char[][] {
methodNode.up().getName().toCharArray(), lockName }, new long[] { pos, pos }, p1, p2);
else {
lockVariable = new FieldReference(lockName, pos);
diff --git a/src/lombok/eclipse/handlers/HandleToString.java b/src/lombok/eclipse/handlers/HandleToString.java
index 5a840e1f..263a588c 100644
--- a/src/lombok/eclipse/handlers/HandleToString.java
+++ b/src/lombok/eclipse/handlers/HandleToString.java
@@ -37,7 +37,7 @@ import lombok.core.AnnotationValues;
import lombok.core.AST.Kind;
import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseAnnotationHandler;
-import lombok.eclipse.EclipseAST.Node;
+import lombok.eclipse.EclipseNode;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
@@ -68,24 +68,23 @@ import org.mangosdk.spi.ProviderFor;
*/
@ProviderFor(EclipseAnnotationHandler.class)
public class HandleToString implements EclipseAnnotationHandler<ToString> {
- private void checkForBogusFieldNames(Node type, AnnotationValues<ToString> annotation) {
- if ( annotation.isExplicit("exclude") ) {
- for ( int i : createListOfNonExistentFields(Arrays.asList(annotation.getInstance().exclude()), type, true, false) ) {
+ private void checkForBogusFieldNames(EclipseNode type, AnnotationValues<ToString> annotation) {
+ if (annotation.isExplicit("exclude")) {
+ for (int i : createListOfNonExistentFields(Arrays.asList(annotation.getInstance().exclude()), type, true, false)) {
annotation.setWarning("exclude", "This field does not exist, or would have been excluded anyway.", i);
}
}
- if ( annotation.isExplicit("of") ) {
- for ( int i : createListOfNonExistentFields(Arrays.asList(annotation.getInstance().of()), type, false, false) ) {
+ if (annotation.isExplicit("of")) {
+ for (int i : createListOfNonExistentFields(Arrays.asList(annotation.getInstance().of()), type, false, false)) {
annotation.setWarning("of", "This field does not exist.", i);
}
}
}
-
- public void generateToStringForType(Node typeNode, Node errorNode) {
- for ( Node child : typeNode.down() ) {
- if ( child.getKind() == Kind.ANNOTATION ) {
- if ( Eclipse.annotationTypeMatches(ToString.class, child) ) {
+ public void generateToStringForType(EclipseNode typeNode, EclipseNode errorNode) {
+ for (EclipseNode child : typeNode.down()) {
+ if (child.getKind() == Kind.ANNOTATION) {
+ if (Eclipse.annotationTypeMatches(ToString.class, child)) {
//The annotation will make it happen, so we can skip it.
return;
}
@@ -95,22 +94,22 @@ public class HandleToString implements EclipseAnnotationHandler<ToString> {
boolean includeFieldNames = true;
try {
includeFieldNames = ((Boolean)ToString.class.getMethod("includeFieldNames").getDefaultValue()).booleanValue();
- } catch ( Exception ignore ) {}
+ } catch (Exception ignore) {}
generateToString(typeNode, errorNode, null, null, includeFieldNames, null, false);
}
- public boolean handle(AnnotationValues<ToString> annotation, Annotation ast, Node annotationNode) {
+ public boolean handle(AnnotationValues<ToString> annotation, Annotation ast, EclipseNode annotationNode) {
ToString ann = annotation.getInstance();
List<String> excludes = Arrays.asList(ann.exclude());
List<String> includes = Arrays.asList(ann.of());
- Node typeNode = annotationNode.up();
+ EclipseNode typeNode = annotationNode.up();
Boolean callSuper = ann.callSuper();
- if ( !annotation.isExplicit("callSuper") ) callSuper = null;
- if ( !annotation.isExplicit("exclude") ) excludes = null;
- if ( !annotation.isExplicit("of") ) includes = null;
+ if (!annotation.isExplicit("callSuper")) callSuper = null;
+ if (!annotation.isExplicit("exclude")) excludes = null;
+ if (!annotation.isExplicit("of")) includes = null;
- if ( excludes != null && includes != null ) {
+ if (excludes != null && includes != null) {
excludes = null;
annotation.setWarning("exclude", "exclude and of are mutually exclusive; the 'exclude' parameter will be ignored.");
}
@@ -120,48 +119,48 @@ public class HandleToString implements EclipseAnnotationHandler<ToString> {
return generateToString(typeNode, annotationNode, excludes, includes, ann.includeFieldNames(), callSuper, true);
}
- public boolean generateToString(Node typeNode, Node errorNode, List<String> excludes, List<String> includes,
+ public boolean generateToString(EclipseNode typeNode, EclipseNode errorNode, List<String> excludes, List<String> includes,
boolean includeFieldNames, Boolean callSuper, boolean whineIfExists) {
TypeDeclaration typeDecl = null;
- if ( typeNode.get() instanceof TypeDeclaration ) typeDecl = (TypeDeclaration) typeNode.get();
+ if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get();
int modifiers = typeDecl == null ? 0 : typeDecl.modifiers;
boolean notAClass = (modifiers &
(ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation | ClassFileConstants.AccEnum)) != 0;
- if ( typeDecl == null || notAClass ) {
+ if (typeDecl == null || notAClass) {
errorNode.addError("@ToString is only supported on a class.");
return false;
}
- if ( callSuper == null ) {
+ if (callSuper == null) {
try {
callSuper = ((Boolean)ToString.class.getMethod("callSuper").getDefaultValue()).booleanValue();
- } catch ( Exception ignore ) {}
+ } catch (Exception ignore) {}
}
- List<Node> nodesForToString = new ArrayList<Node>();
- if ( includes != null ) {
- for ( Node child : typeNode.down() ) {
- if ( child.getKind() != Kind.FIELD ) continue;
+ List<EclipseNode> nodesForToString = new ArrayList<EclipseNode>();
+ if (includes != null) {
+ for (EclipseNode child : typeNode.down()) {
+ if (child.getKind() != Kind.FIELD) continue;
FieldDeclaration fieldDecl = (FieldDeclaration) child.get();
- if ( includes.contains(new String(fieldDecl.name)) ) nodesForToString.add(child);
+ if (includes.contains(new String(fieldDecl.name))) nodesForToString.add(child);
}
} else {
- for ( Node child : typeNode.down() ) {
- if ( child.getKind() != Kind.FIELD ) continue;
+ for (EclipseNode child : typeNode.down()) {
+ if (child.getKind() != Kind.FIELD) continue;
FieldDeclaration fieldDecl = (FieldDeclaration) child.get();
//Skip static fields.
- if ( (fieldDecl.modifiers & ClassFileConstants.AccStatic) != 0 ) continue;
+ if ((fieldDecl.modifiers & ClassFileConstants.AccStatic) != 0) continue;
//Skip excluded fields.
- if ( excludes != null && excludes.contains(new String(fieldDecl.name)) ) continue;
+ if (excludes != null && excludes.contains(new String(fieldDecl.name))) continue;
//Skip fields that start with $
- if ( fieldDecl.name.length > 0 && fieldDecl.name[0] == '$' ) continue;
+ if (fieldDecl.name.length > 0 && fieldDecl.name[0] == '$') continue;
nodesForToString.add(child);
}
}
- switch ( methodExists("toString", typeNode) ) {
+ switch (methodExists("toString", typeNode)) {
case NOT_EXISTS:
MethodDeclaration toString = createToString(typeNode, nodesForToString, includeFieldNames, callSuper, errorNode.get());
injectMethod(typeNode, toString);
@@ -170,14 +169,15 @@ public class HandleToString implements EclipseAnnotationHandler<ToString> {
return true;
default:
case EXISTS_BY_USER:
- if ( whineIfExists ) {
+ if (whineIfExists) {
errorNode.addWarning("Not generating toString(): A method with that name already exists");
}
return true;
}
}
- private MethodDeclaration createToString(Node type, Collection<Node> fields, boolean includeFieldNames, boolean callSuper, ASTNode source) {
+ private MethodDeclaration createToString(EclipseNode type, Collection<EclipseNode> fields,
+ boolean includeFieldNames, boolean callSuper, ASTNode source) {
TypeDeclaration typeDeclaration = (TypeDeclaration)type.get();
char[] rawTypeName = typeDeclaration.name;
String typeName = rawTypeName == null ? "" : new String(rawTypeName);
@@ -190,11 +190,11 @@ public class HandleToString implements EclipseAnnotationHandler<ToString> {
char[] prefix;
- if ( callSuper ) {
+ if (callSuper) {
prefix = (typeName + "(super=").toCharArray();
- } else if ( fields.isEmpty() ) {
+ } else if (fields.isEmpty()) {
prefix = (typeName + "()").toCharArray();
- } else if ( includeFieldNames ) {
+ } else if (includeFieldNames) {
prefix = (typeName + "(" + new String(((FieldDeclaration)fields.iterator().next().get()).name) + "=").toCharArray();
} else {
prefix = (typeName + "(").toCharArray();
@@ -204,7 +204,7 @@ public class HandleToString implements EclipseAnnotationHandler<ToString> {
Expression current = new StringLiteral(prefix, pS, pE, 0);
Eclipse.setGeneratedBy(current, source);
- if ( callSuper ) {
+ if (callSuper) {
MessageSend callToSuper = new MessageSend();
callToSuper.sourceStart = pS; callToSuper.sourceEnd = pE;
Eclipse.setGeneratedBy(callToSuper, source);
@@ -216,18 +216,18 @@ public class HandleToString implements EclipseAnnotationHandler<ToString> {
first = false;
}
- for ( Node field : fields ) {
+ for (EclipseNode field : fields) {
FieldDeclaration f = (FieldDeclaration)field.get();
- if ( f.name == null || f.type == null ) continue;
+ if (f.name == null || f.type == null) continue;
Expression ex;
- if ( f.type.dimensions() > 0 ) {
+ if (f.type.dimensions() > 0) {
MessageSend arrayToString = new MessageSend();
arrayToString.sourceStart = pS; arrayToString.sourceEnd = pE;
arrayToString.receiver = generateQualifiedNameRef(source, TypeConstants.JAVA, TypeConstants.UTIL, "Arrays".toCharArray());
arrayToString.arguments = new Expression[] { new SingleNameReference(f.name, p) };
Eclipse.setGeneratedBy(arrayToString.arguments[0], source);
- if ( f.type.dimensions() > 1 || !BUILT_IN_TYPES.contains(new String(f.type.getLastToken())) ) {
+ if (f.type.dimensions() > 1 || !BUILT_IN_TYPES.contains(new String(f.type.getLastToken()))) {
arrayToString.selector = "deepToString".toCharArray();
} else {
arrayToString.selector = "toString".toCharArray();
@@ -241,7 +241,7 @@ public class HandleToString implements EclipseAnnotationHandler<ToString> {
}
Eclipse.setGeneratedBy(ex, source);
- if ( first ) {
+ if (first) {
current = new BinaryExpression(current, ex, PLUS);
current.sourceStart = pS; current.sourceEnd = pE;
Eclipse.setGeneratedBy(current, source);
@@ -250,7 +250,7 @@ public class HandleToString implements EclipseAnnotationHandler<ToString> {
}
StringLiteral fieldNameLiteral;
- if ( includeFieldNames ) {
+ if (includeFieldNames) {
char[] namePlusEqualsSign = (infixS + new String(f.name) + "=").toCharArray();
fieldNameLiteral = new StringLiteral(namePlusEqualsSign, pS, pE, 0);
} else {
@@ -262,7 +262,7 @@ public class HandleToString implements EclipseAnnotationHandler<ToString> {
current = new BinaryExpression(current, ex, PLUS);
Eclipse.setGeneratedBy(current, source);
}
- if ( !first ) {
+ if (!first) {
StringLiteral suffixLiteral = new StringLiteral(suffix, pS, pE, 0);
Eclipse.setGeneratedBy(suffixLiteral, source);
current = new BinaryExpression(current, suffixLiteral, PLUS);
@@ -296,7 +296,7 @@ public class HandleToString implements EclipseAnnotationHandler<ToString> {
int pS = source.sourceStart, pE = source.sourceEnd;
long p = (long)pS << 32 | pE;
NameReference ref;
- if ( varNames.length > 1 ) ref = new QualifiedNameReference(varNames, new long[varNames.length], pS, pE);
+ if (varNames.length > 1) ref = new QualifiedNameReference(varNames, new long[varNames.length], pS, pE);
else ref = new SingleNameReference(varNames[0], p);
Eclipse.setGeneratedBy(ref, source);
return ref;
diff --git a/src/lombok/eclipse/handlers/PKG.java b/src/lombok/eclipse/handlers/PKG.java
index 6bc4499d..65145262 100644
--- a/src/lombok/eclipse/handlers/PKG.java
+++ b/src/lombok/eclipse/handlers/PKG.java
@@ -32,8 +32,7 @@ import lombok.AccessLevel;
import lombok.core.TransformationsUtil;
import lombok.core.AST.Kind;
import lombok.eclipse.Eclipse;
-import lombok.eclipse.EclipseAST;
-import lombok.eclipse.EclipseAST.Node;
+import lombok.eclipse.EclipseNode;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
@@ -66,7 +65,7 @@ class PKG {
}
static int toModifier(AccessLevel value) {
- switch ( value ) {
+ switch (value) {
case MODULE:
case PACKAGE:
return 0;
@@ -83,8 +82,8 @@ class PKG {
static boolean nameEquals(char[][] typeName, String string) {
StringBuilder sb = new StringBuilder();
boolean first = true;
- for ( char[] elem : typeName ) {
- if ( first ) first = false;
+ for (char[] elem : typeName) {
+ if (first) first = false;
else sb.append('.');
sb.append(elem);
}
@@ -96,19 +95,19 @@ class PKG {
NOT_EXISTS, EXISTS_BY_USER, EXISTS_BY_LOMBOK;
}
- static MemberExistsResult fieldExists(String fieldName, EclipseAST.Node node) {
- while ( node != null && !(node.get() instanceof TypeDeclaration) ) {
+ static MemberExistsResult fieldExists(String fieldName, EclipseNode node) {
+ while (node != null && !(node.get() instanceof TypeDeclaration)) {
node = node.up();
}
- if ( node != null && node.get() instanceof TypeDeclaration ) {
+ if (node != null && node.get() instanceof TypeDeclaration) {
TypeDeclaration typeDecl = (TypeDeclaration)node.get();
- if ( typeDecl.fields != null ) for ( FieldDeclaration def : typeDecl.fields ) {
+ 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;
+ if (fName == null) continue;
+ if (fieldName.equals(new String(fName))) {
+ EclipseNode existing = node.getNodeFor(def);
+ if (existing == null || !existing.isHandled()) return MemberExistsResult.EXISTS_BY_USER;
return MemberExistsResult.EXISTS_BY_LOMBOK;
}
}
@@ -117,19 +116,19 @@ class PKG {
return MemberExistsResult.NOT_EXISTS;
}
- static MemberExistsResult methodExists(String methodName, EclipseAST.Node node) {
- while ( node != null && !(node.get() instanceof TypeDeclaration) ) {
+ static MemberExistsResult methodExists(String methodName, EclipseNode node) {
+ while (node != null && !(node.get() instanceof TypeDeclaration)) {
node = node.up();
}
- if ( node != null && node.get() instanceof TypeDeclaration ) {
+ if (node != null && node.get() instanceof TypeDeclaration) {
TypeDeclaration typeDecl = (TypeDeclaration)node.get();
- if ( typeDecl.methods != null ) for ( AbstractMethodDeclaration def : typeDecl.methods ) {
+ if (typeDecl.methods != null) for (AbstractMethodDeclaration def : typeDecl.methods) {
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 MemberExistsResult.EXISTS_BY_USER;
+ if (mName == null) continue;
+ if (methodName.equals(new String(mName))) {
+ EclipseNode existing = node.getNodeFor(def);
+ if (existing == null || !existing.isHandled()) return MemberExistsResult.EXISTS_BY_USER;
return MemberExistsResult.EXISTS_BY_LOMBOK;
}
}
@@ -138,18 +137,18 @@ class PKG {
return MemberExistsResult.NOT_EXISTS;
}
- static MemberExistsResult constructorExists(EclipseAST.Node node) {
- while ( node != null && !(node.get() instanceof TypeDeclaration) ) {
+ static MemberExistsResult constructorExists(EclipseNode node) {
+ while (node != null && !(node.get() instanceof TypeDeclaration)) {
node = node.up();
}
- if ( node != null && node.get() instanceof TypeDeclaration ) {
+ if (node != null && node.get() instanceof TypeDeclaration) {
TypeDeclaration typeDecl = (TypeDeclaration)node.get();
- if ( typeDecl.methods != null ) for ( AbstractMethodDeclaration def : typeDecl.methods ) {
- if ( def instanceof ConstructorDeclaration ) {
- if ( (def.bits & ASTNode.IsDefaultConstructor) != 0 ) continue;
- EclipseAST.Node existing = node.getNodeFor(def);
- if ( existing == null || !existing.isHandled() ) return MemberExistsResult.EXISTS_BY_USER;
+ if (typeDecl.methods != null) for (AbstractMethodDeclaration def : typeDecl.methods) {
+ if (def instanceof ConstructorDeclaration) {
+ if ((def.bits & ASTNode.IsDefaultConstructor) != 0) continue;
+ EclipseNode existing = node.getNodeFor(def);
+ if (existing == null || !existing.isHandled()) return MemberExistsResult.EXISTS_BY_USER;
return MemberExistsResult.EXISTS_BY_LOMBOK;
}
}
@@ -158,17 +157,17 @@ class PKG {
return MemberExistsResult.NOT_EXISTS;
}
- static EclipseAST.Node getExistingLombokConstructor(EclipseAST.Node node) {
- while ( node != null && !(node.get() instanceof TypeDeclaration) ) {
+ static EclipseNode getExistingLombokConstructor(EclipseNode node) {
+ while (node != null && !(node.get() instanceof TypeDeclaration)) {
node = node.up();
}
- if ( node.get() instanceof TypeDeclaration ) {
- for ( AbstractMethodDeclaration def : ((TypeDeclaration)node.get()).methods ) {
- if ( def instanceof ConstructorDeclaration ) {
- if ( (def.bits & ASTNode.IsDefaultConstructor) != 0 ) continue;
- EclipseAST.Node existing = node.getNodeFor(def);
- if ( existing.isHandled() ) return existing;
+ if (node.get() instanceof TypeDeclaration) {
+ for (AbstractMethodDeclaration def : ((TypeDeclaration)node.get()).methods) {
+ if (def instanceof ConstructorDeclaration) {
+ if ((def.bits & ASTNode.IsDefaultConstructor) != 0) continue;
+ EclipseNode existing = node.getNodeFor(def);
+ if (existing.isHandled()) return existing;
}
}
}
@@ -176,18 +175,18 @@ class PKG {
return null;
}
- static EclipseAST.Node getExistingLombokMethod(String methodName, EclipseAST.Node node) {
- while ( node != null && !(node.get() instanceof TypeDeclaration) ) {
+ static EclipseNode getExistingLombokMethod(String methodName, EclipseNode node) {
+ while (node != null && !(node.get() instanceof TypeDeclaration)) {
node = node.up();
}
- if ( node.get() instanceof TypeDeclaration ) {
- for ( AbstractMethodDeclaration def : ((TypeDeclaration)node.get()).methods ) {
+ if (node.get() instanceof TypeDeclaration) {
+ for (AbstractMethodDeclaration def : ((TypeDeclaration)node.get()).methods) {
char[] mName = def.selector;
- if ( mName == null ) continue;
- if ( methodName.equals(new String(mName)) ) {
- EclipseAST.Node existing = node.getNodeFor(def);
- if ( existing.isHandled() ) return existing;
+ if (mName == null) continue;
+ if (methodName.equals(new String(mName))) {
+ EclipseNode existing = node.getNodeFor(def);
+ if (existing.isHandled()) return existing;
}
}
}
@@ -195,10 +194,10 @@ class PKG {
return null;
}
- static void injectField(EclipseAST.Node type, FieldDeclaration field) {
+ static void injectField(EclipseNode type, FieldDeclaration field) {
TypeDeclaration parent = (TypeDeclaration) type.get();
- if ( parent.fields == null ) {
+ if (parent.fields == null) {
parent.fields = new FieldDeclaration[1];
parent.fields[0] = field;
} else {
@@ -211,27 +210,27 @@ class PKG {
type.add(field, Kind.FIELD).recursiveSetHandled();
}
- static void injectMethod(EclipseAST.Node type, AbstractMethodDeclaration method) {
+ static void injectMethod(EclipseNode type, AbstractMethodDeclaration method) {
TypeDeclaration parent = (TypeDeclaration) type.get();
- if ( parent.methods == null ) {
+ if (parent.methods == null) {
parent.methods = new AbstractMethodDeclaration[1];
parent.methods[0] = method;
} else {
boolean injectionComplete = false;
- if ( method instanceof ConstructorDeclaration ) {
- for ( int i = 0 ; i < parent.methods.length ; i++ ) {
- if ( parent.methods[i] instanceof ConstructorDeclaration &&
- (parent.methods[i].bits & ASTNode.IsDefaultConstructor) != 0 ) {
- EclipseAST.Node tossMe = type.getNodeFor(parent.methods[i]);
+ if (method instanceof ConstructorDeclaration) {
+ for (int i = 0 ; i < parent.methods.length ; i++) {
+ if (parent.methods[i] instanceof ConstructorDeclaration &&
+ (parent.methods[i].bits & ASTNode.IsDefaultConstructor) != 0) {
+ EclipseNode tossMe = type.getNodeFor(parent.methods[i]);
parent.methods[i] = method;
- if ( tossMe != null ) tossMe.up().removeChild(tossMe);
+ if (tossMe != null) tossMe.up().removeChild(tossMe);
injectionComplete = true;
break;
}
}
}
- if ( !injectionComplete ) {
+ if (!injectionComplete) {
AbstractMethodDeclaration[] newArray = new AbstractMethodDeclaration[parent.methods.length + 1];
System.arraycopy(parent.methods, 0, newArray, 0, parent.methods.length);
newArray[parent.methods.length] = method;
@@ -244,13 +243,13 @@ class PKG {
static Annotation[] findAnnotations(FieldDeclaration field, Pattern namePattern) {
List<Annotation> result = new ArrayList<Annotation>();
- if ( field.annotations == null ) return new Annotation[0];
+ if (field.annotations == null) return new Annotation[0];
for (Annotation annotation : field.annotations) {
TypeReference typeRef = annotation.type;
- if ( typeRef != null && typeRef.getTypeName()!= null ) {
+ if (typeRef != null && typeRef.getTypeName()!= null) {
char[][] typeName = typeRef.getTypeName();
String suspect = new String(typeName[typeName.length - 1]);
- if ( namePattern.matcher(suspect).matches() ) {
+ if (namePattern.matcher(suspect).matches()) {
result.add(annotation);
}
}
@@ -294,24 +293,24 @@ class PKG {
return ann;
}
- static List<Integer> createListOfNonExistentFields(List<String> list, Node type, boolean excludeStandard, boolean excludeTransient) {
+ static List<Integer> createListOfNonExistentFields(List<String> list, EclipseNode type, boolean excludeStandard, boolean excludeTransient) {
boolean[] matched = new boolean[list.size()];
- for ( Node child : type.down() ) {
- if ( list.isEmpty() ) break;
- if ( child.getKind() != Kind.FIELD ) continue;
- if ( excludeStandard ) {
- if ( (((FieldDeclaration)child.get()).modifiers & ClassFileConstants.AccStatic) != 0 ) continue;
- if ( child.getName().startsWith("$") ) continue;
+ for (EclipseNode child : type.down()) {
+ if (list.isEmpty()) break;
+ if (child.getKind() != Kind.FIELD) continue;
+ if (excludeStandard) {
+ if ((((FieldDeclaration)child.get()).modifiers & ClassFileConstants.AccStatic) != 0) continue;
+ if (child.getName().startsWith("$")) continue;
}
- if ( excludeTransient && (((FieldDeclaration)child.get()).modifiers & ClassFileConstants.AccTransient) != 0 ) continue;
+ if (excludeTransient && (((FieldDeclaration)child.get()).modifiers & ClassFileConstants.AccTransient) != 0) continue;
int idx = list.indexOf(child.getName());
- if ( idx > -1 ) matched[idx] = true;
+ if (idx > -1) matched[idx] = true;
}
List<Integer> problematic = new ArrayList<Integer>();
- for ( int i = 0 ; i < list.size() ; i++ ) {
- if ( !matched[i] ) problematic.add(i);
+ for (int i = 0 ; i < list.size() ; i++) {
+ if (!matched[i]) problematic.add(i);
}
return problematic;