@SuppressWarnings("unchecked") public CtBlock<R> getSubstitution(CtType<?> targetType) { CtClass<?> c; c = targetType.getFactory().Class().get(this.getClass()); if (c == null) { c = targetType.getFactory().Class().get(this.getClass()); } CtMethod m = c.getMethod("block"); if (this instanceof Template) { return Substitution.substitute(targetType, (Template<?>) this, m.getBody()); } return m.getBody().clone(); }
public CtStatementList getSubstitution(CtType<?> targetType) { CtClass<?> c; CtBlock<?> b; c = targetType.getFactory().Class().get(this.getClass()); if (c == null) { c = targetType.getFactory().Class().get(this.getClass()); } CtStatementList l = targetType.getFactory().Core().createStatementList(); if (this instanceof Template) { b = Substitution.substitute(targetType, (Template<?>) this, c.getMethod("statements").getBody()); } else { b = c.getMethod("statements").getBody().clone(); } l.setStatements(b.getStatements()); return l; }
@Override public List<OperatorInstance> createOperatorInstances(ModificationPoint modificationPoint) { log.debug("Unwrap Try:"); CtTry trytoremove = (CtTry) modificationPoint.getCodeElement(); CtBlock blockOfTry = trytoremove.getBody().clone(); MutationSupporter.clearPosition(blockOfTry); List<OperatorInstance> opInstances = new ArrayList<>(); OperatorInstance opInstace = new StatementOperatorInstance(modificationPoint, this, trytoremove, blockOfTry); opInstances.add(opInstace); return opInstances; }
/** * Removes all assertions from a test. * * @param testMethod Test method * @return Test's clone without any assertion */ public CtMethod<?> removeAssertion(CtMethod<?> testMethod) { CtMethod<?> testWithoutAssertion = CloneHelper.cloneTestMethodNoAmp(testMethod); variableAssertedPerTestMethod.put(testWithoutAssertion, testWithoutAssertion .getElements(TestFramework.ASSERTIONS_FILTER) .stream() .flatMap(invocation -> this.removeAssertion(invocation).stream()) .collect(Collectors.toList()) ); testWithoutAssertion.getElements(new TypeFilter<>(CtTry.class)) .forEach(ctTry -> ctTry.insertBefore((CtStatement) ctTry.getBody().clone())); testWithoutAssertion.getElements(new TypeFilter<>(CtTry.class)) .forEach(testWithoutAssertion.getBody()::removeStatement); return testWithoutAssertion; }