use of com.squareup.javapoet.TypeName in project microservice_framework by CJSCommonPlatform.
the class EventListenerInterceptorChainProviderCodeGenerator method createInterceptorChainEntriesMapField.
private FieldSpec createInterceptorChainEntriesMapField() {
final ClassName list = get("java.util", "List");
final ClassName arrayList = get("java.util", "ArrayList");
final TypeName listOfInterceptorChainEntries = ParameterizedTypeName.get(list, get(InterceptorChainEntry.class));
final TypeName arrayListOfInterceptorChainEntries = ParameterizedTypeName.get(arrayList, get(InterceptorChainEntry.class));
return FieldSpec.builder(listOfInterceptorChainEntries, "interceptorChainEntries", PRIVATE, FINAL).initializer("new $T()", arrayListOfInterceptorChainEntries).build();
}
use of com.squareup.javapoet.TypeName in project glide by bumptech.
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(ParameterSpec.builder(classOfTranscodeType, "transcodeClass").addAnnotation(nonNull()).build()).addParameter(ParameterSpec.builder(requestBuilderOfWildcardOfObject, "other").addAnnotation(nonNull()).build()).addStatement("super($N, $N)", "transcodeClass", "other").build();
ClassName context = ClassName.get("android.content", "Context");
ClassName glide = ClassName.get("com.bumptech.glide", "Glide");
ClassName requestManager = ClassName.get("com.bumptech.glide", "RequestManager");
MethodSpec secondConstructor = MethodSpec.constructorBuilder().addParameter(ParameterSpec.builder(glide, "glide").addAnnotation(nonNull()).build()).addParameter(ParameterSpec.builder(requestManager, "requestManager").addAnnotation(nonNull()).build()).addParameter(ParameterSpec.builder(classOfTranscodeType, "transcodeClass").addAnnotation(nonNull()).build()).addParameter(ParameterSpec.builder(context, "context").addAnnotation(nonNull()).build()).addStatement("super($N, $N ,$N, $N)", "glide", "requestManager", "transcodeClass", "context").build();
return ImmutableList.of(firstConstructor, secondConstructor);
}
use of com.squareup.javapoet.TypeName in project glide by bumptech.
the class ProcessorUtil method getJavadocSafeName.
/**
* Returns a safe String to use in a Javadoc that will function in a link.
*
* <p>This method exists because by Javadoc doesn't handle type parameters({@literal <T>}
* in {@literal RequestOptions<T>} for example).
*/
private TypeName getJavadocSafeName(Element element) {
Types typeUtils = processingEnv.getTypeUtils();
TypeMirror type = element.asType();
if (typeUtils.asElement(type) == null) {
// If there is no Element, it's a primitive and can't have additional types, so we're done.
return ClassName.get(element.asType());
}
Name simpleName = typeUtils.asElement(type).getSimpleName();
return ClassName.bestGuess(simpleName.toString());
}
use of com.squareup.javapoet.TypeName in project arez by arez.
the class ActionDescriptor method buildAction.
/**
* Generate the action wrapper.
*/
@Nonnull
private MethodSpec buildAction() throws ArezProcessorException {
final MethodSpec.Builder builder = MethodSpec.methodBuilder(_action.getSimpleName().toString());
ProcessorUtil.copyAccessModifiers(_action, builder);
ProcessorUtil.copyExceptions(_actionType, builder);
ProcessorUtil.copyTypeParameters(_actionType, builder);
ProcessorUtil.copyDocumentedAnnotations(_action, builder);
builder.addAnnotation(Override.class);
final TypeMirror returnType = _actionType.getReturnType();
builder.returns(TypeName.get(returnType));
final boolean isProcedure = returnType.getKind() == TypeKind.VOID;
final List<? extends TypeMirror> thrownTypes = _action.getThrownTypes();
final boolean isSafe = thrownTypes.isEmpty();
final StringBuilder statement = new StringBuilder();
final ArrayList<Object> parameterNames = new ArrayList<>();
if (!isProcedure) {
statement.append("return ");
}
statement.append("$N().");
parameterNames.add(_componentDescriptor.getContextMethodName());
if (isProcedure && isSafe) {
statement.append("safeAction");
} else if (isProcedure) {
statement.append("action");
} else if (isSafe) {
statement.append("safeAction");
} else {
statement.append("action");
}
statement.append("(");
statement.append("$T.areNamesEnabled() ? $N() + $S : null");
parameterNames.add(GeneratorUtil.AREZ_CLASSNAME);
parameterNames.add(_componentDescriptor.getComponentNameMethodName());
parameterNames.add("." + getName());
statement.append(", ");
statement.append(_mutation);
statement.append(", () -> super.");
statement.append(_action.getSimpleName());
statement.append("(");
boolean firstParam = true;
final List<? extends VariableElement> parameters = _action.getParameters();
final int paramCount = parameters.size();
for (int i = 0; i < paramCount; i++) {
final VariableElement element = parameters.get(i);
final TypeName parameterType = TypeName.get(_actionType.getParameterTypes().get(i));
final ParameterSpec.Builder param = ParameterSpec.builder(parameterType, element.getSimpleName().toString(), Modifier.FINAL);
ProcessorUtil.copyDocumentedAnnotations(element, param);
builder.addParameter(param.build());
parameterNames.add(element.getSimpleName().toString());
if (!firstParam) {
statement.append(",");
}
firstParam = false;
statement.append("$N");
}
statement.append(")");
if (_reportParameters) {
for (final VariableElement parameter : parameters) {
parameterNames.add(parameter.getSimpleName().toString());
statement.append(", $N");
}
}
statement.append(" )");
GeneratorUtil.generateNotDisposedInvariant(_componentDescriptor, builder);
GeneratorUtil.generateTryBlock(builder, thrownTypes, b -> b.addStatement(statement.toString(), parameterNames.toArray()));
return builder.build();
}
use of com.squareup.javapoet.TypeName in project arez by arez.
the class ComponentDescriptor method buildGetByIdMethod.
@Nonnull
private MethodSpec buildGetByIdMethod() {
final TypeName entityType = TypeName.get(getElement().asType());
final MethodSpec.Builder method = MethodSpec.methodBuilder("getBy" + getIdName()).addModifiers(Modifier.FINAL).addAnnotation(GeneratorUtil.NONNULL_CLASSNAME).addParameter(ParameterSpec.builder(getIdType(), "id", Modifier.FINAL).build()).returns(entityType).addStatement("return getByArezId( id )");
ProcessorUtil.copyAccessModifiers(getElement(), method);
return method.build();
}
Aggregations