use of com.squareup.javapoet.MethodSpec.Builder in project glide by bumptech.
the class GlideGenerator method overrideGlideStaticMethod.
private MethodSpec overrideGlideStaticMethod(ExecutableElement methodToOverride) {
List<ParameterSpec> parameters = ProcessorUtil.getParameters(methodToOverride);
TypeElement element = (TypeElement) processingEnv.getTypeUtils().asElement(methodToOverride.getReturnType());
MethodSpec.Builder builder = MethodSpec.methodBuilder(methodToOverride.getSimpleName().toString()).addModifiers(Modifier.PUBLIC, Modifier.STATIC).addJavadoc(processorUtil.generateSeeMethodJavadoc(methodToOverride)).addParameters(parameters);
addReturnAnnotations(builder, methodToOverride);
boolean returnsValue = element != null;
if (returnsValue) {
builder.returns(ClassName.get(element));
}
StringBuilder code = new StringBuilder(returnsValue ? "return " : "");
code.append("$T.$N(");
List<Object> args = new ArrayList<>();
args.add(ClassName.get(glideType));
args.add(methodToOverride.getSimpleName());
if (!parameters.isEmpty()) {
for (ParameterSpec param : parameters) {
code.append("$L, ");
args.add(param.name);
}
code = new StringBuilder(code.substring(0, code.length() - 2));
}
code.append(")");
builder.addStatement(code.toString(), args.toArray(new Object[0]));
return builder.build();
}
use of com.squareup.javapoet.MethodSpec.Builder in project glide by bumptech.
the class RequestManagerGenerator method generateRequestManagerRequestManagerMethodOverride.
private MethodSpec generateRequestManagerRequestManagerMethodOverride(String generatedPackageName, ExecutableElement method) {
ClassName generatedRequestManagerName = ClassName.get(generatedPackageName, GENERATED_REQUEST_MANAGER_SIMPLE_NAME);
Builder returns = ProcessorUtil.overriding(method).addAnnotation(nonNull()).returns(generatedRequestManagerName);
return returns.addCode(ProcessorUtil.generateCastingSuperCall(generatedRequestManagerName, returns.build())).build();
}
use of com.squareup.javapoet.MethodSpec.Builder in project epoxy by airbnb.
the class EpoxyProcessor method generateHashCode.
private MethodSpec generateHashCode(ClassToGenerateInfo helperClass) {
Builder builder = MethodSpec.methodBuilder("hashCode").addAnnotation(Override.class).addModifiers(Modifier.PUBLIC).returns(int.class).addStatement("int result = super.hashCode()");
for (AttributeInfo attributeInfo : helperClass.getAttributeInfo()) {
if (!attributeInfo.useInHash()) {
continue;
}
if (attributeInfo.getType() == DOUBLE) {
builder.addStatement("long temp");
break;
}
}
for (AttributeInfo attributeInfo : helperClass.getAttributeInfo()) {
TypeName type = attributeInfo.getType();
if (!attributeInfo.useInHash() && type.isPrimitive()) {
continue;
}
String name = attributeInfo.getName();
if (attributeInfo.useInHash()) {
if ((type == BYTE) || (type == CHAR) || (type == SHORT) || (type == INT)) {
builder.addStatement("result = 31 * result + $L", name);
} else if (type == LONG) {
builder.addStatement("result = 31 * result + (int) ($L ^ ($L >>> 32))", name, name);
} else if (type == FLOAT) {
builder.addStatement("result = 31 * result + ($L != +0.0f " + "? Float.floatToIntBits($L) : 0)", name, name);
} else if (type == DOUBLE) {
builder.addStatement("temp = Double.doubleToLongBits($L)", name).addStatement("result = 31 * result + (int) (temp ^ (temp >>> 32))");
} else if (type == BOOLEAN) {
builder.addStatement("result = 31 * result + ($L ? 1 : 0)", name);
} else if (type instanceof ArrayTypeName) {
builder.addStatement("result = 31 * result + Arrays.hashCode($L)", name);
} else {
builder.addStatement("result = 31 * result + ($L != null ? $L.hashCode() : 0)", name, name);
}
} else {
builder.addStatement("result = 31 * result + ($L != null ? 1 : 0)", name);
}
}
return builder.addStatement("return result").build();
}
use of com.squareup.javapoet.MethodSpec.Builder in project epoxy by airbnb.
the class EpoxyProcessor method generateSetter.
private MethodSpec generateSetter(ClassToGenerateInfo helperClass, AttributeInfo data) {
String attributeName = data.getName();
Builder builder = MethodSpec.methodBuilder(attributeName).addModifiers(Modifier.PUBLIC).returns(helperClass.getParameterizedGeneratedName()).addParameter(ParameterSpec.builder(data.getType(), attributeName).addAnnotations(data.getSetterAnnotations()).build()).addStatement("this.$L = $L", attributeName, attributeName);
if (data.hasSuperSetterMethod()) {
builder.addStatement("super.$L($L)", attributeName, attributeName);
}
return builder.addStatement("return this").build();
}
use of com.squareup.javapoet.MethodSpec.Builder in project microservice_framework by CJSCommonPlatform.
the class ActionNameToMediaTypesMapperClassBuilder method constructor.
private MethodSpec constructor(final List<ActionNameMapping> actionNameMappings) {
final Builder builder = constructorBuilder().addModifiers(PUBLIC);
actionNameMappings.forEach(actionNameMapping -> addStatement(builder, actionNameMapping));
return builder.build();
}
Aggregations