本文整理汇总了Java中spoon.reflect.declaration.CtMethod.getSimpleName方法的典型用法代码示例。如果您正苦于以下问题:Java CtMethod.getSimpleName方法的具体用法?Java CtMethod.getSimpleName怎么用?Java CtMethod.getSimpleName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spoon.reflect.declaration.CtMethod
的用法示例。
在下文中一共展示了CtMethod.getSimpleName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import spoon.reflect.declaration.CtMethod; //导入方法依赖的package包/类
public void process(CtMethod element) {
Factory factory = this.getFactory();
CtTry ctTry = factory.Core().createTry();
ctTry.setBody(element.getBody());
String snippet;
String testName;
if(element.getModifiers().contains(ModifierKind.STATIC)) {
testName = element.getPosition().getCompilationUnit().getMainType().getQualifiedName() + "." + element.getSimpleName();
snippet = this.getLogName() + ".testIn(Thread.currentThread(), \"" + testName + "\")";
} else {
testName = element.getSimpleName();
snippet = this.getLogName() + ".testIn(Thread.currentThread(),this, \"" + testName + "\")";
}
CtCodeSnippetStatement snippetStatement = factory.Code().createCodeSnippetStatement(snippet);
element.getBody().insertBegin(snippetStatement);
snippet = this.getLogName() + ".testOut(Thread.currentThread())";
CtCodeSnippetStatement snippetFinish = factory.Code().createCodeSnippetStatement(snippet);
CtBlock finalizerBlock = factory.Core().createBlock();
finalizerBlock.addStatement(snippetFinish);
ctTry.setFinalizer(finalizerBlock);
CtBlock methodBlock = factory.Core().createBlock();
methodBlock.addStatement(ctTry);
element.setBody(methodBlock);
}
示例2: updateOldMethods
import spoon.reflect.declaration.CtMethod; //导入方法依赖的package包/类
private void updateOldMethods() {
List<CtMethod> oldMethods = new ArrayList<>();
for (CtMethod test : oldTests) {
String testName = test.getSimpleName();
if (!testAges.containsKey(testName)) {
testAges.put(testName, getAgesFor(test));
}
if (testAges.get(testName) > 0) {
oldMethods.add(test);
}
}
while (oldMethods.size() > maxNumberOfTest) {
final Integer minAge = testAges.get(oldMethods.stream().min((m1, m2) -> testAges.get(m1.getSimpleName()) - testAges.get(m2.getSimpleName())).get().getSimpleName());
Optional<CtMethod> oldestMethod;
while ((oldestMethod = oldMethods.stream().filter(method -> testAges.get(method.getSimpleName()).equals(minAge)).findAny()).isPresent()) {
oldMethods.remove(oldestMethod.get());
}
}
oldMethods.forEach(method -> testAges.put(method.getSimpleName(), testAges.get(method.getSimpleName()) - 1));
}
示例3: getAgesFor
import spoon.reflect.declaration.CtMethod; //导入方法依赖的package包/类
private int getAgesFor(CtMethod test) {
String testName = test.getSimpleName();
if (testName.contains("_cf")) {
return 2;
}
if (!AmplificationHelper.getAmpTestToParent().containsKey(test)) {
return 3;
}
return 0;
}
示例4: getParentTestCoverageFor
import spoon.reflect.declaration.CtMethod; //导入方法依赖的package包/类
private Set<String> getParentTestCoverageFor(CtMethod mth) {
CtMethod parent = getParent(mth);
if (parent != null) {
String parentName = parent.getSimpleName();
if (parentName != null) {
return getCoverageFor(parentName);
}
}
return new HashSet<>();
}
示例5: makeFailureTest
import spoon.reflect.declaration.CtMethod; //导入方法依赖的package包/类
protected CtMethod<?> makeFailureTest(CtMethod<?> test, Failure failure) {
CtMethod cloneMethodTest = AmplificationHelper.cloneMethodTest(test, "");
cloneMethodTest.setSimpleName(test.getSimpleName());
Factory factory = cloneMethodTest.getFactory();
Throwable exception = failure.getException();
if (exception instanceof TestTimedOutException || // TestTimedOutException means infinite loop
exception instanceof AssertionError) { // AssertionError means that some assertion remained in the test: TODO
return null;
}
Class exceptionClass;
if (exception == null) {
exceptionClass = Exception.class;
} else {
exceptionClass = exception.getClass();
}
CtTry tryBlock = factory.Core().createTry();
tryBlock.setBody(cloneMethodTest.getBody());
String snippet = "org.junit.Assert.fail(\"" + test.getSimpleName() + " should have thrown " + exceptionClass.getSimpleName() + "\")";
tryBlock.getBody().addStatement(factory.Code().createCodeSnippetStatement(snippet));
DSpotUtils.addComment(tryBlock, "AssertGenerator generate try/catch block with fail statement", CtComment.CommentType.INLINE);
CtCatch ctCatch = factory.Core().createCatch();
CtTypeReference exceptionType = factory.Type().createReference(exceptionClass);
ctCatch.setParameter(factory.Code().createCatchVariable(exceptionType, "eee"));
ctCatch.setBody(factory.Core().createBlock());
List<CtCatch> catchers = new ArrayList<>(1);
catchers.add(ctCatch);
tryBlock.setCatchers(catchers);
CtBlock body = factory.Core().createBlock();
body.addStatement(tryBlock);
cloneMethodTest.setBody(body);
cloneMethodTest.setSimpleName(cloneMethodTest.getSimpleName() + "_failAssert" + (numberOfFail++));
Counter.updateAssertionOf(cloneMethodTest, 1);
AmplificationHelper.getAmpTestToParent().put(cloneMethodTest, test);
return cloneMethodTest;
}