本文整理匯總了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");
}