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


Java Primitive类代码示例

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


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

示例1: getType

import japa.parser.ast.type.PrimitiveType.Primitive; //导入依赖的package包/类
/**
 * Given a primitive type, computes the corresponding Java Parser type.
 * <p>
 * Presenting a non-primitive type to this method will throw an exception.
 * If you have a non-primitive type, use
 * {@link #importTypeIfRequired(JavaType, List, JavaType)} and then present
 * the {@link NameExpr} it returns to
 * {@link #getClassOrInterfaceType(NameExpr)}.
 * 
 * @param javaType a primitive type (required, and must be primitive)
 * @return the equivalent Java Parser {@link Type}
 */
public static Type getType(final JavaType javaType) {
    Validate.notNull(javaType, "Java type required");
    Validate.isTrue(javaType.isPrimitive(),
            "Java type must be primitive to be presented to this method");
    if (javaType.equals(JavaType.VOID_PRIMITIVE)) {
        return new VoidType();
    }
    else if (javaType.equals(JavaType.BOOLEAN_PRIMITIVE)) {
        return new PrimitiveType(Primitive.Boolean);
    }
    else if (javaType.equals(JavaType.BYTE_PRIMITIVE)) {
        return new PrimitiveType(Primitive.Byte);
    }
    else if (javaType.equals(JavaType.CHAR_PRIMITIVE)) {
        return new PrimitiveType(Primitive.Char);
    }
    else if (javaType.equals(JavaType.DOUBLE_PRIMITIVE)) {
        return new PrimitiveType(Primitive.Double);
    }
    else if (javaType.equals(JavaType.FLOAT_PRIMITIVE)) {
        return new PrimitiveType(Primitive.Float);
    }
    else if (javaType.equals(JavaType.INT_PRIMITIVE)) {
        return new PrimitiveType(Primitive.Int);
    }
    else if (javaType.equals(JavaType.LONG_PRIMITIVE)) {
        return new PrimitiveType(Primitive.Long);
    }
    else if (javaType.equals(JavaType.SHORT_PRIMITIVE)) {
        return new PrimitiveType(Primitive.Short);
    }
    throw new IllegalStateException("Unknown primitive " + javaType);
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:46,代码来源:JavaParserUtils.java

示例2: visit

import japa.parser.ast.type.PrimitiveType.Primitive; //导入依赖的package包/类
@Override
public MethodDeclaration visit(MethodDeclaration n, Void arg) {
    if (!n.isGenerator()) {
        throw new UnsupportedOperationException("cannot transform non-generator");
    }

    // Desugar ALL the loops!
    n.accept(new LoopDesugarTransform(), null);
    if (CompilerSettings.dumpDesugar) {
        System.err.println(n);
    }

    Generator g = new Generator();
    Map<String, TypedVariableDeclarator> vars = new HashMap<String, TypedVariableDeclarator>();

    // Mangle all our scope variables.
    n.accept(new ScopeMangleTransform(), vars);
    if (CompilerSettings.dumpMangle) {
        System.err.println(n);
    }

    // Generate the body.
    n.accept(new LinearizeTransform(), g);

    List<BodyDeclaration> generatorBody = new ArrayList<BodyDeclaration>();

    // Add the fields to the generator body.
    for (Map.Entry<String, TypedVariableDeclarator> kv : vars.entrySet()) {
        VariableDeclarator decl = new VariableDeclarator(new VariableDeclaratorId(kv.getKey()), null);
        generatorBody.add(new FieldDeclaration(ModifierSet.PRIVATE, kv.getValue().type, decl));
    }

    // Add the moveNext method to the generator body.
    generatorBody.add(new MethodDeclaration(0, 0, 0, 0, null, ModifierSet.PROTECTED,
                                            null, null, new PrimitiveType(Primitive.Boolean),
                                            "moveNext", null, 0, null, false,
                                            new BlockStmt(g.generate())));

    ObjectCreationExpr o = new ObjectCreationExpr(0, 0, 0, 0, null, makeRtGeneratorType(n.getType()), null, null, generatorBody);
    List<Statement> methodBody = new ArrayList<Statement>();
    methodBody.add(new ReturnStmt(o));
    MethodDeclaration n2 = new MethodDeclaration(n.getBeginLine(),
            n.getBeginColumn(),
            n.getEndLine(),
            n.getEndColumn(),
            n.getJavaDoc(),
            n.getModifiers(),
            n.getAnnotations(),
            n.getTypeParameters(),
            makeRtGeneratorType(n.getType()),
            n.getName(),
            n.getParameters(),
            n.getArrayCount(),
            n.getThrows(),
            false,
            new BlockStmt(methodBody));

    return n2;
}
 
开发者ID:rfw,项目名称:genja,代码行数:60,代码来源:GeneratorTransform.java


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