本文整理匯總了Java中javax.lang.model.util.SimpleTypeVisitor6類的典型用法代碼示例。如果您正苦於以下問題:Java SimpleTypeVisitor6類的具體用法?Java SimpleTypeVisitor6怎麽用?Java SimpleTypeVisitor6使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SimpleTypeVisitor6類屬於javax.lang.model.util包,在下文中一共展示了SimpleTypeVisitor6類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTypeArgument
import javax.lang.model.util.SimpleTypeVisitor6; //導入依賴的package包/類
@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;
}
示例2: asDeclaredType
import javax.lang.model.util.SimpleTypeVisitor6; //導入依賴的package包/類
private static DeclaredType asDeclaredType(TypeMirror type) {
return type.accept(new SimpleTypeVisitor6<DeclaredType, Object>() {
@Override
public DeclaredType visitDeclared(DeclaredType t, Object o) {
return t;
}
}, null);
}
示例3: isValidMap
import javax.lang.model.util.SimpleTypeVisitor6; //導入依賴的package包/類
/**
* 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);
}
示例4: getGenericType
import javax.lang.model.util.SimpleTypeVisitor6; //導入依賴的package包/類
/**
* 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);
}
示例5: extractGetIfList
import javax.lang.model.util.SimpleTypeVisitor6; //導入依賴的package包/類
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;
}
示例6: extractPutIfList
import javax.lang.model.util.SimpleTypeVisitor6; //導入依賴的package包/類
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;
}
示例7: TypeMirrorToDAInterfaceWithGeneric
import javax.lang.model.util.SimpleTypeVisitor6; //導入依賴的package包/類
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));
}
};
}