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();
}
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));
}
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);
}
use of com.squareup.javapoet.ParameterizedTypeName in project tiger by google.
the class NewDependencyCollector method addDependenciesForRequiredKeys.
/**
* Add dependencies from ctor injected classes needed by requiredKeys recursively to result.
*/
private void addDependenciesForRequiredKeys(SetMultimap<NewBindingKey, NewDependencyInfo> result, Set<NewBindingKey> requiredKeys) {
// Added all the required dependencies from ctor injected classes.
while (!requiredKeys.isEmpty()) {
NewBindingKey key = Iterables.getFirst(requiredKeys, null);
Preconditions.checkNotNull(key);
requiredKeys.remove(key);
if (result.containsKey(key)) {
continue;
}
TypeName typeName = key.getTypeName();
if (Utils.hasBuiltinBinding(typeName)) {
key = Utils.getElementKeyForBuiltinBinding(key);
requiredKeys.add(key);
continue;
}
if (Utils.isMapWithBuiltinValueType(key)) {
NewBindingKey peeledMapKey = Preconditions.checkNotNull(Utils.peelMapWithBuiltinValue(key));
requiredKeys.add(peeledMapKey);
continue;
}
ClassName className;
if (typeName instanceof ClassName) {
className = (ClassName) typeName;
} else {
Preconditions.checkState(typeName instanceof ParameterizedTypeName, "Expect a %s but get %s", ParameterizedTypeName.class, typeName);
ParameterizedTypeName parameterizedTypeName = (ParameterizedTypeName) typeName;
for (TypeName parameter : parameterizedTypeName.typeArguments) {
Preconditions.checkState(parameter instanceof ClassName || parameter instanceof ParameterizedTypeName, String.format("Unexpected parameter type %s for type %s.", parameter, typeName));
}
NewDependencyInfo dependencyInfo = Utils.getDependencyInfoByGeneric(result, key);
if (dependencyInfo != null) {
requiredKeys.addAll(dependencyInfo.getDependencies());
continue;
} else {
className = ((ParameterizedTypeName) typeName).rawType;
}
}
TypeElement classTypeElement = env.getElementUtils().getTypeElement(Utils.getClassCanonicalName(className));
Preconditions.checkNotNull(classTypeElement, String.format("Class %s not found.", className));
Collection<NewDependencyInfo> dependencies = collectFromCtorInjectedClass(classTypeElement);
if (dependencies == null) {
messager.printMessage(Kind.ERROR, String.format("Binding not found for %s", key));
continue;
}
NewDependencyInfo dependency = Iterables.getOnlyElement(dependencies);
if (typeName instanceof ParameterizedTypeName) {
Map<TypeVariableName, TypeName> parameterMap = Utils.getMapFromTypeVariableToSpecialized((ParameterizedTypeName) typeName, (ParameterizedTypeName) dependency.getDependant().getTypeName());
requiredKeys.addAll(Utils.specializeIfNeeded(dependency.getDependencies(), parameterMap));
} else {
requiredKeys.addAll(dependency.getDependencies());
}
checkOneDependency(result, dependency);
addDependencyInfo(result, dependency);
}
}
use of com.squareup.javapoet.ParameterizedTypeName in project tiger by google.
the class NewDependencyCollector method collectionToMultimap.
/**
* NOTE: the key of the returned map is of the raw type if the related
* {@link NewDependencyInfo#getDependant()} is for a generic class.
*/
public static SetMultimap<NewBindingKey, NewDependencyInfo> collectionToMultimap(Collection<NewDependencyInfo> dependencies) {
SetMultimap<NewBindingKey, NewDependencyInfo> result = HashMultimap.create();
for (NewDependencyInfo info : dependencies) {
NewBindingKey key = info.getDependant();
TypeName typeName = key.getTypeName();
// For generic type with type variable, only keep raw type.
if (typeName instanceof ParameterizedTypeName) {
ParameterizedTypeName parameterizedTypeName = (ParameterizedTypeName) typeName;
TypeName anyParameter = Preconditions.checkNotNull(Iterables.getFirst(parameterizedTypeName.typeArguments, null), String.format("ParameterizedTypeName of %s has no parameter.", key));
if (anyParameter instanceof TypeVariableName) {
typeName = parameterizedTypeName.rawType;
key = NewBindingKey.get(typeName, key.getQualifier());
}
}
result.put(key, info);
}
return result;
}
Aggregations