/** Returns a string for {@code type}. Primitive types are always boxed. */ public static String typeToString(TypeMirror type) { StringBuilder result = new StringBuilder(); typeToString(type, result, '.'); return result.toString(); }
/** Returns the provider key for {@code type}. */ public static String get(TypeMirror type) { StringBuilder result = new StringBuilder(); typeToString(type, result, '$'); return result.toString(); }
private static void qualifierToString(AnnotationMirror qualifier, StringBuilder result) { // TODO: guarantee that element values are sorted by name (if there are multiple) result.append('@'); typeToString(qualifier.getAnnotationType(), result, '$'); result.append('('); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : qualifier.getElementValues().entrySet()) { result.append(entry.getKey().getSimpleName()); result.append('='); result.append(entry.getValue().getValue()); } result.append(")/"); }
@Override public Void visitArray(ArrayType arrayType, Void v) { TypeMirror type = arrayType.getComponentType(); if (type instanceof PrimitiveType) { result.append(type.toString()); // Don't box, since this is an array. } else { typeToString(arrayType.getComponentType(), result, innerClassSeparator); } result.append("[]"); return null; } @Override public Void visitTypeVariable(TypeVariable typeVariable, Void v) {
@Override public Void visitDeclared(DeclaredType declaredType, Void v) { TypeElement typeElement = (TypeElement) declaredType.asElement(); rawTypeToString(result, typeElement, innerClassSeparator); List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments(); if (!typeArguments.isEmpty()) { result.append("<"); for (int i = 0; i < typeArguments.size(); i++) { if (i != 0) { result.append(", "); } typeToString(typeArguments.get(i), result, innerClassSeparator); } result.append(">"); } return null; } @Override public Void visitPrimitive(PrimitiveType primitiveType, Void v) {
/** Returns the provided key for {@code method} wrapped by {@code Set}. */ public static String getSetKey(ExecutableElement method) { StringBuilder result = new StringBuilder(); AnnotationMirror qualifier = getQualifier(method.getAnnotationMirrors()); if (qualifier != null) { qualifierToString(qualifier, result); } result.append(SET_PREFIX); typeToString(method.getReturnType(), result, '$'); result.append(">"); return result.toString(); }
/** Returns the provided key for {@code method}. */ public static String get(ExecutableElement method) { StringBuilder result = new StringBuilder(); AnnotationMirror qualifier = getQualifier(method.getAnnotationMirrors()); if (qualifier != null) { qualifierToString(qualifier, result); } typeToString(method.getReturnType(), result, '$'); return result.toString(); }
/** Returns the provider key for {@code variable}. */ public static String get(VariableElement variable) { StringBuilder result = new StringBuilder(); AnnotationMirror qualifier = getQualifier(variable.getAnnotationMirrors()); if (qualifier != null) { qualifierToString(qualifier, result); } typeToString(variable.asType(), result, '$'); return result.toString(); }
key, (singleton ? "IS_SINGLETON" : "NOT_SINGLETON"), typeToString(moduleType), methodName) .addStatement("this.module = module")