本文整理汇总了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;
}