use of kalang.core.ObjectType in project kalang by kasonyang.
the class ObjectTypeTest method test.
@Test
public void test() throws AstNotFoundException {
ClassType type = Types.getClassType(ObjectTypeTest.class.getName());
ClassNode classNode = type.getClassNode();
ObjectType rootType = Types.getRootType();
ClassNode rootClassNode = rootType.getClassNode();
assertEquals(null, type.getFieldDescriptor(rootClassNode, "privateField"));
assertEquals(null, type.getFieldDescriptor(rootClassNode, "protectedField"));
assertNotEquals(null, type.getFieldDescriptor(rootClassNode, "publicField"));
assertNotEquals(null, type.getFieldDescriptor(classNode, "privateField"));
assertNotEquals(null, type.getFieldDescriptor(classNode, "protectedField"));
assertNotEquals(null, type.getFieldDescriptor(classNode, "publicField"));
}
use of kalang.core.ObjectType in project kalang by kasonyang.
the class Ast2Java method visitClassNode.
@Override
public String visitClassNode(ClassNode node) {
cls = node;
// visit(node.imports).join("\r\n")
String imports = "";
String fs = "";
String mdf = visitModifier(node.modifier);
String pkg = "";
String name = node.name;
int dotIdx = name.lastIndexOf('.');
if (dotIdx > 0) {
pkg = name.substring(0, dotIdx);
name = name.substring(dotIdx + 1);
}
String pkgStr = pkg.length() > 0 ? "package " + pkg + ";" : "";
String parentStr = "";
if (node.getSuperType() != null) {
parentStr = "extends " + node.getSuperType().getName();
}
String impStr = "";
if (node.getInterfaces().length > 0) {
List<String> interfaces = new LinkedList();
for (ObjectType itf : node.getInterfaces()) {
interfaces.add(itf.getName());
}
impStr = "implements " + String.join(",", interfaces);
}
String classType = Modifier.isInterface(node.modifier) ? "interface" : "class";
c(pkgStr + "\r\n" + imports + "\r\n" + mdf + " " + classType + " " + name + " " + parentStr + " " + impStr + " {");
for (FieldNode f : node.getFields()) {
c(this.getVarStr(f) + ";\r\n");
}
visitAll(Arrays.asList(node.getDeclaredMethodNodes()));
c("}");
return null;
}
Aggregations