use of com.squareup.javapoet.TypeName in project CoreData by FangCloud-Android.
the class CreateConvertStatement method createSerializableListField.
private static FieldSpec createSerializableListField(Element convertElement) {
TypeName typeName = ClassName.get(convertElement.asType());
if (typeName instanceof ParameterizedTypeName) {
List<TypeName> typeArguments = ((ParameterizedTypeName) typeName).typeArguments;
typeName = typeArguments.get(0);
}
ParameterizedTypeName parameterizedTypeName = ParameterizedTypeName.get(SERIALIZABLE_LIST_CLASS_NAME, typeName);
return FieldSpec.builder(parameterizedTypeName, Utils.converterName(convertElement, SERIALIZABLE_LIST_CLASS_NAME), Modifier.PRIVATE, Modifier.FINAL).initializer("new $T()", parameterizedTypeName).build();
}
use of com.squareup.javapoet.TypeName in project CoreData by FangCloud-Android.
the class Utils method methodGet.
public static String methodGet(Element element, String prefix) {
TypeName typeName = ClassName.get(element.asType());
String elementName = element.getSimpleName().toString();
Set<Modifier> modifiers = element.getModifiers();
StringBuilder sb = new StringBuilder();
if (!TextUtils.isEmpty(prefix)) {
sb.append(prefix);
sb.append(".");
}
if (modifiers.contains(Modifier.PUBLIC)) {
sb.append(elementName);
} else {
if (typeName == TypeName.BOOLEAN) {
if (elementName.startsWith("is")) {
return sb.append(element).append("()").toString();
} else {
sb.append("is");
}
} else {
sb.append("get");
}
sb.append(elementName.substring(0, 1).toUpperCase()).append(elementName.substring(1)).append("()");
}
return sb.toString();
}
use of com.squareup.javapoet.TypeName in project CoreData by FangCloud-Android.
the class Utils method methodSetFormat.
public static String methodSetFormat(Element element, String prefix) {
TypeName typeName = ClassName.get(element.asType());
String elementName = element.getSimpleName().toString();
Set<Modifier> modifiers = element.getModifiers();
StringBuilder sb = new StringBuilder();
if (!TextUtils.isEmpty(prefix)) {
sb.append(prefix).append(".");
}
if (modifiers.contains(Modifier.PUBLIC)) {
sb.append(elementName).append(" = $N");
} else {
sb.append("set");
if (typeName == TypeName.BOOLEAN && elementName.startsWith("is")) {
sb.append(elementName.substring(2));
} else {
sb.append(elementName.substring(0, 1).toUpperCase()).append(elementName.substring(1));
}
sb.append("($N)");
}
return sb.toString();
}
use of com.squareup.javapoet.TypeName in project CoreData by FangCloud-Android.
the class Utils method getProperties.
public static List<Property> getProperties(ProcessingEnvironment env, List<Element> elements, Element primaryKey) {
Elements elementUtils = env.getElementUtils();
Types typeUtils = env.getTypeUtils();
List<Property> propertyList = new ArrayList<>();
for (Element element : elements) {
String columnName = Utils.getColumnName(element);
TypeName dbBaseType;
TypeMirror typeMirror = element.asType();
TypeName typeNameElement = ClassName.get(typeMirror);
if (Utils.isBaseType(typeNameElement)) {
dbBaseType = typeNameElement;
} else {
TypeElement elementFieldType = (TypeElement) typeUtils.asElement(typeMirror);
Relation annotationRelation = element.getAnnotation(Relation.class);
if (annotationRelation != null) {
// 关联数据
Entity relationEntity = elementFieldType.getAnnotation(Entity.class);
if (relationEntity == null) {
throw new IllegalStateException("@Relation 添加的属性必须是 @Entity 的类");
}
EntityDetail relationEntityDetail = EntityDetail.parse(env, elementFieldType);
Element relationEntityPrimaryKey = relationEntityDetail.getPrimaryKey();
if (relationEntityPrimaryKey == null) {
throw new IllegalStateException(relationEntityDetail.getEntityName() + "是关联类型,@Relation 属性必须有主键");
}
dbBaseType = ClassName.get(relationEntityPrimaryKey.asType());
} else {
Embedded embedded = element.getAnnotation(Embedded.class);
if (embedded != null) {
// 内嵌数据, 循环解析内嵌结构的字段
List<Element> embeddedEleList = new ArrayList<>();
fillElementsForDbAndReturnPrimaryKey(env, embeddedEleList, (TypeElement) typeUtils.asElement(typeMirror));
propertyList.addAll(getProperties(env, embeddedEleList, null));
continue;
} else {
Convert convert = element.getAnnotation(Convert.class);
if (convert != null) {
TypeName classConvertDb = Utils.getConvertDbType(convert);
if (Utils.isBaseType(classConvertDb)) {
dbBaseType = classConvertDb;
} else {
throw new IllegalStateException(element.getSimpleName() + "converter dbtype is not a base type");
}
} else {
throw new IllegalStateException(element.getSimpleName() + " is a complex structure field," + "must indicate it as @Relation or @Embedded, " + "or supply a @Convert for it");
}
}
}
}
propertyList.add(new Property(columnName, Utils.getTypeByTypeName(dbBaseType), element == primaryKey));
}
return propertyList;
}
use of com.squareup.javapoet.TypeName in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapper method buildTypeName.
static TypeName buildTypeName(String typeDeclaration) {
String type = trimStorageDeclaration(typeDeclaration);
if (type.endsWith("]")) {
String[] splitType = type.split("\\[");
Class<?> baseType = AbiTypes.getType(splitType[0]);
TypeName typeName;
if (splitType[1].length() == 1) {
typeName = ParameterizedTypeName.get(DynamicArray.class, baseType);
} else {
// Unfortunately we can't encode it's length as a type
typeName = ParameterizedTypeName.get(StaticArray.class, baseType);
}
return typeName;
} else {
Class<?> cls = AbiTypes.getType(type);
return ClassName.get(cls);
}
}
Aggregations