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


Java Factory.createInvocation方法代码示例

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


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

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

示例2: generateEmptyCollection

import spoon.reflect.factory.Factory; //导入方法依赖的package包/类
static CtExpression<?> generateEmptyCollection(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));
    return factory.createInvocation(accessToCollections, executableReference);
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:13,代码来源:CollectionCreator.java

示例3: buildInvocation

import spoon.reflect.factory.Factory; //导入方法依赖的package包/类
private static CtInvocation buildInvocation(Factory factory, String methodName, List<CtExpression> arguments) {
	final CtInvocation invocation = factory.createInvocation();
	final CtExecutableReference<?> executableReference = factory.Core().createExecutableReference();
	executableReference.setStatic(true);
	executableReference.setSimpleName(methodName);
	executableReference.setDeclaringType(factory.createCtTypeReference(org.junit.Assert.class));
	invocation.setExecutable(executableReference);
	invocation.setArguments(arguments); // TODO
	invocation.setType(factory.Type().voidPrimitiveType());
	invocation.setTarget(factory.createTypeAccess(factory.createCtTypeReference(org.junit.Assert.class)));
	return invocation;
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:13,代码来源:AssertBuilder.java

示例4: createAssert

import spoon.reflect.factory.Factory; //导入方法依赖的package包/类
public static CtInvocation createAssert(String name, CtExpression... parameters) {
	final Factory factory = parameters[0].getFactory();
	CtTypeAccess accessToAssert =
			factory.createTypeAccess(factory.createCtTypeReference(Assert.class));
	CtExecutableReference assertEquals = factory.Type().get(Assert.class)
			.getMethodsByName(name).get(0).getReference();
	return factory.createInvocation(
			accessToAssert,
			assertEquals,
			parameters[0],
			parameters[1]
	);
}
 
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:14,代码来源:AssertionAdder.java


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