Search in sources :

Example 1 with TypeArguments

use of org.eclipse.ceylon.compiler.typechecker.tree.Tree.TypeArguments in project ceylon by eclipse.

the class BmeGenerator method createTypeArguments.

/**
 * Create a map with type arguments from the type parameter list in the expression's declaration and the
 *  type argument list in the expression itself.
 */
static Map<TypeParameter, Type> createTypeArguments(final Tree.StaticMemberOrTypeExpression expr) {
    List<TypeParameter> tparams = null;
    Declaration declaration = expr.getDeclaration();
    if (declaration instanceof Generic) {
        tparams = declaration.getTypeParameters();
    } else if (declaration instanceof TypedDeclaration && ((TypedDeclaration) declaration).getType() != null && ((TypedDeclaration) declaration).getType().isTypeConstructor()) {
        tparams = ((TypedDeclaration) declaration).getType().getDeclaration().getTypeParameters();
    } else {
        expr.addUnexpectedError("Getting type parameters from unidentified declaration type " + declaration, Backend.JavaScript);
        return null;
    }
    final HashMap<TypeParameter, Type> targs = new HashMap<>();
    TypeArguments typeArguments = expr.getTypeArguments();
    if (typeArguments != null) {
        List<Type> typeModels = typeArguments.getTypeModels();
        if (typeModels != null) {
            final Iterator<Type> iter = typeModels.iterator();
            for (TypeParameter tp : tparams) {
                Type pt = iter.hasNext() ? iter.next() : tp.getDefaultTypeArgument();
                targs.put(tp, pt);
            }
        }
    }
    return targs;
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Type(org.eclipse.ceylon.model.typechecker.model.Type) HashMap(java.util.HashMap) Generic(org.eclipse.ceylon.model.typechecker.model.Generic) TypeArguments(org.eclipse.ceylon.compiler.typechecker.tree.Tree.TypeArguments) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Aggregations

HashMap (java.util.HashMap)1 TypeArguments (org.eclipse.ceylon.compiler.typechecker.tree.Tree.TypeArguments)1 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)1 Generic (org.eclipse.ceylon.model.typechecker.model.Generic)1 Type (org.eclipse.ceylon.model.typechecker.model.Type)1 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)1 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)1 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)1