private void removeUselessDuplicateAssertions(CtBlock<?> block, CtInvocation<?> duplicatesAssertion, List<CtStatement> statements) { final CtVariableReference variable = ((CtVariableRead<?>) duplicatesAssertion .filterChildren(new TypeFilter<CtVariableRead<?>>(CtVariableRead.class)) .first()) .getVariable(); boolean canBeRemoved = true; for (int i = statements.indexOf(duplicatesAssertion) + 1; i < statements.lastIndexOf(duplicatesAssertion); i++) { if (!TestFramework.get().isAssert(statements.get(i))) { final CtVariableRead<?> first = statements.get(i) .filterChildren(new TypeFilter<CtVariableRead<?>>(CtVariableRead.class) { @Override public boolean matches(CtVariableRead<?> element) { return element.getVariable().equals(variable); } }).first(); if (first != null) { canBeRemoved = false; break; } } } if (canBeRemoved) { block.getStatements().remove(statements.lastIndexOf(duplicatesAssertion)); } }
private void removeUselessDuplicateAssertions(CtBlock<?> block, CtInvocation<?> duplicatesAssertion, List<CtStatement> statements) { final CtVariableReference variable = ((CtVariableRead<?>) duplicatesAssertion .filterChildren(new TypeFilter<CtVariableRead<?>>(CtVariableRead.class)) .first()) .getVariable(); boolean canBeRemoved = true; for (int i = statements.indexOf(duplicatesAssertion) + 1; i < statements.lastIndexOf(duplicatesAssertion); i++) { if (!TestFramework.get().isAssert(statements.get(i))) { final CtVariableRead<?> first = statements.get(i) .filterChildren(new TypeFilter<CtVariableRead<?>>(CtVariableRead.class) { @Override public boolean matches(CtVariableRead<?> element) { return element.getVariable().equals(variable); } }).first(); if (first != null) { canBeRemoved = false; break; } } } if (canBeRemoved) { block.getStatements().remove(statements.lastIndexOf(duplicatesAssertion)); } }