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;
}
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;
}
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;
}
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;
}
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();
}
}
Aggregations