use of spoon.Launcher 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.Launcher in project spoon by INRIA.
the class SignatureTest method testArgumentNotNullForExecutableReference.
@Test
public void testArgumentNotNullForExecutableReference() throws Exception {
final Launcher launcher = new Launcher();
launcher.setArgs(new String[] { "--output-type", "nooutput" });
launcher.addInputResource("./src/test/resources/variable/PropPanelUseCase_1.40.java");
launcher.getEnvironment().setNoClasspath(true);
launcher.run();
final List<CtExecutableReference> references = Query.getElements(launcher.getFactory(), new ReferenceTypeFilter<CtExecutableReference>(CtExecutableReference.class) {
@Override
public boolean matches(CtExecutableReference reference) {
return "addField".equals(reference.getSimpleName()) && super.matches(reference);
}
});
assertEquals("addField(<unknown>,<unknown>)", references.get(0).getSignature());
assertEquals("addField(<unknown>,org.argouml.uml.ui.UMLComboBoxNavigator)", references.get(1).getSignature());
for (CtExecutableReference reference : references) {
assertNotEquals("addField(null,null)", reference.getSignature());
}
}
use of spoon.Launcher in project spoon by INRIA.
the class ImplicitStaticFieldReferenceTest method testAmbiguousImplicitFieldReference.
@Test
public void testAmbiguousImplicitFieldReference() throws Exception {
Launcher launcher = checkFile(false, "AmbiguousImplicitFieldReference.java");
if (expectImplicit) {
CtClass<?> cls = launcher.getFactory().Class().get(AmbiguousImplicitFieldReference.class);
assertEquals("return memberField", cls.getMethod("getMemberField").getBody().getStatements().get(0).toString());
assertEquals("memberField = p_memberField", cls.getMethodsByName("setMemberField").get(0).getBody().getStatements().get(0).toString());
// assertEquals("this.memberField = memberField", cls.getMethodsByName("setMemberField2").get(0).getBody().getStatements().get(0).toString());
assertEquals("getMemberField()", cls.getMethodsByName("testLocalMethodInvocations").get(0).getBody().getStatements().get(0).toString());
}
}
use of spoon.Launcher in project spoon by INRIA.
the class ImplicitStaticFieldReferenceTest method testImplicitFieldReference.
@Test
public void testImplicitFieldReference() throws Exception {
Launcher launcher = checkFile(false, "ImplicitFieldReference.java");
if (expectImplicit) {
CtClass<?> cls = launcher.getFactory().Class().get(ImplicitFieldReference.class);
assertEquals("return memberField", cls.getMethod("getMemberField").getBody().getStatements().get(0).toString());
assertEquals("memberField = p_memberField", cls.getMethodsByName("setMemberField").get(0).getBody().getStatements().get(0).toString());
// assertEquals("this.memberField = memberField", cls.getMethodsByName("setMemberField2").get(0).getBody().getStatements().get(0).toString());
assertEquals("getMemberField()", cls.getMethodsByName("testLocalMethodInvocations").get(0).getBody().getStatements().get(0).toString());
}
}
use of spoon.Launcher in project spoon by INRIA.
the class ImplicitStaticFieldReferenceTest method testAmbiguousImplicitFieldReferenceAutoImport.
@Test
public void testAmbiguousImplicitFieldReferenceAutoImport() throws Exception {
Launcher launcher = checkFile(true, "AmbiguousImplicitFieldReference.java");
if (expectImplicit) {
CtClass<?> cls = launcher.getFactory().Class().get(AmbiguousImplicitFieldReference.class);
assertEquals("return memberField", cls.getMethod("getMemberField").getBody().getStatements().get(0).toString());
assertEquals("memberField = p_memberField", cls.getMethodsByName("setMemberField").get(0).getBody().getStatements().get(0).toString());
// assertEquals("this.memberField = memberField", cls.getMethodsByName("setMemberField2").get(0).getBody().getStatements().get(0).toString());
assertEquals("getMemberField()", cls.getMethodsByName("testLocalMethodInvocations").get(0).getBody().getStatements().get(0).toString());
}
}
Aggregations