Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor parent map #374

Merged
merged 7 commits into from Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -74,7 +74,7 @@ public List<CtMethod> apply(CtMethod testMethod) {
return literals.stream()
.flatMap(literal ->
this.amplify(literal).stream().map(newValue -> {
CtMethod clone = AmplificationHelper.cloneMethodTest(testMethod, getSuffix());
CtMethod clone = AmplificationHelper.cloneTestMethodForAmp(testMethod, getSuffix());
clone.getElements(LITERAL_TYPE_FILTER).get(literals.indexOf(literal)).replace(newValue);
return clone;
})
Expand Down
Expand Up @@ -28,7 +28,7 @@ public List<CtMethod> apply(CtMethod method) {
final Stream<? extends CtMethod<?>> gen_o1 = existingObjects.stream() // must use tmp variable because javac is confused
.flatMap(localVariable -> ConstructorCreator.generateAllConstructionOf(localVariable.getType()).stream())
.map(ctExpression -> {
final CtMethod<?> clone = AmplificationHelper.cloneMethodTest(method, "_sd");
final CtMethod<?> clone = AmplificationHelper.cloneTestMethodForAmp(method, "_sd");
clone.getBody().insertBegin(
clone.getFactory().createLocalVariable(
ctExpression.getType(), "__DSPOT_gen_o" + counterGenerateNewObject++, ctExpression
Expand Down
Expand Up @@ -77,7 +77,7 @@ private List<CtMethod> useReturnValuesOfExistingMethodCall(CtMethod method) {
"__DSPOT_invoc_" + indexOfInvocation,
invocation.clone());
CtExpression<?> target = createLocalVarRef(localVar);
CtMethod methodClone = AmplificationHelper.cloneMethodTest(method, "");
CtMethod methodClone = AmplificationHelper.cloneTestMethodForAmp(method, "");
replaceInvocationByLocalVariable(
methodClone.getElements(new TypeFilter<>(CtStatement.class)).get(indexOfInvocation),
localVar
Expand Down Expand Up @@ -136,7 +136,7 @@ public void reset(CtType testClass) {

private CtMethod addInvocation(CtMethod<?> testMethod, CtMethod<?> methodToInvokeToAdd, CtExpression<?> target, CtStatement position) {
final Factory factory = testMethod.getFactory();
CtMethod methodClone = AmplificationHelper.cloneMethodTest(testMethod, "_sd");
CtMethod methodClone = AmplificationHelper.cloneTestMethodForAmp(testMethod, "_sd");

CtBlock body = methodClone.getElements(new TypeFilter<>(CtStatement.class))
.stream()
Expand Down
Expand Up @@ -66,7 +66,7 @@ public List<CtMethod> apply(CtMethod method) {
}
lit_index++;
}
return AmplificationHelper.updateAmpTestToParent(methods, method);
return methods;
}

public void reset(CtType testClass) {
Expand All @@ -79,7 +79,7 @@ public void reset(CtType testClass) {

private CtMethod createNumberMutant(CtMethod method, int original_lit_index, Number newValue) {
//clone the method
CtMethod cloned_method = AmplificationHelper.cloneMethodTest(method, "_literalMutationNumber");
CtMethod cloned_method = AmplificationHelper.cloneTestMethodForAmp(method, "_literalMutationNumber");
//get the lit_indexth literal of the cloned method
CtLiteral newLiteral = Query.getElements(cloned_method.getBody(), new LiteralToBeMutedFilter())
.get(original_lit_index);
Expand Down Expand Up @@ -125,7 +125,7 @@ private List<CtMethod> createAllStringMutant(CtMethod method, CtLiteral literal,
}

private CtMethod createStringMutant(CtMethod method, int original_lit_index, String newValue) {
CtMethod cloned_method = AmplificationHelper.cloneMethodTest(method, "_literalMutationString");
CtMethod cloned_method = AmplificationHelper.cloneTestMethodForAmp(method, "_literalMutationString");
Counter.updateInputOf(cloned_method, 1);
CtLiteral toReplace = Query.getElements(cloned_method.getBody(), new LiteralToBeMutedFilter())
.get(original_lit_index);
Expand All @@ -141,7 +141,7 @@ private List<CtMethod> createAllCharacterMutant(CtMethod method, CtLiteral lit,
}

private CtMethod createCharacterMutant(CtMethod method, int original_lit_index, Character newValue) {
CtMethod cloned_method = AmplificationHelper.cloneMethodTest(method, "_literalMutationChar");
CtMethod cloned_method = AmplificationHelper.cloneTestMethodForAmp(method, "_literalMutationChar");
Counter.updateInputOf(cloned_method, 1);
CtLiteral toReplace = Query.getElements(cloned_method.getBody(), new LiteralToBeMutedFilter())
.get(original_lit_index);
Expand Down Expand Up @@ -210,7 +210,7 @@ private Set<? extends Number> numberMutated(CtLiteral literal) {

private CtMethod createBooleanMutant(CtMethod test, CtLiteral booleanLiteral) {
Boolean value = (Boolean) booleanLiteral.getValue();
CtMethod cloned_method = AmplificationHelper.cloneMethodTest(test, "_literalMutationBoolean");
CtMethod cloned_method = AmplificationHelper.cloneTestMethodForAmp(test, "_literalMutationBoolean");
CtLiteral newValue = cloned_method.getElements(new TypeFilter<CtLiteral>(CtLiteral.class) {
@Override
public boolean matches(CtLiteral element) {
Expand Down
Expand Up @@ -38,7 +38,7 @@ public List<CtMethod> apply(CtMethod method) {
invocation_index++;
}
}
return AmplificationHelper.updateAmpTestToParent(methods, method);
return methods;
}

@Override
Expand All @@ -47,7 +47,7 @@ public void reset(CtType testClass) {
}

private CtMethod apply(CtMethod method, int invocation_index) {
CtMethod<?> cloned_method = AmplificationHelper.cloneMethodTest(method, "_add");
CtMethod<?> cloned_method = AmplificationHelper.cloneTestMethodForAmp(method, "_add");
//add the cloned method in the same class as the original method
//get the lit_indexth literal of the cloned method
CtInvocation stmt = Query.getElements(cloned_method, new TypeFilter<>(CtInvocation.class)).get(invocation_index);
Expand All @@ -69,4 +69,4 @@ private CtStatement getParent(CtInvocation invocationToBeCloned) {
}


}
}
Expand Up @@ -38,7 +38,7 @@ public List<CtMethod> apply(CtMethod method) {
invocation_index++;
}
}
return AmplificationHelper.updateAmpTestToParent(methods, method);
return methods;
}

@Override
Expand All @@ -48,7 +48,7 @@ public void reset(CtType testClass) {

private CtMethod apply(CtMethod method, int invocation_index) {
//clone the method
CtMethod<?> cloned_method = AmplificationHelper.cloneMethodTest(method, "_remove");
CtMethod<?> cloned_method = AmplificationHelper.cloneTestMethodForAmp(method, "_remove");

//get the lit_indexth literal of the cloned method
CtInvocation stmt = Query.getElements(cloned_method, new TypeFilter<>(CtInvocation.class)).get(invocation_index);
Expand Down
Expand Up @@ -27,7 +27,7 @@ static boolean isVoidReturn(CtInvocation invocation) {
}

static CtMethod<?> createTestWithLog(CtMethod test, final String filter) {
CtMethod clone = AmplificationHelper.cloneMethodTest(test, "");
CtMethod clone = AmplificationHelper.cloneTestMethodNoAmp(test);
clone.setSimpleName(test.getSimpleName() + "_withlog");
final List<CtStatement> allStatement = clone.getElements(new TypeFilter<>(CtStatement.class));
allStatement.stream()
Expand Down
Expand Up @@ -31,7 +31,7 @@ public class AssertionRemover {
* @return Test's clone without any assertion
*/
public CtMethod<?> removeAssertion(CtMethod<?> testMethod) {
CtMethod<?> testWithoutAssertion = AmplificationHelper.cloneMethodTest(testMethod, "");
CtMethod<?> testWithoutAssertion = AmplificationHelper.cloneTestMethodNoAmp(testMethod);
testWithoutAssertion.getElements(AmplificationHelper.ASSERTIONS_FILTER)
.forEach(this::removeAssertion);
return testWithoutAssertion;
Expand Down
Expand Up @@ -195,7 +195,7 @@ private List<CtMethod<?>> addAssertions(CtType<?> testClass, List<CtMethod<?>> t
*/
@SuppressWarnings("unchecked")
private CtMethod<?> buildTestWithAssert(CtMethod test, Map<String, Observation> observations) {
CtMethod testWithAssert = AmplificationHelper.cloneMethodTest(test, "");
CtMethod testWithAssert = AmplificationHelper.cloneTestMethodForAmp(test, "");
int numberOfAddedAssertion = 0;
List<CtStatement> statements = Query.getElements(testWithAssert, new TypeFilter(CtStatement.class));
for (String id : observations.keySet()) {
Expand Down Expand Up @@ -257,9 +257,9 @@ private CtMethod<?> buildTestWithAssert(CtMethod test, Map<String, Observation>
}
Counter.updateAssertionOf(testWithAssert, numberOfAddedAssertion);
if (!testWithAssert.equals(test)) {
AmplificationHelper.getAmpTestToParent().put(testWithAssert, test);
return testWithAssert;
} else {
AmplificationHelper.removeAmpTestParent(testWithAssert);
return null;
}
}
Expand All @@ -272,7 +272,7 @@ private CtMethod<?> buildTestWithAssert(CtMethod test, Map<String, Observation>
* @return New amplified test
*/
protected CtMethod<?> makeFailureTest(CtMethod<?> test, Failure failure) {
CtMethod cloneMethodTest = AmplificationHelper.cloneMethodTest(test, "");
CtMethod cloneMethodTest = AmplificationHelper.cloneTestMethodForAmp(test, "");
cloneMethodTest.setSimpleName(test.getSimpleName());
Factory factory = cloneMethodTest.getFactory();

Expand Down Expand Up @@ -312,8 +312,6 @@ protected CtMethod<?> makeFailureTest(CtMethod<?> test, Failure failure) {
cloneMethodTest.setSimpleName(cloneMethodTest.getSimpleName() + "_failAssert" + (numberOfFail++));
Counter.updateAssertionOf(cloneMethodTest, 1);

AmplificationHelper.getAmpTestToParent().put(cloneMethodTest, test);

return cloneMethodTest;
}
}
Expand Up @@ -108,16 +108,16 @@ public List<CtMethod<?>> selectToKeep(List<CtMethod<?>> amplifiedTestToBeKept) {
this.currentClassTestToBeAmplified, methodNames);
final List<String> pathExecuted = new ArrayList<>();
final List<CtMethod<?>> methodsKept = amplifiedTestToBeKept.stream()
.filter(ctMethod ->
this.selectedToBeAmplifiedCoverageResultsMap.get(
getFirstParentThatHasBeenRun(ctMethod).getSimpleName()) == null ||
coverageResultsMap.get(ctMethod.getSimpleName()).isBetterThan(
this.selectedToBeAmplifiedCoverageResultsMap.get(
getFirstParentThatHasBeenRun(ctMethod).getSimpleName())) &&
!computePathExecuted.apply(coverageResultsMap.get(ctMethod.getSimpleName()).getCoverageBuilder())
.equals(computePathExecuted.apply(this.selectedToBeAmplifiedCoverageResultsMap.get(
getFirstParentThatHasBeenRun(ctMethod).getSimpleName()).getCoverageBuilder()))
)
.filter(ctMethod -> {
final String simpleNameOfFirstParent = getFirstParentThatHasBeenRun(ctMethod).getSimpleName();
return this.selectedToBeAmplifiedCoverageResultsMap.get(simpleNameOfFirstParent) == null ||
coverageResultsMap.get(ctMethod.getSimpleName()).isBetterThan(
this.selectedToBeAmplifiedCoverageResultsMap.get(
simpleNameOfFirstParent)) &&
!computePathExecuted.apply(coverageResultsMap.get(ctMethod.getSimpleName()).getCoverageBuilder())
.equals(computePathExecuted.apply(this.selectedToBeAmplifiedCoverageResultsMap.get(
simpleNameOfFirstParent).getCoverageBuilder()));
})
.filter(ctMethod -> {
final String pathByExecInstructions = computePathExecuted.apply(coverageResultsMap.get(ctMethod.getSimpleName()).getCoverageBuilder());
if (pathExecuted.contains(pathByExecInstructions)) {
Expand All @@ -141,12 +141,12 @@ public List<CtMethod<?>> selectToKeep(List<CtMethod<?>> amplifiedTestToBeKept) {
}

protected CtMethod<?> getFirstParentThatHasBeenRun(CtMethod<?> test) {
CtMethod<?> currentParent = AmplificationHelper.getAmpTestToParent().get(test);
while (AmplificationHelper.getAmpTestToParent().get(currentParent) != null) {
CtMethod<?> currentParent = AmplificationHelper.getAmpTestParent(test);
while (AmplificationHelper.getAmpTestParent(currentParent) != null) {
if (this.selectedToBeAmplifiedCoverageResultsMap.get(currentParent.getSimpleName()) != null) {
return currentParent;
} else {
currentParent = AmplificationHelper.getAmpTestToParent().get(currentParent);
currentParent = AmplificationHelper.getAmpTestParent(currentParent);
}
}
return currentParent;
Expand Down
Expand Up @@ -167,13 +167,13 @@ public List<CtMethod<?>> selectToKeep(List<CtMethod<?>> amplifiedTestToBeKept) {
}

private boolean killsMoreMutantThanParents(CtMethod test, PitResult result) {
CtMethod parent = AmplificationHelper.getAmpTestToParent().get(test);
CtMethod parent = AmplificationHelper.getAmpTestParent(test);
while (parent != null) {
if (this.testThatKilledMutants.get(parent) != null &&
this.testThatKilledMutants.get(parent).contains(result)) {
return false;
}
parent = AmplificationHelper.getAmpTestToParent().get(parent);
parent = AmplificationHelper.getAmpTestParent(parent);
}
return true;
}
Expand Down Expand Up @@ -289,4 +289,4 @@ private int getNbMutantKilledOriginally(String qualifiedName) {
public Minimizer getMinimizer() {
return new PitMutantMinimizer(this.currentClassTestToBeAmplified, this.configuration, this.testThatKilledMutants);
}
}
}