当前位置: 首页>>代码示例>>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;未经允许,请勿转载。