本文整理汇总了Java中com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree类的典型用法代码示例。如果您正苦于以下问题:Java JCPrimitiveTypeTree类的具体用法?Java JCPrimitiveTypeTree怎么用?Java JCPrimitiveTypeTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JCPrimitiveTypeTree类属于com.sun.tools.javac.tree.JCTree包,在下文中一共展示了JCPrimitiveTypeTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDefaultExpr
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; //导入依赖的package包/类
private static JCExpression getDefaultExpr(JavacTreeMaker maker, JCExpression type) {
if (type instanceof JCPrimitiveTypeTree) {
switch (((JCPrimitiveTypeTree) type).getPrimitiveTypeKind()) {
case BOOLEAN:
return maker.Literal(CTC_BOOLEAN, 0);
case CHAR:
return maker.Literal(CTC_CHAR, 0);
default:
case BYTE:
case SHORT:
case INT:
return maker.Literal(CTC_INT, 0);
case LONG:
return maker.Literal(CTC_LONG, 0L);
case FLOAT:
return maker.Literal(CTC_FLOAT, 0F);
case DOUBLE:
return maker.Literal(CTC_DOUBLE, 0D);
}
}
return maker.Literal(CTC_BOT, null);
}
示例2: visitTypeIdent
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; //导入依赖的package包/类
public void visitTypeIdent(JCPrimitiveTypeTree tree) {
TypeTag typetag = typeTag(tree);
try {
if (CTC_BYTE.equals(typetag)) print ("byte");
else if (CTC_CHAR.equals(typetag)) print ("char");
else if (CTC_SHORT.equals(typetag)) print ("short");
else if (CTC_INT.equals(typetag)) print ("int");
else if (CTC_LONG.equals(typetag)) print ("long");
else if (CTC_FLOAT.equals(typetag)) print ("float");
else if (CTC_DOUBLE.equals(typetag)) print ("double");
else if (CTC_BOOLEAN.equals(typetag)) print ("boolean");
else if (CTC_VOID.equals(typetag)) print ("void");
else print("error");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例3: visit
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; //导入依赖的package包/类
@Override
public void visit(GenericTypeWrapper w) {
JCExpression eouter = generate(w.getOuter());
List<JCExpression> params = generate(w.getTypeParameters(),
JCExpression.class);
ListBuffer<JCExpression> newList = new ListBuffer<JCExpression>();
for (JCExpression param : params) {
JCExpression p2 = param;
if (param.getKind() == Kind.PRIMITIVE_TYPE) {
p2 = builder.boxPrimitiveType((JCPrimitiveTypeTree) param);
}
newList.append(p2);
}
result = builder.getTreeMaker().TypeApply(eouter, newList.toList());
}
示例4: diffTypeIdent
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; //导入依赖的package包/类
protected int diffTypeIdent(JCPrimitiveTypeTree oldT, JCPrimitiveTypeTree newT, int[] bounds) {
if (oldT.typetag != newT.typetag) {
printer.print(newT);
} else {
copyTo(bounds[0], bounds[1]);
}
return bounds[1];
}
示例5: visitTypeIdent
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; //导入依赖的package包/类
@Override public void visitTypeIdent(JCPrimitiveTypeTree tree) {
TypeTag typeTag = typeTag(tree);
if (CTC_BYTE.equals(typeTag)) print("byte");
else if (CTC_CHAR.equals(typeTag)) print("char");
else if (CTC_SHORT.equals(typeTag)) print("short");
else if (CTC_INT.equals(typeTag)) print("int");
else if (CTC_LONG.equals(typeTag)) print("long");
else if (CTC_FLOAT.equals(typeTag)) print("float");
else if (CTC_DOUBLE.equals(typeTag)) print("double");
else if (CTC_BOOLEAN.equals(typeTag)) print("boolean");
else if (CTC_VOID.equals(typeTag)) print("void");
else print("error");
}
示例6: visitTypeIdent
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; //导入依赖的package包/类
public void visitTypeIdent(JCPrimitiveTypeTree that) {
try {
print("JCPrimitiveTypeTree:");
} catch (Exception e) {
}
super.visitTypeIdent(that);
}
示例7: visitTypeIdent
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; //导入依赖的package包/类
public void visitTypeIdent(JCPrimitiveTypeTree tree) {
try {
switch(tree.typetag) {
case TypeTags.BYTE:
print("byte");
break;
case TypeTags.CHAR:
print("char");
break;
case TypeTags.SHORT:
print("short");
break;
case TypeTags.INT:
print("int");
break;
case TypeTags.LONG:
print("long");
break;
case TypeTags.FLOAT:
print("float");
break;
case TypeTags.DOUBLE:
print("double");
break;
case TypeTags.BOOLEAN:
print("boolean");
break;
case TypeTags.VOID:
print("void");
break;
default:
print("error");
break;
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例8: methodReturns
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; //导入依赖的package包/类
public static Matcher<MethodTree> methodReturns(final Type returnType) {
return new Matcher<MethodTree>() {
@Override
public boolean matches(MethodTree methodTree, VisitorState state) {
Tree returnTree = methodTree.getReturnType();
Type methodReturnType = null;
if (returnTree == null) {
// This is a constructor, it has no return type.
return false;
}
switch (returnTree.getKind()) {
case ARRAY_TYPE:
methodReturnType = ((JCArrayTypeTree)returnTree).type;
break;
case PRIMITIVE_TYPE:
methodReturnType = ((JCPrimitiveTypeTree)returnTree).type;
break;
case PARAMETERIZED_TYPE:
methodReturnType = ((JCTypeApply)returnTree).type;
break;
default:
return false;
}
return state.getTypes().isSameType(methodReturnType, returnType);
}
};
}
示例9: TypeIdent
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; //导入依赖的package包/类
public JCPrimitiveTypeTree TypeIdent(TypeTag typetag) {
return invoke(TypeIdent, typetag.value);
}
示例10: createToString
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; //导入依赖的package包/类
static JCMethodDecl createToString(JavacNode typeNode, Collection<JavacNode> fields, boolean includeFieldNames, boolean callSuper, FieldAccess fieldAccess, JCTree source) {
JavacTreeMaker maker = typeNode.getTreeMaker();
JCAnnotation overrideAnnotation = maker.Annotation(genJavaLangTypeRef(typeNode, "Override"), List.<JCExpression>nil());
JCModifiers mods = maker.Modifiers(Flags.PUBLIC, List.of(overrideAnnotation));
JCExpression returnType = genJavaLangTypeRef(typeNode, "String");
boolean first = true;
String typeName = getTypeName(typeNode);
String infix = ", ";
String suffix = ")";
String prefix;
if (callSuper) {
prefix = typeName + "(super=";
} else if (fields.isEmpty()) {
prefix = typeName + "()";
} else if (includeFieldNames) {
prefix = typeName + "(" + ((JCVariableDecl)fields.iterator().next().get()).name.toString() + "=";
} else {
prefix = typeName + "(";
}
JCExpression current = maker.Literal(prefix);
if (callSuper) {
JCMethodInvocation callToSuper = maker.Apply(List.<JCExpression>nil(),
maker.Select(maker.Ident(typeNode.toName("super")), typeNode.toName("toString")),
List.<JCExpression>nil());
current = maker.Binary(CTC_PLUS, current, callToSuper);
first = false;
}
for (JavacNode fieldNode : fields) {
JCExpression expr;
JCExpression fieldAccessor = createFieldAccessor(maker, fieldNode, fieldAccess);
JCExpression fieldType = getFieldType(fieldNode, fieldAccess);
// The distinction between primitive and object will be useful if we ever add a 'hideNulls' option.
boolean fieldIsPrimitive = fieldType instanceof JCPrimitiveTypeTree;
boolean fieldIsPrimitiveArray = fieldType instanceof JCArrayTypeTree && ((JCArrayTypeTree) fieldType).elemtype instanceof JCPrimitiveTypeTree;
boolean fieldIsObjectArray = !fieldIsPrimitiveArray && fieldType instanceof JCArrayTypeTree;
@SuppressWarnings("unused")
boolean fieldIsObject = !fieldIsPrimitive && !fieldIsPrimitiveArray && !fieldIsObjectArray;
if (fieldIsPrimitiveArray || fieldIsObjectArray) {
JCExpression tsMethod = chainDots(typeNode, "java", "util", "Arrays", fieldIsObjectArray ? "deepToString" : "toString");
expr = maker.Apply(List.<JCExpression>nil(), tsMethod, List.<JCExpression>of(fieldAccessor));
} else expr = fieldAccessor;
if (first) {
current = maker.Binary(CTC_PLUS, current, expr);
first = false;
continue;
}
if (includeFieldNames) {
current = maker.Binary(CTC_PLUS, current, maker.Literal(infix + fieldNode.getName() + "="));
} else {
current = maker.Binary(CTC_PLUS, current, maker.Literal(infix));
}
current = maker.Binary(CTC_PLUS, current, expr);
}
if (!first) current = maker.Binary(CTC_PLUS, current, maker.Literal(suffix));
JCStatement returnStatement = maker.Return(current);
JCBlock body = maker.Block(0, List.of(returnStatement));
return recursiveSetGeneratedBy(maker.MethodDef(mods, typeNode.toName("toString"), returnType,
List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null), source, typeNode.getContext());
}
示例11: cloneType0
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; //导入依赖的package包/类
private static JCExpression cloneType0(JavacTreeMaker maker, JCTree in) {
if (in == null) return null;
if (in instanceof JCPrimitiveTypeTree) return (JCExpression) in;
if (in instanceof JCIdent) {
return maker.Ident(((JCIdent) in).name);
}
if (in instanceof JCFieldAccess) {
JCFieldAccess fa = (JCFieldAccess) in;
return maker.Select(cloneType0(maker, fa.selected), fa.name);
}
if (in instanceof JCArrayTypeTree) {
JCArrayTypeTree att = (JCArrayTypeTree) in;
return maker.TypeArray(cloneType0(maker, att.elemtype));
}
if (in instanceof JCTypeApply) {
JCTypeApply ta = (JCTypeApply) in;
ListBuffer<JCExpression> lb = new ListBuffer<JCExpression>();
for (JCExpression typeArg : ta.arguments) {
lb.append(cloneType0(maker, typeArg));
}
return maker.TypeApply(cloneType0(maker, ta.clazz), lb.toList());
}
if (in instanceof JCWildcard) {
JCWildcard w = (JCWildcard) in;
JCExpression newInner = cloneType0(maker, w.inner);
TypeBoundKind newKind;
switch (w.getKind()) {
case SUPER_WILDCARD:
newKind = maker.TypeBoundKind(BoundKind.SUPER);
break;
case EXTENDS_WILDCARD:
newKind = maker.TypeBoundKind(BoundKind.EXTENDS);
break;
default:
case UNBOUNDED_WILDCARD:
newKind = maker.TypeBoundKind(BoundKind.UNBOUND);
break;
}
return maker.Wildcard(newKind, newInner);
}
// This is somewhat unsafe, but it's better than outright throwing an exception here. Returning null will just cause an exception down the pipeline.
return (JCExpression) in;
}
示例12: AJCPrimitiveTypeTree
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; //导入依赖的package包/类
public AJCPrimitiveTypeTree(JCPrimitiveTypeTree ltree) {
super(ltree.typetag);
}
示例13: visitTypeIdent
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; //导入依赖的package包/类
@Override public void visitTypeIdent(JCPrimitiveTypeTree tree) {
printNode(tree);
property("typetag", literalName(tree.typetag));
indent--;
}
示例14: visitPrimitiveType
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; //导入依赖的package包/类
@Override
public UPrimitiveTypeTree visitPrimitiveType(PrimitiveTypeTree tree, Void v) {
return UPrimitiveTypeTree.create(((JCPrimitiveTypeTree) tree).typetag);
}
示例15: basicType
import com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree; //导入依赖的package包/类
/** BasicType = BYTE | SHORT | CHAR | INT | LONG | FLOAT | DOUBLE | BOOLEAN
*/
JCPrimitiveTypeTree basicType() {
JCPrimitiveTypeTree t = to(F.at(S.pos()).TypeIdent(typetag(S.token())));
S.nextToken();
return t;
}