Search in sources :

Example 96 with Launcher

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);
}
Also used : SpoonModelBuilder(spoon.SpoonModelBuilder) CtType(spoon.reflect.declaration.CtType) Launcher(spoon.Launcher) CtMethod(spoon.reflect.declaration.CtMethod) Test(org.junit.Test)

Example 97 with Launcher

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());
    }
}
Also used : Launcher(spoon.Launcher) CtExecutableReference(spoon.reflect.reference.CtExecutableReference) Test(org.junit.Test)

Example 98 with Launcher

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());
    }
}
Also used : Launcher(spoon.Launcher) Test(org.junit.Test)

Example 99 with Launcher

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());
    }
}
Also used : Launcher(spoon.Launcher) Test(org.junit.Test)

Example 100 with Launcher

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());
    }
}
Also used : Launcher(spoon.Launcher) Test(org.junit.Test)

Aggregations

Launcher (spoon.Launcher)524 Test (org.junit.Test)486 Factory (spoon.reflect.factory.Factory)163 CtClass (spoon.reflect.declaration.CtClass)111 CtMethod (spoon.reflect.declaration.CtMethod)79 File (java.io.File)75 CtType (spoon.reflect.declaration.CtType)66 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)60 CtTypeReference (spoon.reflect.reference.CtTypeReference)48 SpoonModelBuilder (spoon.SpoonModelBuilder)44 ArrayList (java.util.ArrayList)43 CtAnnotation (spoon.reflect.declaration.CtAnnotation)38 CtInvocation (spoon.reflect.code.CtInvocation)32 CtElement (spoon.reflect.declaration.CtElement)27 CtPackage (spoon.reflect.declaration.CtPackage)27 FileSystemFile (spoon.support.compiler.FileSystemFile)26 CtStatement (spoon.reflect.code.CtStatement)25 CtField (spoon.reflect.declaration.CtField)24 NamedElementFilter (spoon.reflect.visitor.filter.NamedElementFilter)24 SpoonAPI (spoon.SpoonAPI)22