本文整理匯總了Java中javax.lang.model.util.Types.directSupertypes方法的典型用法代碼示例。如果您正苦於以下問題:Java Types.directSupertypes方法的具體用法?Java Types.directSupertypes怎麽用?Java Types.directSupertypes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.lang.model.util.Types
的用法示例。
在下文中一共展示了Types.directSupertypes方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: replaceWithSuperType
import javax.lang.model.util.Types; //導入方法依賴的package包/類
private void replaceWithSuperType(TreePath path, VariableTree oldVarTree, VariableElement varElement, Element superTypeElement) {
Types types = workingCopy.getTypes();
TypeMirror supTypeErasure = types.erasure(superTypeElement.asType());
DeclaredType varType = (DeclaredType) varElement.asType();
TypeMirror theType = null;
List<TypeMirror> supertypes = new LinkedList(types.directSupertypes(varType));
while(!supertypes.isEmpty()) {
TypeMirror supertype = supertypes.remove(0);
if(types.isSameType(types.erasure(supertype), supTypeErasure)) {
theType = supertype;
break;
}
supertypes.addAll(types.directSupertypes(supertype));
}
if(theType == null) {
theType = supTypeErasure;
}
Tree superTypeTree = make.Type(theType);
ExpressionTree oldInitTree = oldVarTree.getInitializer();
ModifiersTree oldModifiers = oldVarTree.getModifiers();
Tree newTree = make.Variable(oldModifiers, oldVarTree.getName(),
superTypeTree, oldInitTree);
rewrite(oldVarTree, newTree);
}
示例2: deepSearchTypes
import javax.lang.model.util.Types; //導入方法依賴的package包/類
private boolean deepSearchTypes(DeclaredType currentElement, TypeMirror orig, TypeMirror something, Map<TypeMirror, TypeParameterElement> mappings) {
Types types = workingCopy.getTypes();
List<? extends TypeMirror> directSupertypes = types.directSupertypes(currentElement);
for (TypeMirror superType : directSupertypes) {
DeclaredType type = (DeclaredType) superType;
List<? extends TypeMirror> typeArguments = type.getTypeArguments();
for (int i = 0; i < typeArguments.size(); i++) {
TypeMirror typeArgument = typeArguments.get(i);
if (something.equals(typeArgument)) {
TypeElement asElement = (TypeElement) type.asElement();
mappings.put(orig, asElement.getTypeParameters().get(i));
if (types.erasure(targetType.asType()).equals(types.erasure(superType))) {
return true;
}
if(deepSearchTypes(type, orig, typeArgument, mappings)) {
break;
}
}
}
if (types.erasure(targetType.asType()).equals(types.erasure(superType))) {
mappings.remove(orig);
return true;
}
}
return false;
}
示例3: nonPrivateDeclaredTypes
import javax.lang.model.util.Types; //導入方法依賴的package包/類
/**
* Finds all types that are declared with non private visibility by the given {@code TypeMirror},
* any class in its superclass chain, or any interface it implements.
*/
private static Set<TypeMirror> nonPrivateDeclaredTypes(Types typeUtils, TypeMirror type) {
if (type == null) {
return new TypeMirrorSet();
} else {
Set<TypeMirror> declared = new TypeMirrorSet();
declared.add(type);
List<TypeElement> nestedTypes =
ElementFilter.typesIn(typeUtils.asElement(type).getEnclosedElements());
for (TypeElement nestedType : nestedTypes) {
if (!nestedType.getModifiers().contains(PRIVATE)) {
declared.add(nestedType.asType());
}
}
for (TypeMirror supertype : typeUtils.directSupertypes(type)) {
declared.addAll(nonPrivateDeclaredTypes(typeUtils, supertype));
}
return declared;
}
}
示例4: nonPrivateDeclaredTypes
import javax.lang.model.util.Types; //導入方法依賴的package包/類
/**
* Finds all types that are declared with non private visibility by the given {@code TypeMirror},
* any class in its superclass chain, or any interface it implements.
*/
private static Set<TypeMirror> nonPrivateDeclaredTypes(Types typeUtils, TypeMirror type) {
if (type == null) {
return new TypeMirrorSet();
} else {
Set<TypeMirror> declared = new TypeMirrorSet();
declared.add(type);
List<TypeElement> nestedTypes =
ElementFilter.typesIn(typeUtils.asElement(type).getEnclosedElements());
for (TypeElement nestedType : nestedTypes) {
if (!nestedType.getModifiers().contains(PRIVATE)) {
declared.add(nestedType.asType());
}
}
for (TypeMirror supertype : typeUtils.directSupertypes(type)) {
declared.addAll(nonPrivateDeclaredTypes(typeUtils, supertype));
}
return declared;
}
}
示例5: testParentOf
import javax.lang.model.util.Types; //導入方法依賴的package包/類
/**
* Test if typeElement is a parent of currentElement.
*/
private static boolean testParentOf(Types types, TypeMirror currentElement, TypeMirror typeMirror) {
List<? extends TypeMirror> directSupertypes = types.directSupertypes(currentElement);
for (TypeMirror superType : directSupertypes) {
if (superType.equals(typeMirror)) {
return true;
} else {
boolean isParent = testParentOf(types, superType, typeMirror);
if (isParent) {
return true;
}
}
}
return false;
}
示例6: visitDeclared
import javax.lang.model.util.Types; //導入方法依賴的package包/類
@Override
public Void visitDeclared(DeclaredType t, Types types) {
t.asElement().getKind(); // ensure class exists
for (TypeMirror st: types.directSupertypes(t))
visit(st, types);
return null;
}
示例7: visitDeclared
import javax.lang.model.util.Types; //導入方法依賴的package包/類
@Override @DefinedBy(Api.LANGUAGE_MODEL)
public Void visitDeclared(DeclaredType t, Types types) {
t.asElement().getKind(); // ensure class exists
for (TypeMirror st: types.directSupertypes(t))
visit(st, types);
return null;
}