本文整理汇总了Java中spoon.reflect.reference.CtTypeReference.getFactory方法的典型用法代码示例。如果您正苦于以下问题:Java CtTypeReference.getFactory方法的具体用法?Java CtTypeReference.getFactory怎么用?Java CtTypeReference.getFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spoon.reflect.reference.CtTypeReference
的用法示例。
在下文中一共展示了CtTypeReference.getFactory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateSingletonList
import spoon.reflect.reference.CtTypeReference; //导入方法依赖的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.reference.CtTypeReference; //导入方法依赖的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: generateNullValue
import spoon.reflect.reference.CtTypeReference; //导入方法依赖的package包/类
@Deprecated
public static CtLocalVariable generateNullValue(CtTypeReference type) {
Factory factory = type.getFactory();
final CtLiteral<?> defaultExpression = factory.createLiteral(null);
defaultExpression.addTypeCast(type);
return factory.Code().createLocalVariable(type, "vc_" + count++, defaultExpression);
}