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