Search in sources :

Example 1 with ParameterizedTypeName

use of com.squareup.javapoet.ParameterizedTypeName in project glide by bumptech.

the class RootModuleGenerator method generateGetExcludedModuleClasses.

// TODO: When we drop support for parsing GlideModules from AndroidManifests, remove this method.
private static MethodSpec generateGetExcludedModuleClasses(Set<String> excludedClassNames) {
    TypeName wildCardOfObject = WildcardTypeName.subtypeOf(Object.class);
    ParameterizedTypeName classOfWildcardOfObjet = ParameterizedTypeName.get(ClassName.get(Class.class), wildCardOfObject);
    ParameterizedTypeName setOfClassOfWildcardOfObject = ParameterizedTypeName.get(ClassName.get(Set.class), classOfWildcardOfObjet);
    ParameterizedTypeName hashSetOfClassOfWildcardOfObject = ParameterizedTypeName.get(ClassName.get(HashSet.class), classOfWildcardOfObjet);
    MethodSpec.Builder builder = MethodSpec.methodBuilder("getExcludedModuleClasses").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).returns(setOfClassOfWildcardOfObject);
    if (excludedClassNames.isEmpty()) {
        builder.addStatement("return $T.emptySet()", Collections.class);
    } else {
        builder.addStatement("$T excludedClasses = new $T()", setOfClassOfWildcardOfObject, hashSetOfClassOfWildcardOfObject);
        for (String excludedClassName : excludedClassNames) {
            // TODO: Remove this when we no longer support manifest parsing.
            // Using a Literal ($L) instead of a type ($T) to get a fully qualified import that allows
            // us to suppress deprecation warnings. Aimed at deprecated GlideModules.
            builder.addStatement("excludedClasses.add($L.class)", excludedClassName);
        }
        builder.addStatement("return excludedClasses");
    }
    return builder.build();
}
Also used : WildcardTypeName(com.squareup.javapoet.WildcardTypeName) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) TypeName(com.squareup.javapoet.TypeName) Set(java.util.Set) HashSet(java.util.HashSet) MethodSpec(com.squareup.javapoet.MethodSpec) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) HashSet(java.util.HashSet)

Example 2 with ParameterizedTypeName

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

the class MappingGenerator method generateJavaFile.

@NotNull
@Override
public JavaFile generateJavaFile(@NotNull StorIOContentResolverTypeMeta storIOSQLiteTypeMeta) {
    final ClassName storIOSQLiteTypeClassName = ClassName.get(storIOSQLiteTypeMeta.packageName, storIOSQLiteTypeMeta.simpleName);
    ClassName superclass = ClassName.get("com.pushtorefresh.storio.contentresolver", SUFFIX);
    ParameterizedTypeName superclassParametrized = ParameterizedTypeName.get(superclass, storIOSQLiteTypeClassName);
    final TypeSpec mapping = TypeSpec.classBuilder(storIOSQLiteTypeMeta.simpleName + SUFFIX).addJavadoc("Generated mapping with collection of resolvers\n").addModifiers(PUBLIC).superclass(superclassParametrized).addMethod(createConstructor(storIOSQLiteTypeMeta)).build();
    return JavaFile.builder(storIOSQLiteTypeMeta.packageName, mapping).indent(INDENT).build();
}
Also used : ClassName(com.squareup.javapoet.ClassName) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) TypeSpec(com.squareup.javapoet.TypeSpec) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ParameterizedTypeName

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

the class MappingGenerator method generateJavaFile.

@NotNull
@Override
public JavaFile generateJavaFile(@NotNull StorIOSQLiteTypeMeta storIOSQLiteTypeMeta) {
    final ClassName storIOSQLiteTypeClassName = ClassName.get(storIOSQLiteTypeMeta.packageName, storIOSQLiteTypeMeta.simpleName);
    ClassName superclass = ClassName.get("com.pushtorefresh.storio.sqlite", SUFFIX);
    ParameterizedTypeName superclassParametrized = ParameterizedTypeName.get(superclass, storIOSQLiteTypeClassName);
    final TypeSpec mapping = TypeSpec.classBuilder(storIOSQLiteTypeMeta.simpleName + SUFFIX).addJavadoc("Generated mapping with collection of resolvers.\n").addModifiers(PUBLIC).superclass(superclassParametrized).addMethod(createConstructor(storIOSQLiteTypeMeta)).build();
    return JavaFile.builder(storIOSQLiteTypeMeta.packageName, mapping).indent(INDENT).build();
}
Also used : ClassName(com.squareup.javapoet.ClassName) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) TypeSpec(com.squareup.javapoet.TypeSpec) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ParameterizedTypeName

use of com.squareup.javapoet.ParameterizedTypeName in project tiger by google.

the class Utils method hasBuiltinBinding.

public static boolean hasBuiltinBinding(TypeName type) {
    if (!(type instanceof ParameterizedTypeName)) {
        return false;
    }
    ParameterizedTypeName typeName = (ParameterizedTypeName) type;
    ClassName rawType = typeName.rawType;
    return rawType.equals(ClassName.get(Provider.class)) || rawType.equals(ClassName.get(Lazy.class));
}
Also used : ClassName(com.squareup.javapoet.ClassName) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName)

Example 5 with ParameterizedTypeName

use of com.squareup.javapoet.ParameterizedTypeName in project tiger by google.

the class Utils method getElementKeyForBuiltinBinding.

/**
   * Return {@link NewBindingKey} for element of the give {@link NewBindingKey} that
   * has built-in binding, null if not built-in building.
   */
@Nullable
public static NewBindingKey getElementKeyForBuiltinBinding(NewBindingKey key) {
    if (!hasBuiltinBinding(key)) {
        return null;
    }
    ParameterizedTypeName parameterizedTypeName = (ParameterizedTypeName) key.getTypeName();
    TypeName typeName = Iterables.getOnlyElement(parameterizedTypeName.typeArguments);
    AnnotationSpec qualifier = key.getQualifier();
    return NewBindingKey.get(typeName, qualifier);
}
Also used : TypeName(com.squareup.javapoet.TypeName) WildcardTypeName(com.squareup.javapoet.WildcardTypeName) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) ArrayTypeName(com.squareup.javapoet.ArrayTypeName) AnnotationSpec(com.squareup.javapoet.AnnotationSpec) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) Nullable(javax.annotation.Nullable)

Aggregations

ParameterizedTypeName (com.squareup.javapoet.ParameterizedTypeName)135 TypeName (com.squareup.javapoet.TypeName)90 ClassName (com.squareup.javapoet.ClassName)53 MethodSpec (com.squareup.javapoet.MethodSpec)47 TypeSpec (com.squareup.javapoet.TypeSpec)29 WildcardTypeName (com.squareup.javapoet.WildcardTypeName)29 TypeElement (javax.lang.model.element.TypeElement)23 ArrayList (java.util.ArrayList)19 TypeMirror (javax.lang.model.type.TypeMirror)19 ArrayTypeName (com.squareup.javapoet.ArrayTypeName)15 HashSet (java.util.HashSet)14 Map (java.util.Map)13 List (java.util.List)12 Set (java.util.Set)12 FieldSpec (com.squareup.javapoet.FieldSpec)11 ParameterSpec (com.squareup.javapoet.ParameterSpec)11 TypeVariableName (com.squareup.javapoet.TypeVariableName)10 Element (javax.lang.model.element.Element)10 PackageElement (javax.lang.model.element.PackageElement)10 Builder (com.squareup.javapoet.TypeSpec.Builder)9