use of spoon.support.visitor.java.internal.PackageRuntimeBuilderContext in project spoon by INRIA.
the class JavaReflectionTreeBuilder method scan.
/**
* transforms a java.lang.Class into a CtType (ie a shadow type in Spoon's parlance)
*/
public <T, R extends CtType<T>> R scan(Class<T> clazz) {
CtPackage ctPackage;
CtType<?> ctEnclosingClass;
if (clazz.getEnclosingClass() != null) {
ctEnclosingClass = scan(clazz.getEnclosingClass());
return ctEnclosingClass.getNestedType(clazz.getSimpleName());
} else {
if (clazz.getPackage() == null) {
ctPackage = factory.Package().getRootPackage();
} else {
ctPackage = factory.Package().getOrCreate(clazz.getPackage().getName());
}
if (contexts.isEmpty()) {
enter(new PackageRuntimeBuilderContext(ctPackage));
}
if (clazz.isAnnotation()) {
visitAnnotationClass((Class<Annotation>) clazz);
} else if (clazz.isInterface()) {
visitInterface(clazz);
} else if (clazz.isEnum()) {
visitEnum(clazz);
} else {
visitClass(clazz);
}
exit();
final R type = ctPackage.getType(clazz.getSimpleName());
if (clazz.isPrimitive() && type.getParent() instanceof CtPackage) {
// primitive type isn't in a package.
type.setParent(null);
}
return type;
}
}
use of spoon.support.visitor.java.internal.PackageRuntimeBuilderContext in project spoon by INRIA.
the class JavaReflectionTreeBuilder method visitPackage.
@Override
public void visitPackage(Package aPackage) {
final CtPackage ctPackage = factory.Package().getOrCreate(aPackage.getName());
enter(new PackageRuntimeBuilderContext(ctPackage));
super.visitPackage(aPackage);
exit();
contexts.peek().addPackage(ctPackage);
}
Aggregations