private boolean wasInitializedBefore(CtStatement statement, CtVariable<?> variable) { if (variable.getDefaultExpression() == null) { CtBlock<?> block = variable.getParent(CtBlock.class); Filter<CtAssignment<?, ?>> filter = initializationAssignmentsFilterFor(variable, statement); return !block.getElements(filter).isEmpty(); } return true; }
private void removeRedundantAssertions(CtMethod<?> amplifiedTestToBeMinimized) { amplifiedTestToBeMinimized.getElements(new TypeFilter<>(CtBlock.class)) .forEach(block -> { final List<CtInvocation<?>> assertions = block.getElements(new TypeFilter<CtInvocation<?>>(CtInvocation.class) { @Override public boolean matches(CtInvocation<?> element) { return element.getParent(CtBlock.class).equals(block) && TestFramework.get().isAssert(element); } }); final List<CtInvocation<?>> duplicatesAssertions = findDuplicates(assertions); // One of them might be removed final List<CtStatement> statements = block.getStatements(); duplicatesAssertions.forEach(duplicatesAssertion -> { DSpotUtils.printProgress(duplicatesAssertions.indexOf(duplicatesAssertion), duplicatesAssertions.size()); removeUselessDuplicateAssertions( block, duplicatesAssertion, statements ); }); }); }
private void removeRedundantAssertions(CtMethod<?> amplifiedTestToBeMinimized) { amplifiedTestToBeMinimized.getElements(new TypeFilter<>(CtBlock.class)) .forEach(block -> { final List<CtInvocation<?>> assertions = block.getElements(new TypeFilter<CtInvocation<?>>(CtInvocation.class) { @Override public boolean matches(CtInvocation<?> element) { return element.getParent(CtBlock.class).equals(block) && TestFramework.get().isAssert(element); } }); final List<CtInvocation<?>> duplicatesAssertions = findDuplicates(assertions); // One of them might be removed final List<CtStatement> statements = block.getStatements(); duplicatesAssertions.forEach(duplicatesAssertion -> { DSpotUtils.printProgress(duplicatesAssertions.indexOf(duplicatesAssertion), duplicatesAssertions.size()); removeUselessDuplicateAssertions( block, duplicatesAssertion, statements ); }); }); }
@Override public void process(final CtMethod<?> method) { if (method != null) { if (isTestCase(method)) { instrumentMethod(method); } else { if (method.getBody() != null) { List<CtIf> ifList = method.getBody().getElements( new Filter<CtIf>() { @Override public boolean matches(CtIf arg0) { if (!(arg0 instanceof CtIf)) { return false; } return true; } }); for (CtIf tmp : ifList) { instrumentIfInsideMethod(tmp); } } } String s = method.getDeclaringType().getQualifiedName(); if (this.ifMetric != null && !this.ifMetric.modifyClass.contains(s)) { this.ifMetric.modifyClass.add(s); } } }
); if (!catches.get(0).getBody().getStatements().isEmpty()) { catches.get(0).getBody().getElements(new TypeFilter<CtVariableAccess>(CtVariableAccess.class) { @Override public boolean matches(CtVariableAccess element) {
} else if (clone instanceof CtVariableRead && !(clone instanceof CtFieldRead)) { final CtVariableReference variable = ((CtVariableRead) clone).getVariable(); final List<CtLocalVariable> assertedVariables = invocation.getParent(CtBlock.class).getElements( localVariable -> localVariable.getSimpleName().equals(variable.getSimpleName())