本文整理汇总了Java中javax.lang.model.type.TypeKind.isPrimitive方法的典型用法代码示例。如果您正苦于以下问题:Java TypeKind.isPrimitive方法的具体用法?Java TypeKind.isPrimitive怎么用?Java TypeKind.isPrimitive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.lang.model.type.TypeKind
的用法示例。
在下文中一共展示了TypeKind.isPrimitive方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTypeClass
import javax.lang.model.type.TypeKind; //导入方法依赖的package包/类
private static String getTypeClass(TypeMirror type, CompilationInfo javac) {
TypeKind kind = type.getKind();
if (kind.isPrimitive()) {
return type.toString();
} else if (kind == TypeKind.ARRAY) {
return resolveArrayClass((ArrayType) type, javac);
} else if (kind == TypeKind.DECLARED) {
return ((TypeElement) ((DeclaredType) type).asElement()).getQualifiedName().toString();
} else if (kind == TypeKind.ERROR) {
return type.toString();
} else if (kind == TypeKind.TYPEVAR) {
return javac.getTypes().erasure(type).toString();
} else {
throw new IllegalStateException("Unknown type: " + type + ", " + type.getKind()); // NOI18N
}
}
示例2: checkPublicType
import javax.lang.model.type.TypeKind; //导入方法依赖的package包/类
private void checkPublicType(ModelContext ctx, TypeMirror type, ExecutableElement method, boolean acceptVoid, String msg) throws ModelException {
TypeKind kind = type.getKind();
if (kind.isPrimitive()) {
return;
}
switch (kind) {
case ARRAY:
checkPublicType(ctx, ((ArrayType) type).getComponentType(), method, false, msg);
return;
case DECLARED:
if (ctx.isPublic(type) || ctx.isProtected(type)) {
return;
}
throw new ModelException(msg + ": " + type + " is not public or protected");
case VOID:
if (acceptVoid) {
return;
}
throw new ModelException(msg + ": unsupported type " + type);
default:
throw new ModelException(msg + ": unsupported type " + type);
}
}
示例3: testIsPrimitive
import javax.lang.model.type.TypeKind; //导入方法依赖的package包/类
static int testIsPrimitive() {
int failures = 0;
// The eight primitive types
Set<TypeKind> primitives = EnumSet.of(BOOLEAN, // 1
BYTE, // 2
CHAR, // 3
DOUBLE, // 4
FLOAT, // 5
INT, // 6
LONG, // 7
SHORT); // 8
for(TypeKind tk : TypeKind.values()) {
boolean primitiveness;
if ((primitiveness=tk.isPrimitive()) != primitives.contains(tk) ) {
failures++;
System.err.println("Unexpected isPrimitive value " + primitiveness +
"for " + tk);
}
}
return failures;
}
示例4: collectBuiltins
import javax.lang.model.type.TypeKind; //导入方法依赖的package包/类
private void collectBuiltins(Map<String, TypeMirror> collected) {
for (TypeKind kind : TypeKind.values()) {
if (kind.isPrimitive()) {
TypeElement boxedClass = types.boxedClass(types.getPrimitiveType(kind));
collected.put(boxedClass.getSimpleName().toString(), boxedClass.asType());
}
}
TypeElement typeElement = elements.getTypeElement(String.class.getCanonicalName());
collected.put(typeElement.getSimpleName().toString(), typeElement.asType());
typeElement = elements.getTypeElement(Templates.Invokable.class.getCanonicalName());
collected.put(typeElement.getSimpleName().toString(), typeElement.asType());
}
示例5: isPossibleCopyMethod
import javax.lang.model.type.TypeKind; //导入方法依赖的package包/类
/**
* Applies to both builder and value candidates.
*
* @param valueAttribute the valueAttribute.
* @param possibleCopyMethod candidate to check.
*/
protected static boolean isPossibleCopyMethod(ValueAttribute valueAttribute,
Element possibleCopyMethod, boolean onValueType) {
if (possibleCopyMethod.getKind() == ElementKind.METHOD) {
ExecutableElement candidateCopyMethod = (ExecutableElement) possibleCopyMethod;
if (candidateCopyMethod.getParameters().size() == 1
&& candidateCopyMethod.getParameters().get(0).asType().equals(valueAttribute.containedTypeElement.asType())) {
return true;
// handle proto style toBuilder() copy method... lots of BuilderModels created because of this
} else if (onValueType
&& candidateCopyMethod.getParameters().size() == 0
&& !candidateCopyMethod.getModifiers().contains(Modifier.STATIC)) {
TypeKind kind = candidateCopyMethod.getReturnType().getKind();
return !kind.isPrimitive() && kind != TypeKind.ARRAY;
}
} else if (!onValueType && possibleCopyMethod.getKind() == ElementKind.CONSTRUCTOR) {
if (!valueAttribute.containingType.names().newTokenInAttributeBuilder()) {
return false;
}
ExecutableElement candidateConstructor = (ExecutableElement) possibleCopyMethod;
return candidateConstructor.getParameters().size() == 1
&& candidateConstructor.getParameters().get(0).asType().equals(valueAttribute.containedTypeElement.asType());
}
return false;
}
示例6: lookupType
import javax.lang.model.type.TypeKind; //导入方法依赖的package包/类
private static TypeMirror lookupType(ProcessingEnvironment env, String binaryName) {
if (binaryName.length() == 1) {
TypeKind kind = fromPrimitiveOrVoidTypeChar(binaryName.charAt(0));
if (kind.isPrimitive()) {
return env.getTypeUtils().getPrimitiveType(kind);
} else if (kind == TypeKind.VOID) {
return env.getTypeUtils().getNoType(kind);
}
}
String canonicalName = binaryName;
if (canonicalName.startsWith("L") && canonicalName.endsWith(";")) {
canonicalName = canonicalName.substring(1, canonicalName.length() - 1);
}
env.getMessager().printMessage(Kind.ERROR, canonicalName);
int arrayDims = 0;
while (canonicalName.startsWith("[")) {
canonicalName = canonicalName.substring(1, canonicalName.length());
arrayDims++;
}
canonicalName = canonicalName.replaceAll("/", ".");
TypeElement typeElement = env.getElementUtils().getTypeElement(canonicalName);
if (typeElement == null) {
throw new RuntimeException(String.format("Type with name %s not found.", canonicalName));
}
TypeMirror mirror = typeElement.asType();
for (int i = 0; i < arrayDims; i++) {
mirror = env.getTypeUtils().getArrayType(mirror);
}
return mirror;
}
示例7: isNumberType
import javax.lang.model.type.TypeKind; //导入方法依赖的package包/类
public boolean isNumberType() {
TypeKind kind = returnType.getKind();
return kind.isPrimitive()
&& kind != TypeKind.CHAR
&& kind != TypeKind.BOOLEAN;
}
示例8: isPrimitiveType
import javax.lang.model.type.TypeKind; //导入方法依赖的package包/类
private static boolean isPrimitiveType(TypeKind k) {
return k.isPrimitive();
}
示例9: PrimitiveTypeDesc
import javax.lang.model.type.TypeKind; //导入方法依赖的package包/类
public PrimitiveTypeDesc(TypeKind typeKind) {
super(typeKind);
if (!typeKind.isPrimitive() && typeKind != TypeKind.VOID)
throw new IllegalArgumentException("Only primitives or void accepted");
}