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


Java CtTypeReference.getFactory方法代码示例

本文整理汇总了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))
        );
    }
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:24,代码来源:CollectionCreator.java

示例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);
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:13,代码来源:CollectionCreator.java

示例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);
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:8,代码来源:ValueCreator.java


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