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


Java CtMethod.getSimpleName方法代码示例

本文整理汇总了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);
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:26,代码来源:TestLogProcessor.java

示例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));
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:21,代码来源:BranchCoverageTestSelector.java

示例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;
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:11,代码来源:BranchCoverageTestSelector.java

示例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<>();
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:11,代码来源:BranchCoverageTestSelector.java

示例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;
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:46,代码来源:MethodsAssertGenerator.java


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