Search in sources :

Example 21 with CtMethod

use of spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.

the class AmplificationHelper method getTopParent.

public static CtMethod getTopParent(CtMethod test) {
    CtMethod topParent;
    CtMethod currentTest = test;
    while ((topParent = getAmpTestParent(currentTest)) != null) {
        currentTest = topParent;
    }
    return currentTest;
}
Also used : CtMethod(spoon.reflect.declaration.CtMethod)

Example 22 with CtMethod

use of spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.

the class AmplificationHelper method cloneTestMethod.

/**
 * Clones a test method.
 *
 * Performs necessary integration with JUnit and adds timeout.
 *
 * @param method Method to be cloned
 * @param suffix Suffix for the cloned method's name
 * @return The cloned method
 */
private static CtMethod cloneTestMethod(CtMethod method, String suffix) {
    CtMethod cloned_method = cloneMethod(method, suffix);
    CtAnnotation testAnnotation = cloned_method.getAnnotations().stream().filter(annotation -> annotation.toString().contains("Test")).findFirst().orElse(null);
    if (testAnnotation != null) {
        cloned_method.removeAnnotation(testAnnotation);
    }
    testAnnotation = method.getFactory().Core().createAnnotation();
    CtTypeReference<Object> ref = method.getFactory().Core().createTypeReference();
    ref.setSimpleName("Test");
    CtPackageReference refPackage = method.getFactory().Core().createPackageReference();
    refPackage.setSimpleName("org.junit");
    ref.setPackage(refPackage);
    testAnnotation.setAnnotationType(ref);
    Map<String, Object> elementValue = new HashMap<>();
    elementValue.put("timeout", timeOutInMs);
    testAnnotation.setElementValues(elementValue);
    cloned_method.addAnnotation(testAnnotation);
    cloned_method.addThrownType(method.getFactory().Type().createReference(Exception.class));
    return cloned_method;
}
Also used : CtAnnotation(spoon.reflect.declaration.CtAnnotation) CtPackageReference(spoon.reflect.reference.CtPackageReference) CtMethod(spoon.reflect.declaration.CtMethod)

Example 23 with CtMethod

use of spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.

the class AmplificationHelper method cloneMethod.

/**
 * Clones a method.
 *
 * @param method Method to be cloned
 * @param suffix Suffix for the cloned method's name
 * @return The cloned method
 */
private static CtMethod cloneMethod(CtMethod method, String suffix) {
    CtMethod cloned_method = method.clone();
    // rename the clone
    cloned_method.setSimpleName(method.getSimpleName() + (suffix.isEmpty() ? "" : suffix + cloneNumber));
    cloneNumber++;
    CtAnnotation toRemove = cloned_method.getAnnotations().stream().filter(annotation -> annotation.toString().contains("Override")).findFirst().orElse(null);
    if (toRemove != null) {
        cloned_method.removeAnnotation(toRemove);
    }
    return cloned_method;
}
Also used : CtAnnotation(spoon.reflect.declaration.CtAnnotation) CtMethod(spoon.reflect.declaration.CtMethod)

Example 24 with CtMethod

use of spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.

the class Counter method getInputOfSinceOrigin.

public static Integer getInputOfSinceOrigin(CtMethod method) {
    CtMethod currentMethod = method;
    CtMethod parent;
    int countAssertion = 0;
    while ((parent = AmplificationHelper.getAmpTestParent(currentMethod)) != null) {
        countAssertion += getInputOf(currentMethod);
        currentMethod = parent;
    }
    countAssertion += getInputOf(currentMethod);
    return countAssertion;
}
Also used : CtMethod(spoon.reflect.declaration.CtMethod)

Example 25 with CtMethod

use of spoon.reflect.declaration.CtMethod in project dspot by STAMP-project.

the class SelectorOnDiff method getModifiedMethod.

@SuppressWarnings("unchecked")
private static Set<CtMethod> getModifiedMethod(String pathFile1, String pathFile2) {
    try {
        final File file1 = new File(pathFile1);
        final File file2 = new File(pathFile2);
        if (!file1.exists() || !file2.exists()) {
            return Collections.emptySet();
        }
        Diff result = (new AstComparator()).compare(file1, file2);
        return result.getRootOperations().stream().map(operation -> operation.getSrcNode().getParent(CtMethod.class)).collect(Collectors.toSet());
    } catch (Exception ignored) {
        // if something bad happen, we do not care, we go for next file
        return Collections.emptySet();
    }
}
Also used : Diff(gumtree.spoon.diff.Diff) TypeFilter(spoon.reflect.visitor.filter.TypeFilter) AmplificationHelper(fr.inria.diversify.utils.AmplificationHelper) Logger(org.slf4j.Logger) InputConfiguration(fr.inria.diversify.utils.sosiefier.InputConfiguration) Main(fr.inria.stamp.Main) AstComparator(gumtree.spoon.AstComparator) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) IOException(java.io.IOException) Factory(spoon.reflect.factory.Factory) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) Collections(edu.emory.mathcs.backport.java.util.Collections) File(java.io.File) CtExecutableReference(spoon.reflect.reference.CtExecutableReference) List(java.util.List) CtType(spoon.reflect.declaration.CtType) AmplificationChecker(fr.inria.diversify.utils.AmplificationChecker) BufferedReader(java.io.BufferedReader) CtMethod(spoon.reflect.declaration.CtMethod) AstComparator(gumtree.spoon.AstComparator) Diff(gumtree.spoon.diff.Diff) File(java.io.File) IOException(java.io.IOException)

Aggregations

CtMethod (spoon.reflect.declaration.CtMethod)240 Test (org.junit.Test)163 Factory (spoon.reflect.factory.Factory)77 Launcher (spoon.Launcher)73 CtClass (spoon.reflect.declaration.CtClass)47 TypeFilter (spoon.reflect.visitor.filter.TypeFilter)47 CtType (spoon.reflect.declaration.CtType)45 AbstractTest (fr.inria.AbstractTest)36 ArrayList (java.util.ArrayList)35 List (java.util.List)33 CtTypeReference (spoon.reflect.reference.CtTypeReference)31 CtInvocation (spoon.reflect.code.CtInvocation)26 CtStatement (spoon.reflect.code.CtStatement)26 AmplificationHelper (fr.inria.diversify.utils.AmplificationHelper)19 Collectors (java.util.stream.Collectors)19 CtLiteral (spoon.reflect.code.CtLiteral)18 CtElement (spoon.reflect.declaration.CtElement)18 CtIf (spoon.reflect.code.CtIf)16 CtAnnotation (spoon.reflect.declaration.CtAnnotation)16 CtField (spoon.reflect.declaration.CtField)16