當前位置: 首頁>>代碼示例>>Java>>正文


Java Types.directSupertypes方法代碼示例

本文整理匯總了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);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:UseSuperTypeRefactoringPlugin.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:PullUpTransformer.java

示例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;
    }
}
 
開發者ID:ccheptea,項目名稱:auto-value-node,代碼行數:24,代碼來源:TypeSimplifier.java

示例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;
  }
}
 
開發者ID:sopak,項目名稱:auto-value-step-builder,代碼行數:24,代碼來源:TypeSimplifier.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:ToolTipAnnotation.java

示例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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:8,代碼來源:JavahTask.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:JavahTask.java


注:本文中的javax.lang.model.util.Types.directSupertypes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。