mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 12:16:49 +00:00
Improving on the structure a little.
This commit is contained in:
1 parent
1677c4a52a
commit
9314db916d
3 files changed
+28
-12
No files matched your search
@@ -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());
|
||||
|
||||
+6
-12
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user