Java Code Examples for com.sun.tools.javac.util.List#map()

The following examples show how to use com.sun.tools.javac.util.List#map() . 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: VarTypePrinter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Type visitClassType(ClassType t, Boolean upward) {
    if (upward && !t.isCompound() && t.tsym.name.isEmpty()) {
        //lift anonymous class type to first supertype (class or interface)
        return types.directSupertypes(t).last();
    } else if (t.isCompound()) {
        List<Type> components = types.directSupertypes(t);
        List<Type> components1 = components.map(c -> c.map(this, upward));
        if (components == components1) return t;
        else return types.makeIntersectionType(components1);
    } else {
        Type outer = t.getEnclosingType();
        Type outer1 = visit(outer, upward);
        List<Type> typarams = t.getTypeArguments();
        List<Type> typarams1 = typarams.map(ta -> mapTypeArgument(ta, upward));
        if (typarams1.stream().anyMatch(ta -> ta.hasTag(BOT))) {
            //not defined
            return syms.botType;
        }
        if (outer1 == outer && typarams1 == typarams) return t;
        else return new ClassType(outer1, typarams1, t.tsym, t.getMetadata()) {
            @Override
            protected boolean needsStripping() {
                return true;
            }
        };
    }
}
 
Example 2
Source File: Infer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Compute a synthetic method type corresponding to the requested polymorphic
 * method signature. The target return type is computed from the immediately
 * enclosing scope surrounding the polymorphic-signature call.
 */
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env,
                                        MethodSymbol spMethod,  // sig. poly. method or null if none
                                        Resolve.MethodResolutionContext resolveContext,
                                        List<Type> argtypes) {
    final Type restype;

    if (spMethod == null || types.isSameType(spMethod.getReturnType(), syms.objectType, true)) {
        // The return type of the polymorphic signature is polymorphic,
        // and is computed from the enclosing tree E, as follows:
        // if E is a cast, then use the target type of the cast expression
        // as a return type; if E is an expression statement, the return
        // type is 'void'; otherwise
        // the return type is simply 'Object'. A correctness check ensures
        // that env.next refers to the lexically enclosing environment in
        // which the polymorphic signature call environment is nested.

        switch (env.next.tree.getTag()) {
            case TYPECAST:
                JCTypeCast castTree = (JCTypeCast)env.next.tree;
                restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
                          castTree.clazz.type :
                          syms.objectType;
                break;
            case EXEC:
                JCTree.JCExpressionStatement execTree =
                        (JCTree.JCExpressionStatement)env.next.tree;
                restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
                          syms.voidType :
                          syms.objectType;
                break;
            default:
                restype = syms.objectType;
        }
    } else {
        // The return type of the polymorphic signature is fixed
        // (not polymorphic)
        restype = spMethod.getReturnType();
    }

    List<Type> paramtypes = argtypes.map(new ImplicitArgType(spMethod, resolveContext.step));
    List<Type> exType = spMethod != null ?
        spMethod.getThrownTypes() :
        List.of(syms.throwableType); // make it throw all exceptions

    MethodType mtype = new MethodType(paramtypes,
                                      restype,
                                      exType,
                                      syms.methodClass);
    return mtype;
}
 
Example 3
Source File: InferenceContext.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public InferenceContext(Infer infer, List<Type> inferencevars) {
    this(infer, inferencevars, inferencevars.map(infer.fromTypeVarFun));
}
 
Example 4
Source File: Infer.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Compute a synthetic method type corresponding to the requested polymorphic
 * method signature. The target return type is computed from the immediately
 * enclosing scope surrounding the polymorphic-signature call.
 */
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env,
                                        MethodSymbol spMethod,  // sig. poly. method or null if none
                                        Resolve.MethodResolutionContext resolveContext,
                                        List<Type> argtypes) {
    final Type restype;

    if (spMethod == null || types.isSameType(spMethod.getReturnType(), syms.objectType, true)) {
        // The return type of the polymorphic signature is polymorphic,
        // and is computed from the enclosing tree E, as follows:
        // if E is a cast, then use the target type of the cast expression
        // as a return type; if E is an expression statement, the return
        // type is 'void'; otherwise
        // the return type is simply 'Object'. A correctness check ensures
        // that env.next refers to the lexically enclosing environment in
        // which the polymorphic signature call environment is nested.

        switch (env.next.tree.getTag()) {
            case TYPECAST:
                JCTypeCast castTree = (JCTypeCast)env.next.tree;
                restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
                          castTree.clazz.type :
                          syms.objectType;
                break;
            case EXEC:
                JCTree.JCExpressionStatement execTree =
                        (JCTree.JCExpressionStatement)env.next.tree;
                restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
                          syms.voidType :
                          syms.objectType;
                break;
            default:
                restype = syms.objectType;
        }
    } else {
        // The return type of the polymorphic signature is fixed
        // (not polymorphic)
        restype = spMethod.getReturnType();
    }

    List<Type> paramtypes = argtypes.map(new ImplicitArgType(spMethod, resolveContext.step));
    List<Type> exType = spMethod != null ?
        spMethod.getThrownTypes() :
        List.of(syms.throwableType); // make it throw all exceptions

    MethodType mtype = new MethodType(paramtypes,
                                      restype,
                                      exType,
                                      syms.methodClass);
    return mtype;
}
 
Example 5
Source File: InferenceContext.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public InferenceContext(Infer infer, List<Type> inferencevars) {
    this(infer, inferencevars, inferencevars.map(infer.fromTypeVarFun));
}