diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2013-06-16 10:54:33 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2013-06-16 13:20:54 +0200 |
commit | 359b7845f21ac7ad023ce1a13af8f6b5d1833068 (patch) | |
tree | 9eeae95b9c89dc7a226e0703cad977bb841cd6cf /src/core/lombok/eclipse | |
parent | 9066d57ed9073cd99d664b2676d6fde54af1a7b6 (diff) | |
download | lombok-359b7845f21ac7ad023ce1a13af8f6b5d1833068.tar.gz lombok-359b7845f21ac7ad023ce1a13af8f6b5d1833068.tar.bz2 lombok-359b7845f21ac7ad023ce1a13af8f6b5d1833068.zip |
Most of the javac implementation for HandleBuilder, plus
some minor updates and refactoring in the eclipse HandleBuilder.
Diffstat (limited to 'src/core/lombok/eclipse')
-rw-r--r-- | src/core/lombok/eclipse/handlers/HandleBuilder.java | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index 929168da..d15f00e6 100644 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -22,6 +22,7 @@ package lombok.eclipse.handlers; import static lombok.eclipse.Eclipse.*; +import static lombok.core.handlers.HandlerUtil.*; import static lombok.eclipse.handlers.EclipseHandlerUtil.*; import java.util.ArrayList; @@ -57,7 +58,6 @@ import org.mangosdk.spi.ProviderFor; import lombok.AccessLevel; import lombok.core.AST.Kind; import lombok.core.AnnotationValues; -import lombok.core.JavaIdentifiers; import lombok.eclipse.Eclipse; import lombok.eclipse.EclipseAnnotationHandler; import lombok.eclipse.EclipseNode; @@ -78,9 +78,11 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { if (buildMethodName == null) builderMethodName = "build"; if (builderClassName == null) builderClassName = ""; - checkName("builderMethodName", builderMethodName, annotationNode); - checkName("buildMethodName", buildMethodName, annotationNode); - if (!builderClassName.isEmpty()) checkName("builderClassName", builderClassName, annotationNode); + if (checkName("builderMethodName", builderMethodName, annotationNode)) return; + if (!checkName("buildMethodName", buildMethodName, annotationNode)) return; + if (!builderClassName.isEmpty()) { + if (!checkName("builderClassName", builderClassName, annotationNode)) return; + } EclipseNode parent = annotationNode.up(); @@ -97,9 +99,9 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { if (parent.get() instanceof TypeDeclaration) { tdParent = parent; TypeDeclaration td = (TypeDeclaration) tdParent.get(); - new HandleConstructor().generateAllArgsConstructor(parent, AccessLevel.PRIVATE, null, SkipIfConstructorExists.I_AM_BUILDER, Collections.<Annotation>emptyList(), ast); + new HandleConstructor().generateAllArgsConstructor(tdParent, AccessLevel.PRIVATE, null, SkipIfConstructorExists.I_AM_BUILDER, Collections.<Annotation>emptyList(), ast); - for (EclipseNode fieldNode : HandleConstructor.findAllFields(parent)) { + for (EclipseNode fieldNode : HandleConstructor.findAllFields(tdParent)) { FieldDeclaration fd = (FieldDeclaration) fieldNode.get(); namesOfParameters.add(fd.name); typesOfParameters.add(fd.type); @@ -202,9 +204,6 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { MethodDeclaration md = generateBuilderMethod(builderMethodName, builderClassName, tdParent, typeParams, ast); if (md != null) injectMethod(tdParent, md); } - - - // create builder method in parent. } private MethodDeclaration generateBuilderMethod(String builderMethodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, ASTNode source) { @@ -349,16 +348,4 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { builder.traverse(new SetGeneratedByVisitor(source), (ClassScope) null); return injectType(tdParent, builder); } - - private static void checkName(String nameSpec, String identifier, EclipseNode annotationNode) { - if (identifier.isEmpty()) { - annotationNode.addError(nameSpec + " cannot be the empty string."); - return; - } - - if (!JavaIdentifiers.isValidJavaIdentifier(identifier)) { - annotationNode.addError(nameSpec + " must be a valid java identifier."); - return; - } - } } |