Search in sources :

Example 26 with TypeName

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();
}
Also used : ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) TypeName(com.squareup.javapoet.TypeName) ClassName(com.squareup.javapoet.ClassName) InterceptorChainEntry(uk.gov.justice.services.core.interceptor.InterceptorChainEntry)

Example 27 with TypeName

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);
}
Also used : WildcardTypeName(com.squareup.javapoet.WildcardTypeName) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) TypeName(com.squareup.javapoet.TypeName) MethodSpec(com.squareup.javapoet.MethodSpec) ClassName(com.squareup.javapoet.ClassName) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName)

Example 28 with TypeName

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());
}
Also used : Types(javax.lang.model.util.Types) TypeMirror(javax.lang.model.type.TypeMirror) ClassName(com.squareup.javapoet.ClassName) TypeName(com.squareup.javapoet.TypeName) Name(javax.lang.model.element.Name) TypeVariableName(com.squareup.javapoet.TypeVariableName)

Example 29 with TypeName

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();
}
Also used : TypeName(com.squareup.javapoet.TypeName) MethodSpec(com.squareup.javapoet.MethodSpec) ParameterSpec(com.squareup.javapoet.ParameterSpec) ArrayList(java.util.ArrayList) VariableElement(javax.lang.model.element.VariableElement) TypeMirror(javax.lang.model.type.TypeMirror) Nonnull(javax.annotation.Nonnull)

Example 30 with TypeName

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();
}
Also used : ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) TypeName(com.squareup.javapoet.TypeName) MethodSpec(com.squareup.javapoet.MethodSpec) Nonnull(javax.annotation.Nonnull)

Aggregations

TypeName (com.squareup.javapoet.TypeName)296 ParameterizedTypeName (com.squareup.javapoet.ParameterizedTypeName)232 MethodSpec (com.squareup.javapoet.MethodSpec)109 ClassName (com.squareup.javapoet.ClassName)82 WildcardTypeName (com.squareup.javapoet.WildcardTypeName)78 TypeSpec (com.squareup.javapoet.TypeSpec)55 ArrayTypeName (com.squareup.javapoet.ArrayTypeName)50 TypeElement (javax.lang.model.element.TypeElement)46 ArrayList (java.util.ArrayList)45 TypeMirror (javax.lang.model.type.TypeMirror)41 ExecutableElement (javax.lang.model.element.ExecutableElement)36 ParameterSpec (com.squareup.javapoet.ParameterSpec)26 Builder (com.squareup.javapoet.TypeSpec.Builder)22 SQLiteDaoDefinition (com.abubusoft.kripton.processor.sqlite.model.SQLiteDaoDefinition)21 CodeBlock (com.squareup.javapoet.CodeBlock)20 VariableElement (javax.lang.model.element.VariableElement)20 SQLiteEntity (com.abubusoft.kripton.processor.sqlite.model.SQLiteEntity)19 SQLProperty (com.abubusoft.kripton.processor.sqlite.model.SQLProperty)18 List (java.util.List)18 Map (java.util.Map)17