use of spoon.reflect.declaration.CtType in project spoon by INRIA.
the class ImportTest method testGetImportKindReturnRightValue.
@Test
public void testGetImportKindReturnRightValue() {
// contract: the importKind is computed based on the reference class type and the boolean isImportAllStaticTypeMembers
final Launcher spoon = new Launcher();
CtType aType = spoon.getFactory().Type().get(Reflection.class);
CtImport ctImport = spoon.getFactory().createImport(aType.getReference());
assertEquals(CtImportKind.TYPE, ctImport.getImportKind());
ctImport = spoon.getFactory().createImport(spoon.getFactory().Type().createWildcardStaticTypeMemberReference(aType.getReference()));
assertEquals(CtImportKind.ALL_STATIC_MEMBERS, ctImport.getImportKind());
ctImport = spoon.getFactory().createImport(((CtMethod) aType.getAllMethods().iterator().next()).getReference());
assertEquals(CtImportKind.METHOD, ctImport.getImportKind());
ctImport = spoon.getFactory().createImport(((CtField) aType.getFields().get(0)).getReference());
assertEquals(CtImportKind.FIELD, ctImport.getImportKind());
ctImport = spoon.getFactory().createImport(aType.getPackage().getReference());
assertEquals(CtImportKind.ALL_TYPES, ctImport.getImportKind());
}
use of spoon.reflect.declaration.CtType in project spoon by INRIA.
the class ImportTest method testWithInnerEnumDoesNotImportStaticInnerMethods.
@Test
public void testWithInnerEnumDoesNotImportStaticInnerMethods() {
final Launcher launcher = new Launcher();
launcher.getEnvironment().setAutoImports(true);
String outputDir = "./target/spooned-innerenum";
launcher.addInputResource("./src/test/java/spoon/test/imports/testclasses/StaticImportsFromEnum.java");
launcher.setSourceOutputDirectory(outputDir);
launcher.run();
PrettyPrinter prettyPrinter = launcher.createPrettyPrinter();
CtType element = launcher.getFactory().Class().getAll().get(0);
List<CtType<?>> toPrint = new ArrayList<>();
toPrint.add(element);
prettyPrinter.calculate(element.getPosition().getCompilationUnit(), toPrint);
String output = prettyPrinter.getResult();
assertTrue("The file should not contain a static import to the inner enum method values", !output.contains("import static spoon.test.imports.testclasses.StaticImportsFromEnum$DataElement.values;"));
assertTrue("The file should not contain a static import to the inner enum method values of a distinct interface", !output.contains("import static spoon.test.imports.testclasses.ItfWithEnum$Bar.values;"));
assertTrue("The file should not contain a static import to the inner enum value", !output.contains("import static spoon.test.imports.testclasses.ItfWithEnum$Bar.Lip;"));
canBeBuilt(outputDir, 7);
}
use of spoon.reflect.declaration.CtType in project spoon by INRIA.
the class ImportTest method testShouldNotCreateAutoreference.
@Test
public void testShouldNotCreateAutoreference() {
final Launcher launcher = new Launcher();
launcher.getEnvironment().setAutoImports(false);
String outputDir = "./target/spooned-autoref";
launcher.addInputResource("./src/test/java/spoon/test/imports/testclasses/ShouldNotAutoreference.java");
launcher.setSourceOutputDirectory(outputDir);
launcher.run();
PrettyPrinter prettyPrinter = launcher.createPrettyPrinter();
CtType element = launcher.getFactory().Class().getAll().get(0);
List<CtType<?>> toPrint = new ArrayList<>();
toPrint.add(element);
prettyPrinter.calculate(element.getPosition().getCompilationUnit(), toPrint);
String output = prettyPrinter.getResult();
assertTrue("The file should not contain a static import for NOFOLLOW_LINKS", !output.contains("import static java.nio.file.LinkOption.NOFOLLOW_LINKS;"));
canBeBuilt(outputDir, 7);
}
use of spoon.reflect.declaration.CtType in project spoon by INRIA.
the class SignatureTest method testBugSignature.
@Test
public void testBugSignature() throws Exception {
// contract: two methods with same name and return type yet different argument types
// must have different signatures
Launcher launcher = new Launcher();
launcher.getEnvironment().setNoClasspath(true);
SpoonModelBuilder comp = launcher.createCompiler();
comp.addInputSources(SpoonResourceHelper.resources("./src/main/java/spoon/SpoonModelBuilder.java"));
comp.build();
CtType<?> ctClass = (CtType<?>) comp.getFactory().Type().get(SpoonModelBuilder.class);
List<CtMethod> methods = ctClass.getElements(new NamedElementFilter<>(CtMethod.class, "addInputSource"));
assertEquals(2, methods.size());
CtMethod<?> method = methods.get(0);
assertEquals("addInputSource(java.io.File)", method.getSignature());
CtMethod<?> method2 = methods.get(1);
assertEquals("addInputSource(spoon.compiler.SpoonResource)", method2.getSignature());
assertNotEquals(method, method2);
}
use of spoon.reflect.declaration.CtType in project spoon by INRIA.
the class MetaModelTest method testGetRoleHandlersOfClass.
@Test
public void testGetRoleHandlersOfClass() {
int countOfIfaces = 0;
for (CtType spoonIface : Metamodel.getAllMetamodelInterfaces()) {
countOfIfaces++;
checkRoleHandlersOfType(spoonIface);
}
assertTrue(countOfIfaces > 10);
}
Aggregations