generation of API for boolean names fixed
This commit is contained in:
parent
e39b8f5625
commit
83f5f01bdd
|
|
@ -21,6 +21,8 @@ abstract class SchemeObject {
|
||||||
abstract void readLine(String line, Map<String, SchemeObject> objects)
|
abstract void readLine(String line, Map<String, SchemeObject> objects)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//TODO: constructor
|
||||||
|
//TODO: YAML
|
||||||
//TODO: datetime
|
//TODO: datetime
|
||||||
//TODO: missable in future
|
//TODO: missable in future
|
||||||
//TODO: register all maps/collections classes and work with java typical types
|
//TODO: register all maps/collections classes and work with java typical types
|
||||||
|
|
@ -322,8 +324,29 @@ class FieldInfo {
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean checkNameStartsWith(String name, String prefix) {
|
||||||
|
return name.length() > prefix.length() && name.startsWith(prefix) && name.charAt(prefix.length()).isUpperCase()
|
||||||
|
}
|
||||||
|
|
||||||
|
String getGetterPrefix(String name) {
|
||||||
|
if (fieldType != FieldType.BOOLEAN) {
|
||||||
|
return "get"
|
||||||
|
}
|
||||||
|
if (checkNameStartsWith(name, "is")) {
|
||||||
|
return "is"
|
||||||
|
} else if (checkNameStartsWith(name, "has")) {
|
||||||
|
return "has"
|
||||||
|
} else if (checkNameStartsWith(name, "have")) {
|
||||||
|
return "have"
|
||||||
|
}
|
||||||
|
return "get"
|
||||||
|
}
|
||||||
|
|
||||||
MethodSpec createGetter(String name) {
|
MethodSpec createGetter(String name) {
|
||||||
final MethodSpec.Builder builder = MethodSpec.methodBuilder("get" + upperStartName(name))
|
String getterPrefix = getGetterPrefix(name);
|
||||||
|
final MethodSpec.Builder builder = MethodSpec.methodBuilder(getterPrefix.equals("get")
|
||||||
|
? getterPrefix + upperStartName(name)
|
||||||
|
: getterPrefix + upperStartName(name.substring(getterPrefix.length())))
|
||||||
.returns(typeName)
|
.returns(typeName)
|
||||||
.addModifiers(Modifier.PUBLIC)
|
.addModifiers(Modifier.PUBLIC)
|
||||||
if (!typeName.isPrimitive()) {
|
if (!typeName.isPrimitive()) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue