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


Java Factory类代码示例

本文整理汇总了Java中spoon.reflect.factory.Factory的典型用法代码示例。如果您正苦于以下问题:Java Factory类的具体用法?Java Factory怎么用?Java Factory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: process

import spoon.reflect.factory.Factory; //导入依赖的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: process

import spoon.reflect.factory.Factory; //导入依赖的package包/类
public void process(String projectName, String path, OutputStream headerOutputStream, OutputStream codeOutputStream) {
    Launcher launcher = new Launcher();
    final String[] args = { "--input", path, "--output-type", "nooutput", "--enable-comments" };
    launcher.setArgs(args);
    launcher.run();

    OutputStreamCodeWriter headerCodeWriter = new OutputStreamCodeWriter(headerOutputStream);
    OutputStreamCodeWriter codeCodeWriter = new OutputStreamCodeWriter(codeOutputStream);
    SourceShovel sourceShovel = new SourceShovel(projectName, headerCodeWriter, codeCodeWriter);

    headerCodeWriter.println();

    Factory factory = launcher.getFactory();
    sourceShovel.addClasses(factory.Class().getAll());
    sourceShovel.generate();

    headerCodeWriter.close();
    codeCodeWriter.close();
}
 
开发者ID:slipperyseal,项目名称:trebuchet,代码行数:20,代码来源:Trebuchet.java

示例3: tryFinallyBody

import spoon.reflect.factory.Factory; //导入依赖的package包/类
protected CtTry tryFinallyBody(CtExecutable method) {
    if(!tryBodyMethod.containsKey(ProcessorUtil.methodId(method))) {
        Factory factory = method.getFactory();
        CtStatement thisStatement = getThisOrSuperCall(method.getBody());

        CtTry ctTry = factory.Core().createTry();
        ((CtTryImpl)ctTry).setBody(method.getBody());

        CtBlock finalizerBlock = factory.Core().createBlock();
        ctTry.setFinalizer(finalizerBlock);

        CtBlock methodBlock = factory.Core().createBlock();
        methodBlock.addStatement(ctTry);
        method.setBody(methodBlock);

        if (thisStatement != null) {
            ctTry.getBody().removeStatement(thisStatement);
            method.getBody().getStatements().add(0, thisStatement);
        }
        tryBodyMethod.put(ProcessorUtil.methodId(method), ctTry);
    }
    return tryBodyMethod.get(ProcessorUtil.methodId(method)) ;
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:24,代码来源:AbstractLoggingInstrumenter.java

示例4: generateSingletonList

import spoon.reflect.factory.Factory; //导入依赖的package包/类
@SuppressWarnings("unchecked")
static CtExpression<?> generateSingletonList(CtTypeReference type, String nameMethod, Class<?> typeOfCollection) {
    final Factory factory = type.getFactory();
    final CtType<?> collectionsType = factory.Type().get(Collections.class);
    final CtTypeAccess<?> accessToCollections = factory.createTypeAccess(collectionsType.getReference());
    final CtMethod<?> singletonListMethod = collectionsType.getMethodsByName(nameMethod).get(0);
    final CtExecutableReference executableReference = factory.Core().createExecutableReference();
    executableReference.setStatic(true);
    executableReference.setSimpleName(singletonListMethod.getSimpleName());
    executableReference.setDeclaringType(collectionsType.getReference());
    executableReference.setType(factory.createCtTypeReference(typeOfCollection));
    if (!type.getActualTypeArguments().isEmpty() &&
            type.getActualTypeArguments().stream().allMatch(ValueCreatorHelper::canGenerateAValueForType)) {
        executableReference.setParameters(type.getActualTypeArguments());
        List<CtExpression<?>> parameters = type.getActualTypeArguments().stream()
                .map(ValueCreator::generateRandomValue).collect(Collectors.toList());
        return factory.createInvocation(accessToCollections, executableReference, parameters);
    } else {
        return factory.createInvocation(accessToCollections, executableReference,
                factory.createConstructorCall(factory.Type().createReference(Object.class))
        );
    }
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:24,代码来源:CollectionCreator.java

示例5: buildSnippetAssertCollection

import spoon.reflect.factory.Factory; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static List<CtStatement> buildSnippetAssertCollection(Factory factory, String expression, Collection value) {
	final CtVariableAccess variableRead = factory.createVariableRead(
			factory.createLocalVariableReference().setSimpleName(expression),
			false
	);
	final CtExecutableReference contains = factory.Type().get(Collection.class).getMethodsByName("contains").get(0).getReference();
	return (List<CtStatement>) value.stream().map(factory::createLiteral)
			.map(o ->
					buildInvocation(factory, "assertTrue",
							Collections.singletonList(factory.createInvocation(variableRead,
									contains, (CtLiteral) o
									)
							)
					)
			)
			.collect(Collectors.toList());
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:19,代码来源:AssertBuilder.java

示例6: printPrimitiveString

import spoon.reflect.factory.Factory; //导入依赖的package包/类
private static CtExpression printPrimitiveString(Factory factory, Object value) {
	if (value == null || value instanceof String ||
			value instanceof Short ||
			value.getClass() == short.class ||
			value instanceof Double ||
			value.getClass() == double.class ||
			value instanceof Float ||
			value.getClass() == float.class ||
			value instanceof Long ||
			value.getClass() == long.class ||
			value instanceof Character ||
			value.getClass() == char.class ||
			value instanceof Byte ||
			value.getClass() == byte.class ||
			value instanceof Integer ||
			value.getClass() == int.class) {
		return factory.createLiteral(value);
	} else {
		return factory.createCodeSnippetExpression(value.toString());
	}
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:22,代码来源:AssertBuilder.java

示例7: removeAssertion

import spoon.reflect.factory.Factory; //导入依赖的package包/类
public void removeAssertion(CtInvocation<?> invocation) {
    final Factory factory = invocation.getFactory();
    invocation.getArguments().forEach(argument -> {
        CtExpression clone = ((CtExpression) argument).clone();
        if (clone instanceof CtUnaryOperator) {
            clone = ((CtUnaryOperator) clone).getOperand();
        }
        if (clone instanceof CtStatement) {
            invocation.insertBefore((CtStatement) clone);
        } else if (! (clone instanceof CtLiteral || clone instanceof CtVariableRead)) {
            CtTypeReference<?> typeOfParameter = clone.getType();
            if (clone.getType().equals(factory.Type().NULL_TYPE)) {
                typeOfParameter = factory.Type().createReference(Object.class);
            }
            final CtLocalVariable localVariable = factory.createLocalVariable(
                    typeOfParameter,
                    typeOfParameter.getSimpleName() + "_" + counter[0]++,
                    clone
            );
            invocation.insertBefore(localVariable);
        }
    });
    invocation.getParent(CtStatementList.class).removeStatement(invocation);
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:25,代码来源:AssertionRemover.java

示例8: testGenerateAllConstructorOf

import spoon.reflect.factory.Factory; //导入依赖的package包/类
@Test
public void testGenerateAllConstructorOf() throws Exception {

    final Factory factory = Utils.getFactory();

    final List<CtExpression> constructionOf =
            ConstructorCreator.generateAllConstructionOf(factory.Type()
                    .get("fr.inria.statementadd.ClassParameterAmplify")
                    .getReference()
            );
    assertEquals("new fr.inria.statementadd.ClassParameterAmplify(-1183186497)",
            constructionOf.get(0).toString());

    assertEquals("new fr.inria.statementadd.ClassParameterAmplify(new fr.inria.statementadd.ClassParameterAmplify(new fr.inria.statementadd.ClassParameterAmplify(1224731715)))",
            constructionOf.get(1).toString());

    assertEquals("new fr.inria.statementadd.ClassParameterAmplify(new fr.inria.statementadd.ClassParameterAmplify(new fr.inria.statementadd.ClassParameterAmplify(-538589801)), 562520686)",
            constructionOf.get(2).toString());

    //TODO this null value is probably not useful
    assertEquals("null",
            constructionOf.get(3).toString());
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:24,代码来源:TestConstructorCreator.java

示例9: testGenerateConstructionOf

import spoon.reflect.factory.Factory; //导入依赖的package包/类
@Test
public void testGenerateConstructionOf() throws Exception {
    final Factory factory = Utils.getFactory();

    CtExpression constructionOf = ConstructorCreator.generateConstructionOf(factory.Type()
            .get("fr.inria.statementadd.ClassParameterAmplify")
            .getReference()
    );

    assertEquals("new fr.inria.statementadd.ClassParameterAmplify(866555445)",
            constructionOf.toString());

    constructionOf = ConstructorCreator.generateConstructionOf(factory.Type()
            .get("fr.inria.statementadd.ClassParameterAmplify")
            .getReference()
    );

    assertEquals("new fr.inria.statementadd.ClassParameterAmplify(1224731715)",
            constructionOf.toString());
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:21,代码来源:TestConstructorCreator.java

示例10: testOnClassWithJavaObjects

import spoon.reflect.factory.Factory; //导入依赖的package包/类
@Test
public void testOnClassWithJavaObjects() throws Exception {

    /*
        Test that the StatementAdd amplifier is able to generate, and manage Collection and Map from java.util
     */

    final String packageName = "fr.inria.statementadd";
    InputProgram inputProgram = Utils.getInputProgram();
    final Factory factory = inputProgram.getFactory();
    inputProgram.setFactory(factory);
    AmplificationHelper.setSeedRandom(32L);
    StatementAdd amplifier = new StatementAdd(packageName);
    amplifier.reset(factory.Class().get(packageName + ".ClassTarget"));

    CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTarget"), "test");
    List<CtMethod> amplifiedMethods = amplifier.apply(ctMethod);

    System.out.println(amplifiedMethods);

    assertEquals(7, amplifiedMethods.size());
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:23,代码来源:StatementAddTest.java

示例11: testStatementAddOnArrayObjects

import spoon.reflect.factory.Factory; //导入依赖的package包/类
@Test
public void testStatementAddOnArrayObjects() throws Exception {
    final String packageName = "fr.inria.statementaddarray";
    InputProgram inputProgram = Utils.getInputProgram();
    final Factory factory = inputProgram.getFactory();
    inputProgram.setFactory(factory);
    AmplificationHelper.setSeedRandom(32L);
    StatementAdd amplifier = new StatementAdd(packageName);
    amplifier.reset(factory.Class().get(packageName + ".ClassTargetAmplify"));

    CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTargetAmplify"), "test");
    List<CtMethod> amplifiedMethods = amplifier.apply(ctMethod);

    System.out.println(amplifiedMethods);

    assertEquals(5, amplifiedMethods.size());
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:18,代码来源:StatementAddTest.java

示例12: testStatementAddOnUnderTest

import spoon.reflect.factory.Factory; //导入依赖的package包/类
@Test
public void testStatementAddOnUnderTest() throws Exception {
    Factory factory = Utils.getFactory();
    CtClass<Object> ctClass = factory.Class().get("fr.inria.mutation.ClassUnderTestTest");
    AmplificationHelper.setSeedRandom(23L);

    StatementAdd amplificator = new StatementAdd();
    amplificator.reset(ctClass);

    CtMethod originalMethod = Utils.findMethod(ctClass, "testLit");

    List<CtMethod> amplifiedMethods = amplificator.apply(originalMethod);

    System.out.println(amplifiedMethods);

    assertEquals(2, amplifiedMethods.size());
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:18,代码来源:StatementAddTest.java

示例13: testStatementAdd

import spoon.reflect.factory.Factory; //导入依赖的package包/类
@Test
public void testStatementAdd() throws Exception {

    /*
        Test the StatementAdd amplifier. It reuse existing object to add method call of accessible method.
        It can reuse return value to add method call. It results here with 7 new test cases.
     */

    final String packageName = "fr.inria.statementadd";
    InputProgram inputProgram = Utils.getInputProgram();
    final Factory factory = inputProgram.getFactory();
    inputProgram.setFactory(factory);
    AmplificationHelper.setSeedRandom(42L);
    StatementAdd amplifier = new StatementAdd(packageName);
    amplifier.reset(factory.Class().get(packageName + ".ClassTargetAmplify"));

    CtMethod<?> ctMethod = Utils.findMethod(factory.Class().get(packageName + ".TestClassTargetAmplify"), "test");
    List<CtMethod> amplifiedMethods = amplifier.apply(ctMethod);

    System.out.println(amplifiedMethods);

    assertEquals(6, amplifiedMethods.size());
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:24,代码来源:StatementAddTest.java

示例14: modelFor

import spoon.reflect.factory.Factory; //导入依赖的package包/类
public static Factory modelFor(Factory factory, File[] sourceFiles, URL[] classpath) {
    factory.getEnvironment().setLevel("OFF");
    try {
        SpoonModelBuilder compiler = launcher().createCompiler(factory);
        if (classpath != null) {
            compiler.setSourceClasspath(JavaLibrary.asFilePath(classpath));
        }
        for (int i = 0; i < sourceFiles.length; i++) {
            File sourceFile = sourceFiles[i];
            compiler.addInputSource(sourceFile);
        }
        compiler.build();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return factory;
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:18,代码来源:SpoonModelLibrary.java

示例15: testCatchProcessor

import spoon.reflect.factory.Factory; //导入依赖的package包/类
@Test
public void testCatchProcessor() throws Exception {
	final String[] args = {
			"-i", "src/test/resources/src/",
			"-o", "target/spooned/"
	};

	final Launcher launcher = new Launcher();
	launcher.setArgs(args);
	launcher.run();

	final Factory factory = launcher.getFactory();
	final ProcessingManager processingManager = new QueueProcessingManager(factory);
	final CatchProcessor processor = new CatchProcessor();
	processingManager.addProcessor(processor);
	processingManager.process(factory.Class().getAll());

	assertEquals(2, processor.emptyCatchs.size());
}
 
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:20,代码来源:CatchProcessorTest.java


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