@Nullable
private TypeMirror getTypeArgument(TypeMirror annotatedType, final TypeElement baseType) {
for (TypeMirror type : getAllTypes(annotatedType)) {
TypeMirror typeArgument = type.accept(new SimpleTypeVisitor6<TypeMirror, Void>() {
@Override public TypeMirror visitDeclared(DeclaredType t, Void aVoid) {
if (isAssignable(t, baseType)) {
List<? extends TypeMirror> typeArguments = t.getTypeArguments();
if (!typeArguments.isEmpty()) {
return typeUtils.erasure(typeArguments.get(0));
}
}
return null;
}
}, null);
if (typeArgument != null) {
return typeArgument;
}
}
error("Failed to find a type argument for %s in %s", baseType, annotatedType);
return null;
}
java类javax.lang.model.util.SimpleTypeVisitor6的实例源码
CmdLineProcessor.java 文件源码
项目:Mastering-Mesos
阅读 26
收藏 0
点赞 0
评论 0
GsonValueProcessor.java 文件源码
项目:gsonvalue
阅读 18
收藏 0
点赞 0
评论 0
private static DeclaredType asDeclaredType(TypeMirror type) {
return type.accept(new SimpleTypeVisitor6<DeclaredType, Object>() {
@Override
public DeclaredType visitDeclared(DeclaredType t, Object o) {
return t;
}
}, null);
}
Parcelables.java 文件源码
项目:auto-value-parcel
阅读 25
收藏 0
点赞 0
评论 0
/**
* Maps can only have String keys and Parcelable values.
*/
private static boolean isValidMap(Types types, TypeMirror type) {
return type.accept(new SimpleTypeVisitor6<Boolean, Types>() {
@Override public Boolean visitDeclared(DeclaredType t, Types o) {
List<? extends TypeMirror> args = t.getTypeArguments();
if (args.size() == 2) {
TypeMirror key = args.get(0);
TypeMirror value = args.get(1);
if (STRING.equals(TypeName.get(key)) && isValidType(o, value)) {
return true;
}
}
return false;
}
}, types);
}
BindingManager.java 文件源码
项目:remoter
阅读 22
收藏 0
点赞 0
评论 0
/**
* Return the generic type if any
*/
public TypeElement getGenericType(TypeMirror typeMirror) {
return typeMirror.accept(new SimpleTypeVisitor6<TypeElement, Void>() {
@Override
public TypeElement visitDeclared(DeclaredType declaredType, Void v) {
TypeElement genericTypeElement = null;
TypeElement typeElement = (TypeElement) declaredType.asElement();
if (parcelClass != null && typeUtils.isAssignable(typeElement.asType(), listTypeMirror)) {
List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
if (!typeArguments.isEmpty()) {
for (TypeMirror genericType : typeArguments) {
if (genericType instanceof WildcardType) {
WildcardType wildcardType = (WildcardType) genericType;
TypeMirror extendsType = wildcardType.getExtendsBound();
if (extendsType != null) {
typeElement = elementUtils.getTypeElement(extendsType.toString());
if (typeElement.getAnnotation(parcelClass) != null) {
genericTypeElement = typeElement;
break;
}
}
} else {
typeElement = elementUtils.getTypeElement(genericType.toString());
if (typeElement.getAnnotation(parcelClass) != null) {
genericTypeElement = typeElement;
break;
}
}
}
}
}
return genericTypeElement;
}
}, null);
}
FragmentCreatorReadGenerator.java 文件源码
项目:fragment-creator
阅读 18
收藏 0
点赞 0
评论 0
String extractGetIfList(TypeMirror typeMirror) {
String name = typeMirror.toString();
if (name.startsWith("java.util.List")) {
//check type
DeclaredType declaredType = typeMirror.accept(new SimpleTypeVisitor6<DeclaredType, String>() {
@Override
public DeclaredType visitDeclared(DeclaredType t, String s) {
return t;
}
}, name);
if (declaredType == null) {
return null;
}
List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
if (typeArguments.isEmpty()) {
return null;
}
TypeMirror typeParameter = typeArguments.get(0);
switch (MirrorUtils.flattenArrayListType(environment, typeParameter)) {
case "java.lang.Integer":
return "args.getIntegerArrayList($S)";
case "java.lang.String":
return "args.getStringArrayList($S)";
case "java.lang.CharSequence":
return "args.getCharSequenceArrayList($S)";
case "android.os.Parcelable":
return "args.getParcelableArrayList($S)";
}
}
return null;
}
FragmentCreatorBuilderGenerator.java 文件源码
项目:fragment-creator
阅读 18
收藏 0
点赞 0
评论 0
String extractPutIfList(TypeMirror typeMirror) {
String name = typeMirror.toString();
if (name.startsWith("java.util.List")) {
//check type
DeclaredType declaredType = typeMirror.accept(new SimpleTypeVisitor6<DeclaredType, String>() {
@Override
public DeclaredType visitDeclared(DeclaredType t, String s) {
return t;
}
}, name);
if (declaredType == null) {
return null;
}
List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
if (typeArguments.isEmpty()) {
return null;
}
TypeMirror typeParameter = typeArguments.get(0);
switch (MirrorUtils.flattenArrayListType(environment, typeParameter)) {
case "java.lang.Integer":
return "args.putIntegerArrayList($S,";
case "java.lang.String":
return "args.putStringArrayList($S,";
case "java.lang.CharSequence":
return "args.putCharSequenceArrayList($S,";
case "android.os.Parcelable":
return "args.putParcelableArrayList($S,";
}
}
return null;
}
JavaxParsingServiceImpl.java 文件源码
项目:damapping
阅读 17
收藏 0
点赞 0
评论 0
public TypeMirrorToDAInterfaceWithGeneric(final JavaxExtractor javaxExtractor, final GenericTypeContext genericTypeContext) {
this.daInterfaceExtractor = new SimpleTypeVisitor6<DAInterface, Void>() {
@Override
public DAInterface visitDeclared(DeclaredType declaredType, Void aVoid) {
return new DAInterfaceImpl(javaxExtractor.extractType(declaredType, genericTypeContext));
}
};
}