Search in sources :

Example 1 with PackageRuntimeBuilderContext

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;
    }
}
Also used : PackageRuntimeBuilderContext(spoon.support.visitor.java.internal.PackageRuntimeBuilderContext) CtPackage(spoon.reflect.declaration.CtPackage) CtAnnotation(spoon.reflect.declaration.CtAnnotation) Annotation(java.lang.annotation.Annotation)

Example 2 with PackageRuntimeBuilderContext

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);
}
Also used : PackageRuntimeBuilderContext(spoon.support.visitor.java.internal.PackageRuntimeBuilderContext) CtPackage(spoon.reflect.declaration.CtPackage)

Aggregations

CtPackage (spoon.reflect.declaration.CtPackage)2 PackageRuntimeBuilderContext (spoon.support.visitor.java.internal.PackageRuntimeBuilderContext)2 Annotation (java.lang.annotation.Annotation)1 CtAnnotation (spoon.reflect.declaration.CtAnnotation)1