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


Java DeclaredType.getEnclosingType方法代碼示例

本文整理匯總了Java中javax.lang.model.type.DeclaredType.getEnclosingType方法的典型用法代碼示例。如果您正苦於以下問題:Java DeclaredType.getEnclosingType方法的具體用法?Java DeclaredType.getEnclosingType怎麽用?Java DeclaredType.getEnclosingType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.lang.model.type.DeclaredType的用法示例。


在下文中一共展示了DeclaredType.getEnclosingType方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: enclosedBy

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
private boolean enclosedBy(TypeMirror t1, TypeMirror t2) {
    if(t1.getKind() == TypeKind.DECLARED) {
        if(workingCopy.getTypes().isSameType(t1, t2)) {
            return true;
        }
        DeclaredType dt = (DeclaredType) t1;
        TypeMirror enclosingType = dt.getEnclosingType();
        if(enclosingType.getKind() == TypeKind.NONE) {
            return false;
        } else {
            return enclosedBy(enclosingType, t2);
        }
    } else {
        return false;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:MoveMembersTransformer.java

示例2: visitDeclared

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
@Override
public TypeMirror visitDeclared(DeclaredType t, CompilationInfo p) {
    if (t.getTypeArguments().isEmpty()) {
        return t;
    }
    List<TypeMirror> newArgs = new ArrayList<TypeMirror>(t.getTypeArguments().size());
    for (TypeMirror tm : t.getTypeArguments()) {
        newArgs.add(visit(tm, p));
    }
    
    TypeMirror enclosing = t.getEnclosingType();
    if (enclosing != null) {
        enclosing = visit(enclosing, p);
    }
    
    return p.getTypes().getDeclaredType(
        (DeclaredType)enclosing,
        (TypeElement)t.asElement(), 
        newArgs.toArray(new TypeMirror[newArgs.size()]));
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:ControllerGenerator.java

示例3: visitNewClass

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
@Override
public List<? extends TypeMirror> visitNewClass(NewClassTree node, Object p) {
    TypeMirror tm = info.getTrees().getTypeMirror(getCurrentPath());
    if (tm == null || tm.getKind() != TypeKind.DECLARED) {
        return null;
    }
    Element el = info.getTrees().getElement(getCurrentPath());
    if (el == null) {
        return null;
    }
    if (theExpression.getLeaf() != node.getEnclosingExpression()) {
        ExecutableType execType = (ExecutableType)info.getTypes().asMemberOf((DeclaredType)tm, el);
        return visitMethodOrNew(node, p, node.getArguments(), execType);
    } else {
        DeclaredType dt = (DeclaredType)tm;
        if (dt.getEnclosingType() == null) {
            return null;
        }
        return Collections.singletonList(dt.getEnclosingType());
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:ExpectedTypeResolver.java

示例4: resolveCapturedTypeInt

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
/**
 * Note: may return {@code null}, if an intersection type is encountered, to indicate a 
 * real type cannot be created.
 */
private static TypeMirror resolveCapturedTypeInt(CompilationInfo info, TypeMirror tm) {
    if (tm == null) return tm;
    
    TypeMirror orig = SourceUtils.resolveCapturedType(tm);

    if (orig != null) {
        tm = orig;
    }
    
    if (tm.getKind() == TypeKind.WILDCARD) {
        TypeMirror extendsBound = ((WildcardType) tm).getExtendsBound();
        TypeMirror superBound = ((WildcardType) tm).getSuperBound();
        if (extendsBound != null || superBound != null) {
            TypeMirror rct = resolveCapturedTypeInt(info, extendsBound != null ? extendsBound : superBound);
            if (rct != null) {
                switch (rct.getKind()) {
                    case WILDCARD:
                        return rct;
                    case ARRAY:
                    case DECLARED:
                    case ERROR:
                    case TYPEVAR:
                    case OTHER:
                        return info.getTypes().getWildcardType(
                                extendsBound != null ? rct : null, superBound != null ? rct : null);
                }
            } else {
                // propagate failure out of all wildcards
                return null;
            }
        }
    } else if (tm.getKind() == TypeKind.INTERSECTION) {
        return null;
    }
    
    if (tm.getKind() == TypeKind.DECLARED) {
        DeclaredType dt = (DeclaredType) tm;
        List<TypeMirror> typeArguments = new LinkedList<TypeMirror>();
        
        for (TypeMirror t : dt.getTypeArguments()) {
            TypeMirror targ = resolveCapturedTypeInt(info, t);
            if (targ == null) {
                // bail out, if the type parameter is a wildcard, it's probably not possible
                // to create a proper parametrized type from it
                if (t.getKind() == TypeKind.WILDCARD || t.getKind() == TypeKind.INTERSECTION) {
                    return null;
                }
                // use rawtype
                typeArguments.clear();
                break;
            }
            typeArguments.add(targ);
        }
        
        final TypeMirror enclosingType = dt.getEnclosingType();
        if (enclosingType.getKind() == TypeKind.DECLARED) {
            return info.getTypes().getDeclaredType((DeclaredType) enclosingType, (TypeElement) dt.asElement(), typeArguments.toArray(new TypeMirror[0]));
        } else {
            if (dt.asElement() == null) return dt;
            return info.getTypes().getDeclaredType((TypeElement) dt.asElement(), typeArguments.toArray(new TypeMirror[0]));
        }
    }

    if (tm.getKind() == TypeKind.ARRAY) {
        ArrayType at = (ArrayType) tm;
        TypeMirror tm2 = resolveCapturedTypeInt(info, at.getComponentType());
        return info.getTypes().getArrayType(tm2 != null ? tm2 : tm);
    }
    
    return tm;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:76,代碼來源:TypeUtilities.java

示例5: resolveCapturedTypeInt

import javax.lang.model.type.DeclaredType; //導入方法依賴的package包/類
private static TypeMirror resolveCapturedTypeInt(CompilationInfo info, TypeMirror tm) {
    if (tm == null) {
        return tm;
    }
    
    TypeMirror orig = resolveCapturedType(tm);

    if (orig != null) {
        tm = orig;
    }
    
    if (tm.getKind() == TypeKind.WILDCARD) {
        TypeMirror extendsBound = ((WildcardType) tm).getExtendsBound();
        TypeMirror rct = resolveCapturedTypeInt(info, extendsBound != null ? extendsBound : ((WildcardType) tm).getSuperBound());
        if (rct != null) {
            return rct.getKind() == TypeKind.WILDCARD ? rct : info.getTypes().getWildcardType(extendsBound != null ? rct : null, extendsBound == null ? rct : null);
        }
    }
    
    if (tm.getKind() == TypeKind.DECLARED) {
        DeclaredType dt = (DeclaredType) tm;
        TypeElement el = (TypeElement) dt.asElement();
        if (((DeclaredType)el.asType()).getTypeArguments().size() != dt.getTypeArguments().size()) {
            return info.getTypes().getDeclaredType(el);
        }
        
        List<TypeMirror> typeArguments = new LinkedList<>();
        
        for (TypeMirror t : dt.getTypeArguments()) {
            typeArguments.add(resolveCapturedTypeInt(info, t));
        }
        
        final TypeMirror enclosingType = dt.getEnclosingType();
        if (enclosingType.getKind() == TypeKind.DECLARED) {
            return info.getTypes().getDeclaredType((DeclaredType) enclosingType, el, typeArguments.toArray(new TypeMirror[0]));
        } else {
            return info.getTypes().getDeclaredType(el, typeArguments.toArray(new TypeMirror[0]));
        }
    }

    if (tm.getKind() == TypeKind.ARRAY) {
        ArrayType at = (ArrayType) tm;
        TypeMirror componentType = resolveCapturedTypeInt(info, at.getComponentType());
        switch (componentType.getKind()) {
            case VOID:
            case EXECUTABLE:
            case WILDCARD:  // heh!
            case PACKAGE:
                break;
            default:
                return info.getTypes().getArrayType(componentType);
        }
    }
    
    return tm;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:57,代碼來源:SourceUtils.java


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