/** * 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; }
if (clazz.isPrimitive() && type.getParent() instanceof CtPackage) {
private CtType<?> getTypeParent(CtType<?> parent) { final CtType typeParent = parent.getParent(CtType.class); if (typeParent == null) { return parent; } return getTypeParent(typeParent); }
@Override public boolean matches(CtType element) { // Definition of "top level" CtType. return element.getParent(CtType.class) == null && !element.isImplicit(); } };
@Override public boolean matches(CtType element) { // Definition of "top level" CtType. return element.getParent(CtType.class) == null && !element.isImplicit(); } };
@Deprecated public static Set<CtType> computeClassProvider(CtType testClass) { List<CtType> types = Query.getElements(testClass.getParent(CtPackage.class), new TypeFilter(CtType.class)); types = types.stream() .filter(Objects::nonNull) .filter(type -> type.getPackage() != null) .filter(type -> type.getPackage().getQualifiedName().equals(testClass.getPackage().getQualifiedName())) .collect(Collectors.toList()); if (testClass.getParent(CtType.class) != null) { types.add(testClass.getParent(CtType.class)); } types.addAll(types.stream() .flatMap(type -> getImport(type).stream()) .collect(Collectors.toSet())); return new HashSet<>(types); }
@Override public void defineSpace(ProgramVariant variant) { List<CtType<?>> affected = variant.getAffectedClasses(); List<CtPackage> packageAnalyzed = new ArrayList<>(); for (CtType<?> ing : affected) { CtPackage p = ing.getParent(CtPackage.class); if (!packageAnalyzed.contains(p)) { packageAnalyzed.add(p); for (CtType<?> t : p.getTypes()) { this.createFixSpaceFromAClass(t); } } } }
cloneClass.setParent(testClass.getParent()); List<CtMethod<?>> testsWithoutAssertions = tests.stream() .map(this.assertionRemover::removeAssertion)
public boolean matches(CtExecutable element) { boolean t = element.getParent(CtExecutable.class) == null && !element.isImplicit() && !(element instanceof CtAnonymousExecutable); return t;
@Deprecated public Map<String, NGrams> calculateByPackage(List<CtType<?>> all) throws JSAPException { Map<String, NGrams> result = new HashedMap(); CodeParserLauncher ingp = new CodeParserLauncher<>(ingredientProcessor); int allElements = 0; for (CtType<?> ctType : all) { NGrams ns = new NGrams(); CtPackage parent = (CtPackage) ctType.getParent(CtPackage.class); if (!result.containsKey(parent.getQualifiedName())) { allElements += getNGramsFromCodeElements(parent, ns, ingp); result.put(parent.getQualifiedName(), ns); } } logger.debug("allElements " + allElements); return result; } @Deprecated
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())); } }
public boolean matches(CtExecutable element) { boolean t = element.getParent(CtExecutable.class) == null && !element.isImplicit() && !(element instanceof CtAnonymousExecutable)
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; }
protected List<CtType<?>> obtainClassesFromScope(ProgramVariant variant) { if (IngredientPoolScope.PACKAGE.equals(scope)) { List<CtType<?>> affected = variant.getAffectedClasses(); List<CtType<?>> types = new ArrayList<>(); List<CtPackage> packageAnalyzed = new ArrayList<>(); for (CtType<?> ing : affected) { CtPackage p = ing.getParent(CtPackage.class); if (!packageAnalyzed.contains(p)) { packageAnalyzed.add(p); for (CtType<?> type : p.getTypes()) { types.add(type); } } } return types; } if (IngredientPoolScope.LOCAL.equals(scope)) { return variant.getAffectedClasses(); } if (IngredientPoolScope.GLOBAL.equals(scope)) { return MutationSupporter.getFactory().Type().getAll(); } return null; }
protected List<CtType<?>> obtainClassesFromScope(ProgramVariant variant) { if (IngredientPoolScope.PACKAGE.equals(scope)) { List<CtType<?>> affected = variant.getAffectedClasses(); List<CtType<?>> types = new ArrayList<>(); List<CtPackage> packageAnalyzed = new ArrayList<>(); for (CtType<?> ing : affected) { CtPackage p = ing.getParent(CtPackage.class); if (!packageAnalyzed.contains(p)) { packageAnalyzed.add(p); for (CtType<?> type : p.getTypes()) { types.add(type); } } } return types; } if (IngredientPoolScope.LOCAL.equals(scope)) { return variant.getAffectedClasses(); } if (IngredientPoolScope.GLOBAL.equals(scope)) { return MutationSupporter.getFactory().Type().getAll(); } return null; }
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 <T> boolean hasDeclaringTypeWithGenerics(CtTypeReference<T> reference) { // If current reference use generic types, we don't need this hack. if (reference.getActualTypeArguments().size() != 0) { return false; } // If current reference is a class declared in a method, we don't need this hack. if (reference.getDeclaration() == null) { return false; } if (reference.getDeclaration().getParent(CtMethod.class) != null) { return false; } // If the declaring type isn't a CtType, we don't need this hack. if (reference.getDeclaringType() == null) { return false; } final CtElement declaration = reference.getDeclaringType().getDeclaration(); if (declaration == null) { return false; } if (!(declaration instanceof CtType)) { return false; } // Checks if the declaring type has generic types. return ((CtType<?>) declaration).getFormalTypeParameters().size() != 0; }
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); } }