diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-06-08 22:50:51 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-06-08 22:50:51 +0200 |
commit | 9314db916d13c3642b60f3aad25d765e182a198c (patch) | |
tree | 32f985c9bd9c43f34693903a72b7087856689577 | |
parent | 1677c4a52a0aea1b955f7c2c7d096903d4a8c5ce (diff) | |
download | lombok-9314db916d13c3642b60f3aad25d765e182a198c.tar.gz lombok-9314db916d13c3642b60f3aad25d765e182a198c.tar.bz2 lombok-9314db916d13c3642b60f3aad25d765e182a198c.zip |
Improving on the structure a little.
-rw-r--r-- | src/lombok/apt/HandleGetter_javac.java | 4 | ||||
-rw-r--r-- | src/lombok/apt/PKG.java | 18 | ||||
-rw-r--r-- | src/lombok/transformations/TransformationsUtil.java | 18 |
3 files changed, 28 insertions, 12 deletions
diff --git a/src/lombok/apt/HandleGetter_javac.java b/src/lombok/apt/HandleGetter_javac.java index 8432e7b0..d726867c 100644 --- a/src/lombok/apt/HandleGetter_javac.java +++ b/src/lombok/apt/HandleGetter_javac.java @@ -60,6 +60,10 @@ class HandleGetter_javac extends HandlerForCompiler<Getter> { private MethodTree createGetter(Element field, TreeMaker treeMaker, Name.Table nameTable) { JCStatement returnStatement = treeMaker.Return(treeMaker.Ident((Symbol)field)); + + //TODO Trab the position in the source file of the field by looking it up in the JCClassDecl, + //and copy it into the 'position' info for the Ident and Return AST Nodes. + JCBlock methodBody = treeMaker.Block(0, List.of(returnStatement)); Name methodName = Name.fromString(nameTable, PKG.toGetterName(field)); JCExpression methodType = treeMaker.Type((Type)field.asType()); diff --git a/src/lombok/apt/PKG.java b/src/lombok/apt/PKG.java index cfedf83b..bbe13379 100644 --- a/src/lombok/apt/PKG.java +++ b/src/lombok/apt/PKG.java @@ -8,6 +8,7 @@ import javax.lang.model.element.Element; import javax.lang.model.type.TypeKind; import lombok.Lombok; +import lombok.transformations.TransformationsUtil; class PKG { @@ -48,20 +49,13 @@ class PKG { } } - static String toGetterName(Element element) { - CharSequence fieldName = element.getSimpleName(); - if ( fieldName.length() == 0 ) return "get"; + static String toGetterName(Element field) { + CharSequence fieldName = field.getSimpleName(); - final String prefix, suffix; + boolean isBoolean = (field.asType().getKind() == TypeKind.BOOLEAN || + "java.lang.Boolean".equals(field.asType().toString())); - if ( element.asType().getKind() == TypeKind.BOOLEAN || "java.lang.Boolean".equals(element.asType().toString()) ) prefix = "is"; - else prefix = "get"; - - char first = fieldName.charAt(0); - if ( Character.isLowerCase(first) ) - suffix = String.format("%s%s", Character.toTitleCase(first), fieldName.subSequence(1, fieldName.length())); - else suffix = fieldName.toString(); - return String.format("%s%s", prefix, suffix); + return TransformationsUtil.toGetterName(fieldName, isBoolean); } static byte[] readStream(InputStream in) throws IOException { diff --git a/src/lombok/transformations/TransformationsUtil.java b/src/lombok/transformations/TransformationsUtil.java new file mode 100644 index 00000000..7869025a --- /dev/null +++ b/src/lombok/transformations/TransformationsUtil.java @@ -0,0 +1,18 @@ +package lombok.transformations; + +public class TransformationsUtil { + private TransformationsUtil() {} + + public static String toGetterName(CharSequence fieldName, boolean isBoolean) { + final String prefix = isBoolean ? "is" : "get"; + final String suffix; + + if ( fieldName.length() == 0 ) return prefix; + + char first = fieldName.charAt(0); + if ( Character.isLowerCase(first) ) + suffix = String.format("%s%s", Character.toTitleCase(first), fieldName.subSequence(1, fieldName.length())); + else suffix = fieldName.toString(); + return String.format("%s%s", prefix, suffix); + } +} |