use of com.squareup.javapoet.ParameterizedTypeName in project kripton by xcesco.
the class SetPrefsTransformation method generateReadProperty.
@Override
public void generateReadProperty(Builder methodBuilder, String preferenceName, TypeName beanClass, String beanName, PrefsProperty property, boolean readAll) {
boolean isStringSet = isStringSet(property);
String tempPre = "";
String tempPost = "";
String tempPreDefaultValue = "";
String tempPostDefaultValue = "";
if (readAll) {
methodBuilder.beginControlFlow("");
}
if (property.hasTypeAdapter()) {
// this comment is needed to include $T for PrefsTypeAdapterUtils
methodBuilder.addComment("Use $T to convert objects", PrefsTypeAdapterUtils.class);
tempPre = String.format("%s.getAdapter(%s.class).toJava(", PrefsTypeAdapterUtils.class.getSimpleName(), TypeUtility.className(property.typeAdapter.adapterClazz).simpleName());
tempPost = ")";
tempPreDefaultValue = String.format("%s.getAdapter(%s.class).toData(", PrefsTypeAdapterUtils.class.getSimpleName(), TypeUtility.className(property.typeAdapter.adapterClazz).simpleName());
tempPostDefaultValue = ")";
}
if (isStringSet) {
methodBuilder.addStatement("$T<String> temp=$L.getStringSet($S, " + tempPreDefaultValue + "defaultBean." + getter(beanClass, property) + tempPostDefaultValue + ")", Set.class, preferenceName, property.getPreferenceKey());
if (readAll) {
methodBuilder.addCode("$L." + setter(beanClass, property) + (!property.isPublicField() ? "(" : "=") + "", beanName);
} else {
methodBuilder.addCode("return ");
}
methodBuilder.addCode(tempPre);
ParameterizedTypeName typeName;
if (property.hasTypeAdapter()) {
typeName = (ParameterizedTypeName) TypeUtility.typeName(property.typeAdapter.dataType);
} else {
typeName = (ParameterizedTypeName) TypeUtility.typeName(property.getElement().asType());
}
if (TypeUtility.isEquals(typeName.rawType, Set.class.getCanonicalName())) {
methodBuilder.addCode("temp");
} else {
methodBuilder.addCode("new $T<String>(temp)", typeName.rawType);
}
methodBuilder.addCode(tempPost);
if (readAll) {
methodBuilder.addCode((!property.isPublicField() ? ")" : ""));
}
methodBuilder.addCode(";\n");
} else {
methodBuilder.addStatement("String temp=$L.getString($S, null)", preferenceName, property.getPreferenceKey());
if (readAll) {
methodBuilder.addCode("$L." + setter(beanClass, property) + (!property.isPublicField() ? "(" : "=") + "", beanName);
} else {
methodBuilder.addCode("return ");
}
methodBuilder.addCode("$T.hasText(temp) ? ", StringUtils.class);
methodBuilder.addCode("parse$L(temp)", formatter.convert(property.getName()));
methodBuilder.addCode(": null");
if (readAll) {
methodBuilder.addCode((!property.isPublicField() ? ")" : ""));
}
methodBuilder.addCode(";\n");
}
if (readAll) {
methodBuilder.endControlFlow();
}
}
use of com.squareup.javapoet.ParameterizedTypeName in project AndroidLife by CaMnter.
the class FieldCollectionViewBinding method render.
/**
* 为 @BindViews 生成代码块
*
* @return CodeBlock
*/
CodeBlock render() {
CodeBlock.Builder builder = CodeBlock.builder().add("target.$L = $T.$L(", name, UTILS, kind.factoryName);
for (int i = 0; i < ids.size(); i++) {
if (i > 0) {
builder.add(", ");
}
builder.add("\n");
boolean requiresCast = requiresCast(type);
if (!requiresCast && !required) {
builder.add("source.findViewById($L)", ids.get(i).code);
} else {
builder.add("$T.find", UTILS);
builder.add(required ? "RequiredView" : "OptionalView");
if (requiresCast) {
builder.add("AsType");
}
builder.add("(source, $L, \"field '$L'\"", ids.get(i).code, name);
if (requiresCast) {
TypeName rawType = type;
if (rawType instanceof ParameterizedTypeName) {
rawType = ((ParameterizedTypeName) rawType).rawType;
}
builder.add(", $T.class", rawType);
}
builder.add(")");
}
}
return builder.add(")").build();
}
use of com.squareup.javapoet.ParameterizedTypeName in project Rocket by mozilla-tw.
the class RequestBuilderGenerator method generateConstructors.
private List<MethodSpec> generateConstructors() {
ParameterizedTypeName classOfTranscodeType = ParameterizedTypeName.get(ClassName.get(Class.class), transcodeTypeName);
TypeName wildcardOfObject = WildcardTypeName.subtypeOf(Object.class);
ParameterizedTypeName requestBuilderOfWildcardOfObject = ParameterizedTypeName.get(ClassName.get(requestBuilderType), wildcardOfObject);
MethodSpec firstConstructor = MethodSpec.constructorBuilder().addParameter(classOfTranscodeType, "transcodeClass").addParameter(requestBuilderOfWildcardOfObject, "other").addStatement("super($N, $N)", "transcodeClass", "other").build();
ClassName glide = ClassName.get("com.bumptech.glide", "Glide");
ClassName requestManager = ClassName.get("com.bumptech.glide", "RequestManager");
MethodSpec secondConstructor = MethodSpec.constructorBuilder().addParameter(glide, "glide").addParameter(requestManager, "requestManager").addParameter(classOfTranscodeType, "transcodeClass").addStatement("super($N, $N ,$N)", "glide", "requestManager", "transcodeClass").build();
return ImmutableList.of(firstConstructor, secondConstructor);
}
use of com.squareup.javapoet.ParameterizedTypeName in project Rocket by mozilla-tw.
the class RequestManagerGenerator method generateAsMethod.
private MethodSpec generateAsMethod(String generatedCodePackageName, TypeSpec requestBuilder) {
TypeVariableName resourceType = TypeVariableName.get("ResourceType");
ParameterizedTypeName classOfResouceType = ParameterizedTypeName.get(ClassName.get(Class.class), resourceType);
ClassName generatedRequestBuilderClassName = ClassName.get(generatedCodePackageName, requestBuilder.name);
ParameterizedTypeName requestBuilderOfResourceType = ParameterizedTypeName.get(generatedRequestBuilderClassName, resourceType);
return MethodSpec.methodBuilder("as").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).addTypeVariable(TypeVariableName.get("ResourceType")).addParameter(classOfResouceType, "resourceClass").returns(requestBuilderOfResourceType).addStatement("return new $T<>(glide, this, resourceClass)", this.generatedRequestBuilderClassName).build();
}
use of com.squareup.javapoet.ParameterizedTypeName in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapper method buildEventTransactionReceiptFunction.
static MethodSpec buildEventTransactionReceiptFunction(String responseClassName, String functionName, List<NamedTypeName> indexedParameters, List<NamedTypeName> nonIndexedParameters) throws ClassNotFoundException {
ParameterizedTypeName parameterizedTypeName = ParameterizedTypeName.get(ClassName.get(List.class), ClassName.get("", responseClassName));
String generatedFunctionName = "get" + Strings.capitaliseFirstLetter(functionName) + "Events";
MethodSpec.Builder transactionMethodBuilder = MethodSpec.methodBuilder(generatedFunctionName).addModifiers(Modifier.PUBLIC).addModifiers(Modifier.STATIC).addParameter(TransactionReceipt.class, "transactionReceipt").returns(parameterizedTypeName);
buildVariableLengthEventConstructor(transactionMethodBuilder, functionName, indexedParameters, nonIndexedParameters);
transactionMethodBuilder.addStatement("$T valueList = extractEventParameters(event, " + "transactionReceipt)", ParameterizedTypeName.get(List.class, EventValues.class)).addStatement("$1T responses = new $1T(valueList.size())", ParameterizedTypeName.get(ClassName.get(ArrayList.class), ClassName.get("", responseClassName))).beginControlFlow("for ($T eventValues : valueList)", EventValues.class).addStatement("$1T typedResponse = new $1T()", ClassName.get("", responseClassName)).addCode(buildTypedResponse("typedResponse", indexedParameters, nonIndexedParameters)).addStatement("responses.add(typedResponse)").endControlFlow();
transactionMethodBuilder.addStatement("return responses");
return transactionMethodBuilder.build();
}
Aggregations