Search in sources :

Example 1 with ClassType

use of kalang.core.ClassType in project kalang by kasonyang.

the class AstUtil method getUnimplementedMethod.

@Nonnull
public static List<MethodDescriptor> getUnimplementedMethod(ClassNode theClass, ObjectType theInterface) {
    ClassType theType = Types.getClassType(theClass);
    MethodDescriptor[] implementedMethods = theType.getMethodDescriptors(theClass, true, false);
    List<MethodDescriptor> list = new LinkedList();
    for (MethodDescriptor m : theInterface.getMethodDescriptors(theClass, false, true)) {
        if (ModifierUtil.isDefault(m.getModifier()))
            continue;
        String name = m.getName();
        Type[] types = m.getParameterTypes();
        MethodDescriptor overridingMd = MethodUtil.getMethodDescriptor(implementedMethods, name, types);
        if (overridingMd == null || // TODO move check to where method declare
        !OverrideUtil.overridingCompatible(overridingMd.getModifier(), m.getModifier()) || !OverrideUtil.returnTypeCompatible(overridingMd.getReturnType(), m.getReturnType()) || !OverrideUtil.exceptionTypeCompatible(overridingMd.getExceptionTypes(), m.getExceptionTypes())) {
            list.add(m);
        }
    }
    return list;
}
Also used : ArrayType(kalang.core.ArrayType) Type(kalang.core.Type) ObjectType(kalang.core.ObjectType) GenericType(kalang.core.GenericType) ClassType(kalang.core.ClassType) ClassType(kalang.core.ClassType) MethodDescriptor(kalang.core.MethodDescriptor) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull)

Example 2 with ClassType

use of kalang.core.ClassType in project kalang by kasonyang.

the class AstUtil method hasSetter.

public static boolean hasSetter(ClassNode clazz, FieldNode field) {
    ClassType type = Types.getClassType(clazz);
    MethodDescriptor md = MethodUtil.getMethodDescriptor(type.getMethodDescriptors(clazz, true, true), "set" + NameUtil.firstCharToUpperCase(field.getName()), new Type[] { field.getType() });
    return md != null;
}
Also used : ClassType(kalang.core.ClassType) MethodDescriptor(kalang.core.MethodDescriptor)

Example 3 with ClassType

use of kalang.core.ClassType in project kalang by kasonyang.

the class ParameterizedTypeTest method test.

@Test
public void test() throws AstNotFoundException {
    // TODO optimize
    ClassType pt = Types.getClassType(Types.getClassType("java.util.LinkedList").getClassNode(), new Type[] { Types.getIntClassType() });
    ObjectType supType = pt.getSuperType();
    assertTrue(supType instanceof ClassType);
    assertEquals("java.util.AbstractSequentialList<java.lang.Integer>", supType.toString());
// MethodDescriptor[] mds = supType.getMethodDescriptors(null, true,true);
// System.out.print(Arrays.toString(mds));
}
Also used : ObjectType(kalang.core.ObjectType) ClassType(kalang.core.ClassType) Test(org.junit.Test)

Example 4 with ClassType

use of kalang.core.ClassType in project kalang by kasonyang.

the class ClassTypeTest method testEarsedType.

@Test
public void testEarsedType() throws AstNotFoundException {
    AstLoader astLoader = new AstLoader();
    ClassType listType = Types.getClassType(astLoader.loadAst("java.util.List"), new Type[0]);
    ClassType arrayListType = Types.getClassType(astLoader.loadAst("java.util.ArrayList"), new Type[0]);
    assertTrue(arrayListType.isSubTypeOf(listType));
}
Also used : AstLoader(kalang.compiler.AstLoader) ClassType(kalang.core.ClassType) Test(org.junit.Test)

Example 5 with ClassType

use of kalang.core.ClassType in project kalang by kasonyang.

the class Ast2Class method typeSignature.

@Nullable
private String typeSignature(Type type) {
    if (type instanceof GenericType) {
        return "T" + type.getName() + ";";
    } else if (type instanceof ClassType) {
        ClassType pt = (ClassType) type;
        String ptypes = "";
        for (Type p : pt.getTypeArguments()) {
            ptypes += typeSignature(p);
        }
        if (!ptypes.isEmpty())
            ptypes = "<" + ptypes + ">";
        return "L" + pt.getClassNode().name.replace('.', '/') + ptypes + ";";
    } else if (type instanceof PrimitiveType) {
        return getTypeDescriptor(type);
    } else if (type instanceof ArrayType) {
        return "[" + typeSignature(((ArrayType) type).getComponentType());
    } else if (type instanceof WildcardType) {
        WildcardType wt = (WildcardType) type;
        Type[] lbs = wt.getLowerBounds();
        Type[] ubs = wt.getUpperBounds();
        if (lbs.length > 0) {
            // FIXME handle other lowerBounds
            return "-" + typeSignature(lbs[0]);
        } else if (ubs.length > 0) {
            // FIXME handle other lowerBounds
            return "+" + typeSignature(ubs[0]);
        } else {
            return "*";
        }
    } else {
        throw Exceptions.unsupportedTypeException(type);
    }
}
Also used : ArrayType(kalang.core.ArrayType) GenericType(kalang.core.GenericType) Type(kalang.core.Type) GenericType(kalang.core.GenericType) WildcardType(kalang.core.WildcardType) ArrayType(kalang.core.ArrayType) ObjectType(kalang.core.ObjectType) ClassType(kalang.core.ClassType) PrimitiveType(kalang.core.PrimitiveType) WildcardType(kalang.core.WildcardType) PrimitiveType(kalang.core.PrimitiveType) ClassType(kalang.core.ClassType) Nullable(javax.annotation.Nullable)

Aggregations

ClassType (kalang.core.ClassType)10 ObjectType (kalang.core.ObjectType)7 ArrayType (kalang.core.ArrayType)5 GenericType (kalang.core.GenericType)5 Type (kalang.core.Type)5 MethodDescriptor (kalang.core.MethodDescriptor)4 PrimitiveType (kalang.core.PrimitiveType)3 WildcardType (kalang.core.WildcardType)3 Test (org.junit.Test)3 LinkedList (java.util.LinkedList)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 AmbiguousMethodException (kalang.AmbiguousMethodException)1 MethodNotFoundException (kalang.MethodNotFoundException)1 BlockStmt (kalang.ast.BlockStmt)1 ClassNode (kalang.ast.ClassNode)1 ExprStmt (kalang.ast.ExprStmt)1 MethodNode (kalang.ast.MethodNode)1 NewObjectExpr (kalang.ast.NewObjectExpr)1 ObjectInvokeExpr (kalang.ast.ObjectInvokeExpr)1