Java Code Examples for javax.lang.model.type.TypeKind#INTERSECTION

The following examples show how to use javax.lang.model.type.TypeKind#INTERSECTION . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LambdaToMethod.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: LambdaToMethod.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: LambdaToMethod.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: TooStrongCast.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 5
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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;
}
 
Example 6
Source File: ConvertVarToExplicitType.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean isValidType(HintContext ctx) {
    TreePath treePath = ctx.getPath();
    TreePath initTreePath = ctx.getVariables().get("$init");  //NOI18N
    TreePath expressionTreePath = ctx.getVariables().get("$expression"); //NOI18N
    if (initTreePath != null) {
        TypeMirror variableTypeMirror = ctx.getInfo().getTrees().getElement(treePath).asType();
        if (Utilities.isAnonymousType(variableTypeMirror)) {
            return false;
        } else if (variableTypeMirror.getKind() == TypeKind.DECLARED) {
            DeclaredType dt = (DeclaredType) variableTypeMirror;
            if (dt.getTypeArguments().size() > 0) {
                for (TypeMirror paramType : dt.getTypeArguments()) {
                    if (Utilities.isAnonymousType(paramType)) {
                        return false;
                    }
                }
            }
        }

        if (!Utilities.isValidType(variableTypeMirror) || (variableTypeMirror.getKind() == TypeKind.INTERSECTION)) {
            return false;
        }
        return true;
    } else if (expressionTreePath != null) {
        ExecutableElement iterator = ExpandEnhancedForLoop.findIterable(ctx.getInfo());
        return (iterator != null);
    } else {
        return false;
    }
}
 
Example 7
Source File: Lambda.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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;
    }
}
 
Example 8
Source File: TypeUtils.java    From Mixin with MIT License 5 votes vote down vote up
private static TypeMirror toRawType(ProcessingEnvironment processingEnv, DeclaredType targetType) {
    if (targetType.getKind() == TypeKind.INTERSECTION) {
        return targetType;
    }
    Name qualifiedName = ((TypeElement)targetType.asElement()).getQualifiedName();
    TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(qualifiedName);
    return typeElement != null ? typeElement.asType() : targetType;
}
 
Example 9
Source File: LambdaToMethod.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 10
Source File: LambdaToMethod.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 11
Source File: TypeUtil.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public static boolean isIntersection(TypeMirror t) {
  return t.getKind() == TypeKind.INTERSECTION;
}
 
Example 12
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * 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;
}
 
Example 13
Source File: TypeUtilities.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 14
Source File: Utilities.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 15
Source File: LambdaToMethod.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 16
Source File: LambdaToMethod.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 17
Source File: StandaloneIntersectionType.java    From buck with Apache License 2.0 4 votes vote down vote up
public StandaloneIntersectionType(List<? extends TypeMirror> bounds) {
  super(TypeKind.INTERSECTION);

  this.bounds = Collections.unmodifiableList(new ArrayList<>(bounds));
}
 
Example 18
Source File: LambdaToMethod.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 19
Source File: LambdaToMethod.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 20
Source File: TurbineTypeMirror.java    From turbine with Apache License 2.0 4 votes vote down vote up
@Override
public TypeKind getKind() {
  return TypeKind.INTERSECTION;
}