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


Java CtMethod.getParent方法代码示例

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


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

示例1: apply

import spoon.reflect.declaration.CtMethod; //导入方法依赖的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

示例2: isTest

import spoon.reflect.declaration.CtMethod; //导入方法依赖的package包/类
public static boolean isTest(CtMethod<?> candidate) {
    CtClass<?> parent = candidate.getParent(CtClass.class);
    if (candidate.getAnnotation(org.junit.Ignore.class) != null) {
        return false;
    }
    if (candidate.isImplicit()
            || candidate.getVisibility() == null
            || !candidate.getVisibility().equals(ModifierKind.PUBLIC)
            || candidate.getBody() == null
            || candidate.getBody().getStatements().size() == 0
            || !candidate.getParameters().isEmpty()) {
        return false;
    }


    List<CtInvocation> listOfAssertion =
            candidate.getBody().getElements(new TypeFilter<CtInvocation>(CtInvocation.class) {
        @Override
        public boolean matches(CtInvocation element) {
            return hasAssertCall.test(element);
        }
    });

    if (listOfAssertion.isEmpty()) {
        listOfAssertion.addAll(candidate.getBody().getElements(new HasAssertInvocationFilter(3)));
    }

    if (!listOfAssertion.isEmpty()) {
        return true;
    }

    return (candidate.getAnnotation(org.junit.Test.class) != null ||
                    ((candidate.getSimpleName().contains("test") ||
                            candidate.getSimpleName().contains("should")) && !isTestJUnit4(parent)));
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:36,代码来源:AmplificationChecker.java


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