Search in sources :

Example 1 with ListOfTypes

use of org.robovm.compiler.util.generic.ListOfTypes in project robovm by robovm.

the class ObjCBlockPlugin method resolveMethodType.

/**
     * 
     */
private static Type resolveMethodType(SootMethod blockMethod, int paramIndex, Type t, Type[] resolvedArgs, TypeVariable<?>[] typeParameters) {
    if (t instanceof SootClassType) {
        return t;
    }
    if (t instanceof SootTypeType) {
        return t;
    }
    if (t instanceof TypeVariable) {
        int idx = indexOf(((TypeVariable<?>) t).getName(), typeParameters);
        if (idx != -1) {
            Type u = resolvedArgs[idx];
            if (u instanceof TypeVariable) {
                if (((TypeVariable<?>) t).getName().equals(((TypeVariable<?>) u).getName())) {
                    return resolveMethodType(blockMethod, paramIndex, ((TypeVariable<?>) t).getBounds()[0], resolvedArgs, typeParameters);
                }
            }
            return resolveMethodType(blockMethod, paramIndex, resolvedArgs[idx], resolvedArgs, typeParameters);
        }
        throw new CompilerException("Unresolved type variable " + t + " in " + (paramIndex == -1 ? "return type" : "parameter " + (paramIndex + 1)) + " of @Block method " + blockMethod);
    }
    if (t instanceof WildcardType) {
        Type[] upperBounds = ((WildcardType) t).getUpperBounds();
        return resolveMethodType(blockMethod, paramIndex, upperBounds[0], resolvedArgs, typeParameters);
    }
    if (t instanceof ParameterizedType) {
        ImplForType pType = (ImplForType) t;
        ListOfTypes types = new ListOfTypes(pType.getActualTypeArguments().length);
        for (Type arg : pType.getActualTypeArguments()) {
            types.add(resolveMethodType(blockMethod, paramIndex, arg, resolvedArgs, typeParameters));
        }
        return new ImplForType((ImplForType) pType.getOwnerType(), pType.getRawType().getSootClass().getName(), types);
    }
    if (t instanceof GenericArrayType) {
        Type componentType = resolveMethodType(blockMethod, paramIndex, ((GenericArrayType) t).getGenericComponentType(), resolvedArgs, typeParameters);
        return new ImplForArray(componentType);
    }
    throw new CompilerException("Unresolved type " + t + " in " + (paramIndex == -1 ? "return type" : "parameter " + (paramIndex + 1)) + " of @Block method " + blockMethod);
}
Also used : SootClassType(org.robovm.compiler.util.generic.SootClassType) GenericArrayType(org.robovm.compiler.util.generic.GenericArrayType) ParameterizedType(org.robovm.compiler.util.generic.ParameterizedType) ImplForArray(org.robovm.compiler.util.generic.ImplForArray) SootTypeType(org.robovm.compiler.util.generic.SootTypeType) RefType(soot.RefType) ShortType(soot.ShortType) BooleanType(soot.BooleanType) SootTypeType(org.robovm.compiler.util.generic.SootTypeType) WildcardType(org.robovm.compiler.util.generic.WildcardType) SootMethodType(org.robovm.compiler.util.generic.SootMethodType) SootClassType(org.robovm.compiler.util.generic.SootClassType) ByteType(soot.ByteType) Type(org.robovm.compiler.util.generic.Type) DoubleType(soot.DoubleType) GenericArrayType(org.robovm.compiler.util.generic.GenericArrayType) FloatType(soot.FloatType) IntType(soot.IntType) ImplForType(org.robovm.compiler.util.generic.ImplForType) CharType(soot.CharType) LongType(soot.LongType) ParameterizedType(org.robovm.compiler.util.generic.ParameterizedType) PrimType(soot.PrimType) VoidType(soot.VoidType) WildcardType(org.robovm.compiler.util.generic.WildcardType) TypeVariable(org.robovm.compiler.util.generic.TypeVariable) CompilerException(org.robovm.compiler.CompilerException) ListOfTypes(org.robovm.compiler.util.generic.ListOfTypes) ImplForType(org.robovm.compiler.util.generic.ImplForType)

Example 2 with ListOfTypes

use of org.robovm.compiler.util.generic.ListOfTypes in project robovm by robovm.

the class ObjCBlockPlugin method resolveParameterizedType.

/**
     * Loops through all type arguments and replaces type variables with the
     * actually known types.
     */
private static ParameterizedType resolveParameterizedType(ParameterizedType parameterizedType, Map<String, Type> typeVariables) {
    List<Type> resolvedTypes = new LinkedList<Type>();
    for (Type t : parameterizedType.getActualTypeArguments()) {
        if (t instanceof TypeVariable<?>) {
            Type resolvedType = typeVariables.get(((TypeVariable<?>) t).getName());
            if (resolvedType instanceof ParameterizedType) {
                resolvedType = resolveParameterizedType((ParameterizedType) resolvedType, typeVariables);
            }
            resolvedTypes.add(resolvedType != null ? resolvedType : t);
        } else if (t instanceof ParameterizedType) {
            ParameterizedType pType = (ParameterizedType) t;
            resolvedTypes.add(resolveParameterizedType(pType, typeVariables));
        } else {
            resolvedTypes.add(t);
        }
    }
    ListOfTypes types = new ListOfTypes(resolvedTypes.toArray(new Type[resolvedTypes.size()]));
    return new ImplForType(null, parameterizedType.getRawType().toString(), types);
}
Also used : ParameterizedType(org.robovm.compiler.util.generic.ParameterizedType) RefType(soot.RefType) ShortType(soot.ShortType) BooleanType(soot.BooleanType) SootTypeType(org.robovm.compiler.util.generic.SootTypeType) WildcardType(org.robovm.compiler.util.generic.WildcardType) SootMethodType(org.robovm.compiler.util.generic.SootMethodType) SootClassType(org.robovm.compiler.util.generic.SootClassType) ByteType(soot.ByteType) Type(org.robovm.compiler.util.generic.Type) DoubleType(soot.DoubleType) GenericArrayType(org.robovm.compiler.util.generic.GenericArrayType) FloatType(soot.FloatType) IntType(soot.IntType) ImplForType(org.robovm.compiler.util.generic.ImplForType) CharType(soot.CharType) LongType(soot.LongType) ParameterizedType(org.robovm.compiler.util.generic.ParameterizedType) PrimType(soot.PrimType) VoidType(soot.VoidType) TypeVariable(org.robovm.compiler.util.generic.TypeVariable) ListOfTypes(org.robovm.compiler.util.generic.ListOfTypes) ImplForType(org.robovm.compiler.util.generic.ImplForType) LinkedList(java.util.LinkedList)

Aggregations

GenericArrayType (org.robovm.compiler.util.generic.GenericArrayType)2 ImplForType (org.robovm.compiler.util.generic.ImplForType)2 ListOfTypes (org.robovm.compiler.util.generic.ListOfTypes)2 ParameterizedType (org.robovm.compiler.util.generic.ParameterizedType)2 SootClassType (org.robovm.compiler.util.generic.SootClassType)2 SootMethodType (org.robovm.compiler.util.generic.SootMethodType)2 SootTypeType (org.robovm.compiler.util.generic.SootTypeType)2 Type (org.robovm.compiler.util.generic.Type)2 TypeVariable (org.robovm.compiler.util.generic.TypeVariable)2 WildcardType (org.robovm.compiler.util.generic.WildcardType)2 BooleanType (soot.BooleanType)2 ByteType (soot.ByteType)2 CharType (soot.CharType)2 DoubleType (soot.DoubleType)2 FloatType (soot.FloatType)2 IntType (soot.IntType)2 LongType (soot.LongType)2 PrimType (soot.PrimType)2 RefType (soot.RefType)2 ShortType (soot.ShortType)2