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;
}
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;
}
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));
}
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));
}
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);
}
}
Aggregations