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


Java TypeKind.INTERSECTION屬性代碼示例

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


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

示例1: checkAmbiguous

/**
 * Checks whether a method or constructor call would become ambiguous if the parameter type changes.
 * 
 * @param info compilation context
 * @param parentExec path to the constructor or method invocation
 * @param argIndex
 * @param casteeType
 * @return 
 */
private static boolean checkAmbiguous(CompilationInfo info, final TreePath parentExec, int argIndex, TypeMirror casteeType, TreePath realArgTree) {
    CharSequence altType = info.getTypeUtilities().getTypeName(casteeType, TypeUtilities.TypeNameOptions.PRINT_FQN);
    String prefix = null;
    if (casteeType != null && !(casteeType.getKind() == TypeKind.NULL || casteeType.getKind() == TypeKind.INTERSECTION)) {
        prefix = "(" + altType + ")"; // NOI18N
    }
    Tree leaf = parentExec.getLeaf();
    List<? extends Tree> arguments;
    if (leaf instanceof MethodInvocationTree) {
        MethodInvocationTree mi = (MethodInvocationTree)leaf;
        arguments = mi.getArguments();
    } else {
        arguments = ((NewClassTree)leaf).getArguments();
    }
    Tree argTree = arguments.get(argIndex);
    TreePath argPath = new TreePath(parentExec, argTree);
    return !Utilities.checkAlternativeInvocation(info, parentExec, argPath, realArgTree, prefix);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:TooStrongCast.java

示例2: interfaceParameterIsIntersectionType

/**
 * Erasure destroys the implementation parameter subtype
 * relationship for intersection types
 */
boolean interfaceParameterIsIntersectionType() {
    List<Type> tl = tree.getDescriptorType(types).getParameterTypes();
    if (tree.kind == ReferenceKind.UNBOUND) {
        tl = tl.tail;
    }
    for (; tl.nonEmpty(); tl = tl.tail) {
        Type pt = tl.head;
        if (pt.getKind() == TypeKind.TYPEVAR) {
            TypeVar tv = (TypeVar) pt;
            if (tv.bound.getKind() == TypeKind.INTERSECTION) {
                return true;
            }
        }
    }
    return false;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:20,代碼來源:LambdaToMethod.java

示例3: avoidIntersectionType

private static TypeMirror avoidIntersectionType(CompilationInfo copy, TypeMirror org) {
    if (org.getKind() == TypeKind.INTERSECTION) {
        Element objEl = copy.getElements().getTypeElement("java.lang.Object"); // NOI18N
        if (objEl == null) {
            // TODO: report
            return org;
        }
        return objEl.asType();
    } else {
        return org;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:12,代碼來源:Lambda.java

示例4: interfaceParameterIsIntersectionType

/**
 * Erasure destroys the implementation parameter subtype
 * relationship for intersection types
 */
boolean interfaceParameterIsIntersectionType() {
    List<Type> tl = tree.getDescriptorType(types).getParameterTypes();
    for (; tl.nonEmpty(); tl = tl.tail) {
        Type pt = tl.head;
        if (pt.getKind() == TypeKind.TYPEVAR) {
            TypeVar tv = (TypeVar) pt;
            if (tv.bound.getKind() == TypeKind.INTERSECTION) {
                return true;
            }
        }
    }
    return false;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:LambdaToMethod.java

示例5: resolveCapturedTypeInt

/**
 * 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,代碼行數:75,代碼來源:TypeUtilities.java

示例6: addParametersReturnReceiver

/**
 * Generate the parameter list for the converted member reference.
 *
 * @return The receiver variable symbol, if any
 */
VarSymbol addParametersReturnReceiver() {
    Type samDesc = localContext.bridgedRefSig();
    List<Type> samPTypes = samDesc.getParameterTypes();
    List<Type> descPTypes = tree.getDescriptorType(types).getParameterTypes();

    // Determine the receiver, if any
    VarSymbol rcvr;
    switch (tree.kind) {
        case BOUND:
            // The receiver is explicit in the method reference
            rcvr = addParameter("rec$", tree.getQualifierExpression().type, false);
            receiverExpression = attr.makeNullCheck(tree.getQualifierExpression());
            break;
        case UNBOUND:
            // The receiver is the first parameter, extract it and
            // adjust the SAM and unerased type lists accordingly
            rcvr = addParameter("rec$", samDesc.getParameterTypes().head, false);
            samPTypes = samPTypes.tail;
            descPTypes = descPTypes.tail;
            break;
        default:
            rcvr = null;
            break;
    }
    List<Type> implPTypes = tree.sym.type.getParameterTypes();
    int implSize = implPTypes.size();
    int samSize = samPTypes.size();
    // Last parameter to copy from referenced method, exclude final var args
    int last = localContext.needsVarArgsConversion() ? implSize - 1 : implSize;

    // Failsafe -- assure match-up
    boolean checkForIntersection = tree.varargsElement != null || implSize == descPTypes.size();

    // Use parameter types of the implementation method unless the unerased
    // SAM parameter type is an intersection type, in that case use the
    // erased SAM parameter type so that the supertype relationship
    // the implementation method parameters is not obscured.
    // Note: in this loop, the lists implPTypes, samPTypes, and descPTypes
    // are used as pointers to the current parameter type information
    // and are thus not usable afterwards.
    for (int i = 0; implPTypes.nonEmpty() && i < last; ++i) {
        // By default use the implementation method parmeter type
        Type parmType = implPTypes.head;
        // If the unerased parameter type is a type variable whose
        // bound is an intersection (eg. <T extends A & B>) then
        // use the SAM parameter type
        if (checkForIntersection && descPTypes.head.getKind() == TypeKind.TYPEVAR) {
            TypeVar tv = (TypeVar) descPTypes.head;
            if (tv.bound.getKind() == TypeKind.INTERSECTION) {
                parmType = samPTypes.head;
            }
        }
        addParameter("x$" + i, parmType, true);

        // Advance to the next parameter
        implPTypes = implPTypes.tail;
        samPTypes = samPTypes.tail;
        descPTypes = descPTypes.tail;
    }
    // Flatten out the var args
    for (int i = last; i < samSize; ++i) {
        addParameter("xva$" + i, tree.varargsElement, true);
    }

    return rcvr;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:71,代碼來源:LambdaToMethod.java


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