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


Java CtMethod.setSimpleName方法代码示例

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


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

示例1: cloneMethod

import spoon.reflect.declaration.CtMethod; //导入方法依赖的package包/类
protected CtMethod cloneMethod(CtMethod method, String suffix) {
    count++;
    CtMethod cloned_method = this.getFactory().Core().clone(method);
    cloned_method.setParent(method.getParent());
    //rename the clone
    cloned_method.setSimpleName(method.getSimpleName()+suffix+cloneNumber);
    cloneNumber++;

    CtAnnotation toRemove = cloned_method.getAnnotations().stream()
                                         .filter(annotation -> annotation.toString().contains("Override"))
                                         .findFirst().orElse(null);

    if(toRemove != null) {
        cloned_method.removeAnnotation(toRemove);
    }
    mutatedMethod.add(cloned_method);
    return cloned_method;
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:19,代码来源:TestProcessor.java

示例2: cloneMethod

import spoon.reflect.declaration.CtMethod; //导入方法依赖的package包/类
private static CtMethod cloneMethod(CtMethod method, String suffix) {
    CtMethod cloned_method = method.clone();
    //rename the clone
    cloned_method.setSimpleName(method.getSimpleName() + (suffix.isEmpty() ? "" : suffix + cloneNumber));
    cloneNumber++;

    CtAnnotation toRemove = cloned_method.getAnnotations().stream()
            .filter(annotation -> annotation.toString().contains("Override"))
            .findFirst().orElse(null);

    if (toRemove != null) {
        cloned_method.removeAnnotation(toRemove);
    }
    return cloned_method;
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:16,代码来源:AmplificationHelper.java

示例3: createTestWithLog

import spoon.reflect.declaration.CtMethod; //导入方法依赖的package包/类
static CtMethod<?> createTestWithLog(CtMethod test, final String filter) {
    CtMethod clone = AmplificationHelper.cloneMethodTest(test, "");
    clone.setSimpleName(test.getSimpleName() + "_withlog");
    final List<CtStatement> allStatement = clone.getElements(new TypeFilter<>(CtStatement.class));
    allStatement.stream()
            .filter(statement -> isStmtToLog(filter, statement))
            .forEach(statement ->
                    addLogStmt(statement,
                            test.getSimpleName() + "__" + indexOfByRef(allStatement, statement))
            );
    return clone;
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:13,代码来源:AssertGeneratorHelper.java

示例4: apply

import spoon.reflect.declaration.CtMethod; //导入方法依赖的package包/类
@Override
public List<CtMethod> apply(CtMethod testMethod) {
    final CtCodeSnippetStatement snippet = testMethod.getFactory().Code().
            createCodeSnippetStatement("UncompilableClass class = new UncompilableClass()");
    final CtMethod method = testMethod.clone();
    method.getBody().insertEnd(snippet);
    method.setSimpleName("uncompilableTest");

    final CtCodeSnippetStatement snippet1 = testMethod.getFactory().Code().createCodeSnippetStatement("String clazz = new String()");
    final CtMethod method1 = testMethod.clone();
    method1.getBody().insertEnd(snippet1);
    method1.setSimpleName("compilableTest");

    return Arrays.asList(method, method1);
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:16,代码来源:DSpotCompilerTest.java

示例5: getClass

import spoon.reflect.declaration.CtMethod; //导入方法依赖的package包/类
private CtClass<?> getClass(Factory factory) {
    final CtClass<?> aClass = factory.Class().create("MyTestClass");
    final CtMethod<Void> method = factory.createMethod();
    method.setSimpleName("method");
    method.setType(factory.Type().VOID_PRIMITIVE);
    method.setBody(factory.createCodeSnippetStatement("System.out.println()"));
    method.addModifier(ModifierKind.PUBLIC);
    aClass.addMethod(method);
    return aClass;
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:11,代码来源:DSpotCompilerTest.java

示例6: performExtraction

import spoon.reflect.declaration.CtMethod; //导入方法依赖的package包/类
public static CtMethod<?> performExtraction(CtMethod<?> ctMethod) {

        // remove assertion

        final CtMethod<?> ctMethodWithoutAssertion =
                new AssertionRemover().removeAssertion(ctMethod);

        final Factory factory = ctMethodWithoutAssertion.getFactory();
        final CtMethod<?> extractedMethod = ctMethodWithoutAssertion.clone();

        extractedMethod.setSimpleName("extract_" + ctMethodWithoutAssertion.getSimpleName());
        new ArrayList<>(extractedMethod.getThrownTypes()).forEach(extractedMethod::removeThrownType);
        extractedMethod.setParent(ctMethod.getParent());
        ctMethodWithoutAssertion.getAnnotations().forEach(extractedMethod::removeAnnotation);
        final int[] count = new int[1];
        final Map<CtAbstractInvocation<?>, List<CtVariableAccess>> parametersPerInvocation =
                new HashMap<>();
        extractedMethod.getElements(new TypeFilter<>(CtLiteral.class))
                .stream()
                .filter(ctLiteral -> !(ctLiteral.getValue() instanceof String)) // TODO
                .forEach(ctLiteral -> {
                    final CtParameter<?> parameter = factory.createParameter();
                    parameter.setType(ctLiteral.getType());
                    parameter.setSimpleName("lit" + count[0]++);
                    extractedMethod.addParameter(parameter);
                    final CtVariableAccess<?> variableRead = factory.createVariableRead(factory.createParameterReference(parameter), false);
                    final CtAbstractInvocation invocation = ctLiteral.getParent(CtAbstractInvocation.class);
                    if (invocation != null) {
                        if (!parametersPerInvocation.containsKey(invocation)) {
                            parametersPerInvocation.put(invocation, new ArrayList<>());
                        }
                        if (ctLiteral.getParent() instanceof CtUnaryOperator) {
                            parametersPerInvocation.get(invocation)
                                    .add(invocation.getArguments().indexOf(ctLiteral.getParent()), variableRead);
                        } else {
                            parametersPerInvocation.get(invocation)
                                    .add(invocation.getArguments().indexOf(ctLiteral), variableRead);
                        }
                    } else {
                        ctLiteral.replace(variableRead);
                    }
                });

        extractedMethod.getElements(new TypeFilter<>(CtAbstractInvocation.class))
                .stream()
                .filter(parametersPerInvocation::containsKey)
                .forEach(ctAbstractInvocation ->
                    ctAbstractInvocation.setArguments(parametersPerInvocation.get(ctAbstractInvocation))
                );

        return extractedMethod;
    }
 
开发者ID:STAMP-project,项目名称:Ex2Amplifier,代码行数:53,代码来源:ArgumentsExtractor.java

示例7: 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

示例8: test

import spoon.reflect.declaration.CtMethod; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
    final File javaFile = new File(outputDirectory.getAbsolutePath() + "/" + "example.TestSuiteExample".replaceAll("\\.", "\\/") + ".java");
    try {
        FileUtils.forceDelete(javaFile);
    } catch (IOException ignored) {
        //ignored
    }

    Launcher launcher = new Launcher();
    launcher.addInputResource("src/test/resources/test-projects/src/test/java/example/TestSuiteExample.java");
    launcher.getEnvironment().setNoClasspath(true);
    launcher.buildModel();
    final CtType<?> type = launcher.getFactory().Type().get("example.TestSuiteExample");

    assertFalse(javaFile.exists());
    DSpotUtils.printAmplifiedTestClass(type, outputDirectory);
    assertTrue(javaFile.exists());

    final CtMethod<?> clone = type.getMethods().stream()
            .findFirst().get().clone();
    final int nbMethodStart = type.getMethods().size();
    type.getMethods().forEach(type::removeMethod);
    clone.setSimpleName("MyNewMethod");
    type.addMethod(clone);

    DSpotUtils.printAmplifiedTestClass(type, outputDirectory);
    launcher = new Launcher();
    launcher.addInputResource(outputDirectory.getAbsolutePath() + "/" + "example.TestSuiteExample".replaceAll("\\.", "\\/") + ".java");
    launcher.getEnvironment().setNoClasspath(true);
    launcher.buildModel();

    assertEquals(nbMethodStart + 1, launcher.getFactory().Class().get("example.TestSuiteExample").getMethods().size());

    type.getMethods().forEach(type::removeMethod);
    clone.setSimpleName("MyNewMethod2");
    type.addMethod(clone);

    DSpotUtils.printAmplifiedTestClass(type, outputDirectory);
    launcher = new Launcher();
    launcher.addInputResource(outputDirectory.getAbsolutePath() + "/" + "example.TestSuiteExample".replaceAll("\\.", "\\/") + ".java");
    launcher.getEnvironment().setNoClasspath(true);
    launcher.buildModel();

    assertEquals(nbMethodStart + 2, launcher.getFactory().Class().get("example.TestSuiteExample").getMethods().size());
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:47,代码来源:PrintTest.java


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