Java Code Examples for com.sun.tools.javac.code.Type#allparams()

The following examples show how to use com.sun.tools.javac.code.Type#allparams() . 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: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Enter all interfaces of type `type' into the hash table `seensofar'
 *  with their class symbol as key and their type as value. Make
 *  sure no class is entered with two different types.
 */
void checkClassBounds(DiagnosticPosition pos,
                      Map<TypeSymbol,Type> seensofar,
                      Type type) {
    if (type.isErroneous()) return;
    for (List<Type> l = types.interfaces(type); l.nonEmpty(); l = l.tail) {
        Type it = l.head;
        Type oldit = seensofar.put(it.tsym, it);
        if (oldit != null) {
            List<Type> oldparams = oldit.allparams();
            List<Type> newparams = it.allparams();
            if (!types.containsTypeEquivalent(oldparams, newparams))
                log.error(pos,
                          Errors.CantInheritDiffArg(it.tsym,
                                                    Type.toString(oldparams),
                                                    Type.toString(newparams)));
        }
        checkClassBounds(pos, seensofar, it);
    }
    Type st = types.supertype(type);
    if (st != Type.noType) checkClassBounds(pos, seensofar, st);
}
 
Example 2
Source File: JavacResolution.java    From EasyMPermission with MIT License 5 votes vote down vote up
public static Type ifTypeIsIterableToComponent(Type type, JavacAST ast) {
		Types types = Types.instance(ast.getContext());
		Symtab syms = Symtab.instance(ast.getContext());
		Type boundType = ReflectiveAccess.Types_upperBound(types, type);
//		Type boundType = types.upperBound(type);
		Type elemTypeIfArray = types.elemtype(boundType);
		if (elemTypeIfArray != null) return elemTypeIfArray;
		
		Type base = types.asSuper(boundType, syms.iterableType.tsym);
		if (base == null) return syms.objectType;
		
		List<Type> iterableParams = base.allparams();
		return iterableParams.isEmpty() ? syms.objectType : ReflectiveAccess.Types_upperBound(types, iterableParams.head);
	}
 
Example 3
Source File: Check.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private Type firstIncompatibleTypeArg(Type type) {
    List<Type> formals = type.tsym.type.allparams();
    List<Type> actuals = type.allparams();
    List<Type> args = type.getTypeArguments();
    List<Type> forms = type.tsym.type.getTypeArguments();
    ListBuffer<Type> bounds_buf = new ListBuffer<>();

    // For matching pairs of actual argument types `a' and
    // formal type parameters with declared bound `b' ...
    while (args.nonEmpty() && forms.nonEmpty()) {
        // exact type arguments needs to know their
        // bounds (for upper and lower bound
        // calculations).  So we create new bounds where
        // type-parameters are replaced with actuals argument types.
        bounds_buf.append(types.subst(forms.head.getUpperBound(), formals, actuals));
        args = args.tail;
        forms = forms.tail;
    }

    args = type.getTypeArguments();
    List<Type> tvars_cap = types.substBounds(formals,
                              formals,
                              types.capture(type).allparams());
    while (args.nonEmpty() && tvars_cap.nonEmpty()) {
        // Let the actual arguments know their bound
        args.head.withTypeVar((TypeVar)tvars_cap.head);
        args = args.tail;
        tvars_cap = tvars_cap.tail;
    }

    args = type.getTypeArguments();
    List<Type> bounds = bounds_buf.toList();

    while (args.nonEmpty() && bounds.nonEmpty()) {
        Type actual = args.head;
        if (!isTypeArgErroneous(actual) &&
                !bounds.head.isErroneous() &&
                !checkExtends(actual, bounds.head)) {
            return args.head;
        }
        args = args.tail;
        bounds = bounds.tail;
    }

    args = type.getTypeArguments();
    bounds = bounds_buf.toList();

    for (Type arg : types.capture(type).getTypeArguments()) {
        if (arg.hasTag(TYPEVAR) &&
                arg.getUpperBound().isErroneous() &&
                !bounds.head.isErroneous() &&
                !isTypeArgErroneous(args.head)) {
            return args.head;
        }
        bounds = bounds.tail;
        args = args.tail;
    }

    return null;
}