Search in sources :

Example 76 with ClassName

use of com.squareup.javapoet.ClassName in project epoxy by airbnb.

the class ResourceProcessor method parseCompiledR.

private void parseCompiledR(TypeElement rClass, Map<Integer, AndroidResource> symbols) {
    for (Element element : rClass.getEnclosedElements()) {
        String innerClassName = element.getSimpleName().toString();
        if (SUPPORTED_TYPES.contains(innerClassName)) {
            for (Element enclosedElement : element.getEnclosedElements()) {
                if (enclosedElement instanceof VariableElement) {
                    VariableElement variableElement = (VariableElement) enclosedElement;
                    Object value = variableElement.getConstantValue();
                    if (value instanceof Integer) {
                        int id = (Integer) value;
                        ClassName rClassName = ClassName.get(elementUtils.getPackageOf(variableElement).toString(), "R", innerClassName);
                        String resourceName = variableElement.getSimpleName().toString();
                        symbols.put(id, new AndroidResource(id, rClassName, resourceName));
                    }
                }
            }
        }
    }
}
Also used : VariableElement(javax.lang.model.element.VariableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) ClassName(com.squareup.javapoet.ClassName) VariableElement(javax.lang.model.element.VariableElement)

Example 77 with ClassName

use of com.squareup.javapoet.ClassName in project RxCache by VictorAlbertos.

the class GetProvidersClass method from.

ProvidersClass from(Element element) throws ValidationException {
    if (!SuperficialValidation.validateElement(element))
        return null;
    if (element.getKind() != ElementKind.INTERFACE)
        return null;
    ClassName className = ClassName.get((TypeElement) element);
    List<ProvidersClass.Method> methods = getMethods(element);
    return new ProvidersClass(className, element, methods);
}
Also used : ClassName(com.squareup.javapoet.ClassName)

Example 78 with ClassName

use of com.squareup.javapoet.ClassName in project storio by pushtorefresh.

the class GetResolverGenerator method generateJavaFile.

@NotNull
public JavaFile generateJavaFile(@NotNull final StorIOContentResolverTypeMeta storIOContentResolverTypeMeta) {
    final ClassName storIOContentResolverTypeClassName = ClassName.get(storIOContentResolverTypeMeta.packageName, storIOContentResolverTypeMeta.simpleName);
    final TypeSpec getResolver = TypeSpec.classBuilder(generateName(storIOContentResolverTypeMeta)).addJavadoc("Generated resolver for Get Operation\n").addModifiers(PUBLIC).superclass(ParameterizedTypeName.get(ClassName.get("com.pushtorefresh.storio.contentresolver.operations.get", "DefaultGetResolver"), storIOContentResolverTypeClassName)).addMethod(storIOContentResolverTypeMeta.needCreator ? createMapFromCursorWithCreatorMethodSpec(storIOContentResolverTypeMeta, storIOContentResolverTypeClassName) : createMapFromCursorMethodSpec(storIOContentResolverTypeMeta, storIOContentResolverTypeClassName)).build();
    return JavaFile.builder(storIOContentResolverTypeMeta.packageName, getResolver).indent(INDENT).build();
}
Also used : ClassName(com.squareup.javapoet.ClassName) TypeSpec(com.squareup.javapoet.TypeSpec) NotNull(org.jetbrains.annotations.NotNull)

Example 79 with ClassName

use of com.squareup.javapoet.ClassName in project storio by pushtorefresh.

the class PutResolverGenerator method generateJavaFile.

@NotNull
public JavaFile generateJavaFile(@NotNull final StorIOContentResolverTypeMeta storIOContentResolverTypeMeta) {
    final ClassName storIOContentResolverTypeClassName = ClassName.get(storIOContentResolverTypeMeta.packageName, storIOContentResolverTypeMeta.simpleName);
    final TypeSpec putResolver = TypeSpec.classBuilder(generateName(storIOContentResolverTypeMeta)).addJavadoc("Generated resolver for Put Operation\n").addModifiers(PUBLIC).superclass(ParameterizedTypeName.get(ClassName.get("com.pushtorefresh.storio.contentresolver.operations.put", "DefaultPutResolver"), storIOContentResolverTypeClassName)).addMethod(createMapToInsertQueryMethodSpec(storIOContentResolverTypeMeta, storIOContentResolverTypeClassName)).addMethod(createMapToUpdateQueryMethodSpec(storIOContentResolverTypeMeta, storIOContentResolverTypeClassName)).addMethod(createMapToContentValuesMethodSpec(storIOContentResolverTypeMeta, storIOContentResolverTypeClassName)).build();
    return JavaFile.builder(storIOContentResolverTypeMeta.packageName, putResolver).indent(INDENT).build();
}
Also used : ClassName(com.squareup.javapoet.ClassName) TypeSpec(com.squareup.javapoet.TypeSpec) NotNull(org.jetbrains.annotations.NotNull)

Example 80 with ClassName

use of com.squareup.javapoet.ClassName in project requery by requery.

the class EntityGenerator method generateListeners.

private void generateListeners(MethodSpec.Builder constructor) {
    for (Map.Entry<Element, ? extends ListenerDescriptor> entry : entity.listeners().entrySet()) {
        for (Annotation annotation : entry.getValue().listenerAnnotations()) {
            String annotationName = annotation.annotationType().getSimpleName().replace("Persist", "Insert").replace("Remove", "Delete");
            String methodName = Names.lowerCaseFirst(annotationName);
            // avoid hardcoding the package name here
            Element listener = elements.getTypeElement(PreInsertListener.class.getCanonicalName());
            PackageElement packageElement = elements.getPackageOf(listener);
            // generate the listener name
            String packageName = packageElement.getQualifiedName().toString();
            ClassName listenerName = ClassName.get(packageName, annotationName + "Listener");
            ParameterizedTypeName getterType = ParameterizedTypeName.get(listenerName, typeName);
            TypeSpec.Builder listenerBuilder = TypeSpec.anonymousClassBuilder("").addSuperinterface(getterType).addMethod(CodeGeneration.overridePublicMethod(methodName).addParameter(typeName, "entity").addStatement("$L()", entry.getKey().getSimpleName()).build());
            constructor.addStatement("$L.modifyListeners().add$L($L)", PROXY_NAME, annotationName + "Listener", listenerBuilder.build());
        }
    }
}
Also used : ClassName(com.squareup.javapoet.ClassName) PreInsertListener(io.requery.proxy.PreInsertListener) Map(java.util.Map) Annotation(java.lang.annotation.Annotation) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) TypeSpec(com.squareup.javapoet.TypeSpec)

Aggregations

ClassName (com.squareup.javapoet.ClassName)99 TypeSpec (com.squareup.javapoet.TypeSpec)60 MethodSpec (com.squareup.javapoet.MethodSpec)41 TypeElement (javax.lang.model.element.TypeElement)37 ParameterizedTypeName (com.squareup.javapoet.ParameterizedTypeName)35 TypeName (com.squareup.javapoet.TypeName)30 Element (javax.lang.model.element.Element)19 TypeMirror (javax.lang.model.type.TypeMirror)17 Builder (com.squareup.javapoet.TypeSpec.Builder)16 FieldSpec (com.squareup.javapoet.FieldSpec)15 ArrayList (java.util.ArrayList)15 CodeBlock (com.squareup.javapoet.CodeBlock)11 ExecutableElement (javax.lang.model.element.ExecutableElement)11 NotNull (org.jetbrains.annotations.NotNull)10 VariableElement (javax.lang.model.element.VariableElement)9 JavaFile (com.squareup.javapoet.JavaFile)8 Map (java.util.Map)8 WildcardTypeName (com.squareup.javapoet.WildcardTypeName)7 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7