use of kalang.ast.ClassNode in project kalang by kasonyang.
the class JavaAstLoader method buildFromClass.
/**
* build ast from java class
*
* @param clz the java class
* @return the ast built from java class
* @throws AstNotFoundException
*/
@Nonnull
public ClassNode buildFromClass(@Nonnull Class clz) throws AstNotFoundException {
ClassNode cn = new JvmClassNode(clz, this);
loadedClasses.put(clz.getName(), cn);
return cn;
}
use of kalang.ast.ClassNode in project kalang by kasonyang.
the class JavaAstLoader method findAst.
public ClassNode findAst(Class clazz) throws AstNotFoundException {
String name = clazz.getName();
ClassNode ast = loadedClasses.get(name);
if (ast != null) {
return ast;
}
return buildFromClass(clazz);
}
use of kalang.ast.ClassNode in project kalang by kasonyang.
the class KalangCompiler method findAst.
@Override
protected ClassNode findAst(@Nonnull String className) throws AstNotFoundException {
String[] classNameInfo = className.split("\\$", 2);
String topClassName = classNameInfo[0];
if (compilationUnits.containsKey(topClassName)) {
CompilationUnit compilationUnit = compilationUnits.get(topClassName);
ClassNode clazz = compilationUnit.getAst();
if (classNameInfo.length == 1) {
return clazz;
} else {
ClassNode c = findInnerClass(clazz, className);
if (c != null) {
return c;
}
}
}
SourceLoader srcLoader = getSourceLoader();
if (srcLoader != null) {
KalangSource source = srcLoader.loadSource(className);
if (source != null) {
return createCompilationUnit(source).getAst();
}
}
return super.findAst(className);
}
use of kalang.ast.ClassNode in project kalang by kasonyang.
the class AstUtil method createClassNodeWithInterfaces.
public static ClassNode createClassNodeWithInterfaces(String name, @Nullable ObjectType superType, @Nullable ObjectType... interfaces) {
ClassNode cn = new ClassNode();
cn.name = name;
cn.setSuperType(superType == null ? Types.getRootType() : superType);
if (interfaces != null) {
for (ObjectType itf : interfaces) cn.addInterface(itf);
}
return cn;
}
use of kalang.ast.ClassNode 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"));
}
Aggregations