本文整理汇总了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());
}
示例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)));
}