当前位置: 首页>>代码示例>>Java>>正文


Java CtType.setParent方法代码示例

本文整理汇总了Java中spoon.reflect.declaration.CtType.setParent方法的典型用法代码示例。如果您正苦于以下问题:Java CtType.setParent方法的具体用法?Java CtType.setParent怎么用?Java CtType.setParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在spoon.reflect.declaration.CtType的用法示例。


在下文中一共展示了CtType.setParent方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: computeAmplifiedCoverage

import spoon.reflect.declaration.CtType; //导入方法依赖的package包/类
private Coverage computeAmplifiedCoverage() {
    // computing the amplified test coverage
    CtType<?> clone = this.currentClassTestToBeAmplified.clone();
    clone.setParent(this.currentClassTestToBeAmplified.getParent());
    this.currentClassTestToBeAmplified.getMethods().stream()
            .filter(AmplificationChecker::isTest)
            .forEach(clone::removeMethod);
    this.selectedAmplifiedTest.forEach(clone::addMethod);

    DSpotUtils.printJavaFileWithComment(clone, new File(DSpotCompiler.pathToTmpTestSources));

    final String classesOfProject = program.getProgramDir() + program.getClassesDir() +
            AmplificationHelper.PATH_SEPARATOR + program.getProgramDir() + program.getTestClassesDir();

    final String classpath = AutomaticBuilderFactory.getAutomaticBuilder(this.configuration)
            .buildClasspath(program.getProgramDir()) +
            AmplificationHelper.PATH_SEPARATOR + classesOfProject;

    return EntryPoint.runCoverageOnTestClasses(classpath, classesOfProject,
            DSpotUtils.getAllTestClasses(configuration)
    );
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:23,代码来源:CloverCoverageSelector.java

示例2: generateAsserts

import spoon.reflect.declaration.CtType; //导入方法依赖的package包/类
public List<CtMethod<?>> generateAsserts(CtType<?> testClass, List<CtMethod<?>> tests) throws IOException, ClassNotFoundException {
    CtType cloneClass = testClass.clone();
    cloneClass.setParent(testClass.getParent());
    List<CtMethod<?>> testWithoutAssertions = tests.stream()
            .map(this.assertionRemover::removeAssertion)
            .collect(Collectors.toList());
    testWithoutAssertions.forEach(cloneClass::addMethod);
    MethodsAssertGenerator ags = new MethodsAssertGenerator(testClass, this.configuration, compiler);
    final List<CtMethod<?>> amplifiedTestWithAssertion =
            ags.generateAsserts(cloneClass, testWithoutAssertions);
    if (amplifiedTestWithAssertion.isEmpty()) {
        LOGGER.info("Could not generate any test with assertions");
    } else {
        LOGGER.info("{} new tests with assertions generated", amplifiedTestWithAssertion.size());
    }
    return amplifiedTestWithAssertion;
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:18,代码来源:AssertGenerator.java

示例3: apply

import spoon.reflect.declaration.CtType; //导入方法依赖的package包/类
@Override
public List<CtMethod> apply(CtMethod ctMethod) {
    if (!canBeRun.test(ctMethod)) {
        return Collections.emptyList();
    }
    final CtMethod<?> extractedMethod = ArgumentsExtractor.performExtraction(ctMethod);
    final CtType ctType = ctMethod.getParent(CtClass.class);
    CtType<?> clone = ctType.clone();
    clone.setParent(ctType.getParent());
    clone.removeMethod(ctMethod);
    clone.addMethod(extractedMethod);
    DSpotUtils.printJavaFileWithComment(clone, new File(DSpotCompiler.pathToTmpTestSources));
    final String classpath = AutomaticBuilderFactory
            .getAutomaticBuilder(this.configuration)
            .buildClasspath(this.configuration.getInputProgram().getProgramDir())
            + AmplificationHelper.PATH_SEPARATOR +
            this.configuration.getInputProgram().getProgramDir() + "/" + this.configuration.getInputProgram().getClassesDir()
            + AmplificationHelper.PATH_SEPARATOR + "target/dspot/dependencies/"
            + AmplificationHelper.PATH_SEPARATOR +
            this.configuration.getInputProgram().getProgramDir() + "/" + this.configuration.getInputProgram().getTestClassesDir();
    DSpotCompiler.compile(DSpotCompiler.pathToTmpTestSources, classpath,
            new File(this.configuration.getInputProgram().getProgramDir() + "/" + this.configuration.getInputProgram().getTestClassesDir()));
    final List<Map<String, List<String>>> conditionForEachParameterForEachState = JBSERunner.runJBSE(classpath, extractedMethod);
    return conditionForEachParameterForEachState.stream()
            .map(conditions ->
                    this.generateNewTestMethod(ctMethod, conditions)
            )
            .collect(Collectors.toList());
}
 
开发者ID:STAMP-project,项目名称:Ex2Amplifier,代码行数:30,代码来源:Ex2Amplifier.java

示例4: amplifyTest

import spoon.reflect.declaration.CtType; //导入方法依赖的package包/类
public CtType amplifyTest(String fullQualifiedName, List<String> methods) throws InterruptedException, IOException, ClassNotFoundException {
    CtType<Object> clone = this.compiler.getLauncher().getFactory().Type().get(fullQualifiedName).clone();
    clone.setParent(this.compiler.getLauncher().getFactory().Type().get(fullQualifiedName).getParent());
    return amplifyTest(clone, methods.stream()
            .map(methodName -> clone.getMethodsByName(methodName).get(0))
            .filter(AmplificationChecker::isTest)
            .collect(Collectors.toList()));
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:9,代码来源:DSpot.java

示例5: selectToKeep

import spoon.reflect.declaration.CtType; //导入方法依赖的package包/类
@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(AmplificationChecker::isTest)
            .forEach(clone::removeMethod);
    amplifiedTestToBeKept.forEach(clone::addMethod);

    DSpotUtils.printJavaFileWithComment(clone, new File(PATH_TO_COPIED_FILES));

    final Map<String, Map<String, List<Integer>>> lineCoveragePerTestMethods =
            CloverExecutor.execute(this.configuration, PATH_TO_COPIED_FILES, clone.getQualifiedName());

    final List<CtMethod<?>> selectedTests = lineCoveragePerTestMethods.keySet().stream()
            .filter(testMethodName ->
                    lineCoveragePerTestMethods.get(testMethodName).keySet().stream()
                            .anyMatch(className ->
                                    lineCoveragePerTestMethods.get(testMethodName).get(className)
                                            .stream()
                                            .anyMatch(executedLine ->
                                                    !this.originalLineCoveragePerClass.get(
                                                            this.configuration.getInputProgram().getFactory().Type().get(className)
                                                    ).contains(executedLine)
                                            )
                            )
            )
            .map(clone::getMethodsByName)
            .map(ctMethods -> ctMethods.get(0))
            .collect(Collectors.toList());

    this.selectedAmplifiedTest.addAll(selectedTests);

    return selectedTests;
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:40,代码来源:CloverCoverageSelector.java

示例6: selectToKeep

import spoon.reflect.declaration.CtType; //导入方法依赖的package包/类
@Override
public List<CtMethod<?>> selectToKeep(List<CtMethod<?>> amplifiedTestToBeKept) {
    if (amplifiedTestToBeKept.isEmpty()) {
        return amplifiedTestToBeKept;
    }

    // construct a test classes with only amplified tests
    CtType clone = this.currentClassTestToBeAmplified.clone();
    clone.setParent(this.currentClassTestToBeAmplified.getParent());
    this.currentClassTestToBeAmplified.getMethods().stream()
            .filter(AmplificationChecker::isTest)
            .forEach(clone::removeMethod);
    amplifiedTestToBeKept.forEach(clone::addMethod);

    // pretty print it
    DSpotUtils.printJavaFileWithComment(clone, new File(DSpotCompiler.pathToTmpTestSources));

    // then compile
    final String classpath = AutomaticBuilderFactory
            .getAutomaticBuilder(this.configuration)
            .buildClasspath(this.program.getProgramDir())
            + AmplificationHelper.PATH_SEPARATOR +
            this.program.getProgramDir() + "/" + this.program.getClassesDir()
            + AmplificationHelper.PATH_SEPARATOR + "target/dspot/dependencies/"
            + AmplificationHelper.PATH_SEPARATOR +
            this.program.getProgramDir() + "/" + this.program.getTestClassesDir();

    DSpotCompiler.compile(DSpotCompiler.pathToTmpTestSources, classpath,
            new File(this.program.getProgramDir() + "/" + this.program.getTestClassesDir()));

    AutomaticBuilderFactory
            .getAutomaticBuilder(this.configuration)
            .runPit(this.program.getProgramDir(), clone);
    final List<PitResult> pitResults = PitResultParser.parseAndDelete(program.getProgramDir() + AutomaticBuilderFactory
            .getAutomaticBuilder(this.configuration).getOutputDirectoryPit());
    final int numberOfSelectedAmplifiedTest = pitResults.stream()
            .filter(pitResult -> pitResult.getStateOfMutant() == PitResult.State.KILLED ||
                    pitResult.getStateOfMutant() == PitResult.State.SURVIVED)
            .filter(pitResult -> !this.originalMutantExecuted.contains(pitResult))
            .map(pitResult -> {
                final CtMethod amplifiedTestThatExecuteMoreMutants = pitResult.getMethod(clone);
                if (!this.mutantExecutedPerAmplifiedTestMethod.containsKey(amplifiedTestThatExecuteMoreMutants)) {
                    this.mutantExecutedPerAmplifiedTestMethod.put(amplifiedTestThatExecuteMoreMutants, new HashSet<>());
                }
                this.mutantExecutedPerAmplifiedTestMethod.get(amplifiedTestThatExecuteMoreMutants).add(pitResult);
                this.selectedAmplifiedTest.add(amplifiedTestThatExecuteMoreMutants);
                return amplifiedTestThatExecuteMoreMutants;
            }).collect(Collectors.toSet()).size();
    LOGGER.info("{} has been selected to amplify the test suite", numberOfSelectedAmplifiedTest);
    return amplifiedTestToBeKept;
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:52,代码来源:ExecutedMutantSelector.java

示例7: selectToKeep

import spoon.reflect.declaration.CtType; //导入方法依赖的package包/类
@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(AmplificationChecker::isTest)
            .forEach(clone::removeMethod);
    amplifiedTestToBeKept.forEach(clone::addMethod);

    DSpotUtils.printJavaFileWithComment(clone, new File(DSpotCompiler.pathToTmpTestSources));
    final AutomaticBuilder automaticBuilder = AutomaticBuilderFactory
            .getAutomaticBuilder(this.configuration);
    final String classpath = AutomaticBuilderFactory
            .getAutomaticBuilder(this.configuration)
            .buildClasspath(this.program.getProgramDir())
            + AmplificationHelper.PATH_SEPARATOR +
            this.program.getProgramDir() + "/" + this.program.getClassesDir()
            + AmplificationHelper.PATH_SEPARATOR + "target/dspot/dependencies/"
            + AmplificationHelper.PATH_SEPARATOR +
            this.program.getProgramDir() + "/" + this.program.getTestClassesDir();

    DSpotCompiler.compile(DSpotCompiler.pathToTmpTestSources, classpath,
            new File(this.program.getProgramDir() + "/" + this.program.getTestClassesDir()));

    AutomaticBuilderFactory
            .getAutomaticBuilder(this.configuration)
            .runPit(this.program.getProgramDir(), clone);
    final List<PitResult> results = PitResultParser.parseAndDelete(program.getProgramDir() + automaticBuilder.getOutputDirectoryPit());

    Set<CtMethod<?>> selectedTests = new HashSet<>();
    if (results != null) {
        LOGGER.info("{} mutants has been generated ({})", results.size(), this.numberOfMutant);
        if (results.size() != this.numberOfMutant) {
            LOGGER.warn("Number of generated mutant is different than the original one.");
        }
        results.stream()
                .filter(result -> result.getStateOfMutant() == PitResult.State.KILLED &&
                        !this.originalKilledMutants.contains(result) &&
                        !this.mutantNotTestedByOriginal.contains(result))
                .forEach(result -> {
                    CtMethod method = result.getMethod(clone);
                    if (killsMoreMutantThanParents(method, result)) {
                        if (!testThatKilledMutants.containsKey(method)) {
                            testThatKilledMutants.put(method, new HashSet<>());
                        }
                        testThatKilledMutants.get(method).add(result);
                        if (method == null) {
                            selectedTests.addAll(amplifiedTestToBeKept);// output of pit test does not allow us to know which test case kill new mutants... we keep them all...
                        } else {
                            selectedTests.add(method);
                        }
                    }
                });
    }

    this.selectedAmplifiedTest.addAll(selectedTests);

    selectedTests.forEach(selectedTest ->
            LOGGER.info("{} kills {} more mutants",
                    selectedTest == null ?
                            this.currentClassTestToBeAmplified.getSimpleName() : selectedTest.getSimpleName(),
                    this.testThatKilledMutants.containsKey(selectedTest) ?
                            this.testThatKilledMutants.get(selectedTest).size() : this.testThatKilledMutants.get(null))
    );
    return new ArrayList<>(selectedTests);
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:70,代码来源:PitMutantScoreSelector.java


注:本文中的spoon.reflect.declaration.CtType.setParent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。