本文整理汇总了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))
);
}
}
示例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);
}
示例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;
}
示例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]
);
}