use of spoon.reflect.declaration.CtPackage in project spoon by INRIA.
the class TestCompilationUnit method testGetUnitTypeWorksWithCreatedObjects.
@Test
public void testGetUnitTypeWorksWithCreatedObjects() {
final Launcher launcher = new Launcher();
CtPackage myPackage = launcher.getFactory().Package().getOrCreate("my.package");
CompilationUnit cu = launcher.getFactory().createCompilationUnit();
assertEquals(CompilationUnit.UNIT_TYPE.UNKNOWN, cu.getUnitType());
cu.setDeclaredPackage(myPackage);
assertEquals(CompilationUnit.UNIT_TYPE.PACKAGE_DECLARATION, cu.getUnitType());
cu.setDeclaredTypes(Collections.singletonList(launcher.getFactory().createClass()));
assertEquals(CompilationUnit.UNIT_TYPE.TYPE_DECLARATION, cu.getUnitType());
}
use of spoon.reflect.declaration.CtPackage in project spoon by INRIA.
the class CtPackageImpl method addPackage.
@Override
public <T extends CtPackage> T addPackage(CtPackage pack) {
if (pack == null) {
return (T) this;
}
if (packs == CtElementImpl.<CtPackage>emptySet()) {
this.packs = orderedPackageSet();
}
// they are the same
if (this.getQualifiedName().equals(pack.getQualifiedName())) {
addAllTypes(pack, this);
addAllPackages(pack, this);
return (T) this;
}
// it already exists
for (CtPackage p1 : packs) {
if (p1.getQualifiedName().equals(pack.getQualifiedName())) {
addAllTypes(pack, p1);
addAllPackages(pack, p1);
return (T) this;
}
}
pack.setParent(this);
getFactory().getEnvironment().getModelChangeListener().onSetAdd(this, SUB_PACKAGE, this.packs, pack);
this.packs.add(pack);
return (T) this;
}
use of spoon.reflect.declaration.CtPackage in project spoon by INRIA.
the class CloneVisitorGenerator method createCloneVisitor.
private CtClass<Object> createCloneVisitor() {
final CtPackage aPackage = getFactory().Package().getOrCreate(TARGET_CLONE_PACKAGE);
final CtClass<Object> target = getFactory().Class().get(GENERATING_CLONE);
target.setSimpleName(TARGET_CLONE_TYPE);
target.addModifier(ModifierKind.PUBLIC);
aPackage.addType(target);
final List<CtTypeReference> references = target.getElements(new TypeFilter<CtTypeReference>(CtTypeReference.class) {
@Override
public boolean matches(CtTypeReference reference) {
return GENERATING_CLONE.equals(reference.getQualifiedName());
}
});
for (CtTypeReference reference : references) {
reference.setSimpleName(TARGET_CLONE_TYPE);
reference.setPackage(aPackage.getReference());
}
target.getConstructors().forEach(c -> c.addModifier(ModifierKind.PUBLIC));
return target;
}
use of spoon.reflect.declaration.CtPackage in project spoon by INRIA.
the class CtBiScannerGenerator method createBiScanner.
private CtClass<Object> createBiScanner() {
final CtPackage aPackage = getFactory().Package().getOrCreate(TARGET_BISCANNER_PACKAGE);
final CtClass<Object> target = getFactory().Class().get(GENERATING_BISCANNER);
target.setSimpleName("CtBiScannerDefault");
target.addModifier(ModifierKind.PUBLIC);
aPackage.addType(target);
target.addComment(getFactory().Code().createComment("autogenerated by " + getClass().getSimpleName(), CtComment.CommentType.INLINE));
final List<CtTypeReference> references = target.getElements(new TypeFilter<CtTypeReference>(CtTypeReference.class) {
@Override
public boolean matches(CtTypeReference reference) {
return GENERATING_BISCANNER.equals(reference.getQualifiedName());
}
});
for (CtTypeReference reference : references) {
reference.setSimpleName("CtBiScannerDefault");
reference.setPackage(aPackage.getReference());
}
return target;
}
use of spoon.reflect.declaration.CtPackage in project spoon by INRIA.
the class ReplacementVisitorGenerator method createReplacementVisitor.
private CtClass<Object> createReplacementVisitor() {
final CtPackage aPackage = getFactory().Package().getOrCreate(TARGET_REPLACE_PACKAGE);
final CtClass<Object> target = getFactory().Class().get(GENERATING_REPLACE_VISITOR);
target.addModifier(ModifierKind.PUBLIC);
aPackage.addType(target);
final List<CtTypeReference> references = target.getElements(new TypeFilter<CtTypeReference>(CtTypeReference.class) {
@Override
public boolean matches(CtTypeReference reference) {
return GENERATING_REPLACE_VISITOR.equals(reference.getQualifiedName());
}
});
for (CtTypeReference reference : references) {
reference.setPackage(aPackage.getReference());
}
return target;
}
Aggregations