/** * Returns clone of the patternType. * The clone is done only once. Later calls returns cached clone. * @return */ private CtType<?> getClonedPatternType() { if (clonedPatternType == null) { clonedPatternType = patternType.clone(); if (patternType.isParentInitialized()) { //set parent package, to keep origin qualified name of the Template. It is needed for correct substitution of Template name by target type reference clonedPatternType.setParent(patternType.getParent()); } setElements(Collections.singletonList(clonedPatternType)); } return clonedPatternType; }
final R type = ctPackage.getType(clazz.getSimpleName()); if (clazz.isPrimitive() && type.getParent() instanceof CtPackage) { type.setParent(null); // primitive type isn't in a package.
@Override public <T extends CtPackage> T addType(CtType<?> type) { type.setParent(this); types.add(type); return (T) this; }
@Override public <N, C extends CtType<T>> C addNestedType(CtType<N> nestedType) { if (nestedTypes == CtElementImpl.<CtType<?>>emptySet()) { nestedTypes = new TreeSet<CtType<?>>(); } nestedType.setParent(this); this.nestedTypes.add(nestedType); return (C) this; }
cloneClass.setParent(testClass.getParent()); List<CtMethod<?>> testsWithoutAssertions = tests.stream() .map(this.assertionRemover::removeAssertion)
private boolean printAndCompile(InputConfiguration configuration, CtType<?> clone, CtMethod<?> amplifiedTestToBeMinimized) { clone.setParent(this.testClass.getParent()); this.testClass.getMethods().stream() .filter(TestFramework.get()::isTest) .forEach(clone::removeMethod); clone.addMethod(amplifiedTestToBeMinimized); DSpotUtils.printCtTypeToGivenDirectory(clone, new File(DSpotCompiler.getPathToAmplifiedTestSrc())); return DSpotCompiler.compile(configuration, DSpotCompiler.getPathToAmplifiedTestSrc(), this.configuration.getFullClassPathWithExtraDependencies(), new File(this.configuration.getAbsolutePathToTestClasses())); } }
private boolean printAndCompile(InputConfiguration configuration, CtType<?> clone, CtMethod<?> amplifiedTestToBeMinimized) { clone.setParent(this.testClass.getParent()); this.testClass.getMethods().stream() .filter(TestFramework.get()::isTest) .forEach(clone::removeMethod); clone.addMethod(amplifiedTestToBeMinimized); DSpotUtils.printCtTypeToGivenDirectory(clone, new File(DSpotCompiler.getPathToAmplifiedTestSrc())); return DSpotCompiler.compile(configuration, DSpotCompiler.getPathToAmplifiedTestSrc(), this.configuration.getFullClassPathWithExtraDependencies(), new File(this.configuration.getAbsolutePathToTestClasses())); } }
@Override public List<CtMethod<?>> selectToKeep(List<CtMethod<?>> amplifiedTestToBeKept) { if (amplifiedTestToBeKept.isEmpty()) { return amplifiedTestToBeKept; } CtType<?> clone = this.currentClassTestToBeAmplified.clone(); clone.setParent(this.currentClassTestToBeAmplified.getParent()); this.currentClassTestToBeAmplified.getMethods().stream() .filter(TestFramework.get()::isTest) .forEach(clone::removeMethod); amplifiedTestToBeKept.forEach(clone::addMethod); DSpotUtils.printCtTypeToGivenDirectory(clone, new File(getPathToCopiedFiles())); final Map<String, Map<String, List<Integer>>> lineCoveragePerTestMethods = CloverExecutor.execute(this.configuration, getPathToCopiedFiles(), clone.getQualifiedName()); final List<CtMethod<?>> selectedTests = this.selectTests(clone, lineCoveragePerTestMethods); this.selectedAmplifiedTest.addAll(selectedTests); return selectedTests; }
clone.setParent(this.currentClassTestToBeAmplified.getParent()); this.currentClassTestToBeAmplified.getMethods().stream() .filter(TestFramework.get()::isTest)
clone.setParent(this.currentClassTestToBeAmplified.getParent()); this.currentClassTestToBeAmplified.getMethods().stream() .filter(TestFramework.get()::isTest)
private Coverage computeAmplifiedCoverage() { // computing the amplified test coverage CtType<?> clone = this.currentClassTestToBeAmplified.clone(); clone.setParent(this.currentClassTestToBeAmplified.getParent()); this.selectedAmplifiedTest.forEach(clone::addMethod); DSpotUtils.printCtTypeToGivenDirectory(clone, new File(DSpotCompiler.getPathToAmplifiedTestSrc())); final String classpath = this.configuration.getDependencies() + AmplificationHelper.PATH_SEPARATOR + this.configuration.getClasspathClassesProject(); DSpotCompiler.compile(this.configuration, DSpotCompiler.getPathToAmplifiedTestSrc(), classpath, new File(this.configuration.getAbsolutePathToTestClasses())); try { return EntryPoint.runCoverage( classpath, this.configuration.getClasspathClassesProject(), clone.getQualifiedName() ); } catch (TimeoutException e) { throw new RuntimeException(e); } }