Java Code Examples for javax.lang.model.type.TypeKind#INT
The following examples show how to use
javax.lang.model.type.TypeKind#INT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Type.java From javaide with GNU General Public License v3.0 | 6 votes |
public TypeKind getKind() { switch (tag) { case BYTE: return TypeKind.BYTE; case CHAR: return TypeKind.CHAR; case SHORT: return TypeKind.SHORT; case INT: return TypeKind.INT; case LONG: return TypeKind.LONG; case FLOAT: return TypeKind.FLOAT; case DOUBLE: return TypeKind.DOUBLE; case BOOLEAN: return TypeKind.BOOLEAN; case VOID: return TypeKind.VOID; case BOT: return TypeKind.NULL; case NONE: return TypeKind.NONE; default: return TypeKind.OTHER; } }
Example 2
Source File: TypeTag.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public TypeKind getPrimitiveTypeKind() { switch (this) { case BOOLEAN: return TypeKind.BOOLEAN; case BYTE: return TypeKind.BYTE; case SHORT: return TypeKind.SHORT; case INT: return TypeKind.INT; case LONG: return TypeKind.LONG; case CHAR: return TypeKind.CHAR; case FLOAT: return TypeKind.FLOAT; case DOUBLE: return TypeKind.DOUBLE; case VOID: return TypeKind.VOID; default: throw new AssertionError("unknown primitive type " + this); } }
Example 3
Source File: MalformedFormatString.java From netbeans with Apache License 2.0 | 6 votes |
/** * Unbox a wrapper type into a TypeKind. Some additional types are mapped to TypeKinds which cannot really appear in * expressions (at least I hope) * * @param tm * @return */ private static TypeKind unboxBoxed(TypeMirror tm) { TypeElement te = (TypeElement)((DeclaredType)tm).asElement(); String qn = te.getQualifiedName().toString(); if (!qn.startsWith("java.lang.")) { // NO18N if (qn.equals("java.math.BigInteger")) { // NOI18N return TypeKind.WILDCARD; } return null; } switch (qn.substring(10)) { case "Short": return TypeKind.SHORT; // NOI18N case "Long": return TypeKind.LONG; // NOI18N case "Byte": return TypeKind.BYTE; // NOI18N case "Integer": return TypeKind.INT; // NOI18N case "Double": return TypeKind.DOUBLE; // NOI18N case "Float": return TypeKind.FLOAT; // NOI18N case "Character": return TypeKind.CHAR; // NOI18N case "String": return TypeKind.OTHER; // NOI18N case "Object": return TypeKind.PACKAGE; // NOI18N } return null; }
Example 4
Source File: TypeTag.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public TypeKind getPrimitiveTypeKind() { switch (this) { case BOOLEAN: return TypeKind.BOOLEAN; case BYTE: return TypeKind.BYTE; case SHORT: return TypeKind.SHORT; case INT: return TypeKind.INT; case LONG: return TypeKind.LONG; case CHAR: return TypeKind.CHAR; case FLOAT: return TypeKind.FLOAT; case DOUBLE: return TypeKind.DOUBLE; case VOID: return TypeKind.VOID; default: throw new AssertionError("unknown primitive type " + this); } }
Example 5
Source File: PrimitiveTypeImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static TypeKind getKind(BaseTypeBinding binding) { switch (binding.id) { case TypeIds.T_boolean: return TypeKind.BOOLEAN; case TypeIds.T_byte: return TypeKind.BYTE; case TypeIds.T_char: return TypeKind.CHAR; case TypeIds.T_double: return TypeKind.DOUBLE; case TypeIds.T_float: return TypeKind.FLOAT; case TypeIds.T_int: return TypeKind.INT; case TypeIds.T_long: return TypeKind.LONG; case TypeIds.T_short: return TypeKind.SHORT; default: throw new IllegalArgumentException("BaseTypeBinding of unexpected id " + binding.id); //$NON-NLS-1$ } }
Example 6
Source File: TypeTag.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public TypeKind getPrimitiveTypeKind() { switch (this) { case BOOLEAN: return TypeKind.BOOLEAN; case BYTE: return TypeKind.BYTE; case SHORT: return TypeKind.SHORT; case INT: return TypeKind.INT; case LONG: return TypeKind.LONG; case CHAR: return TypeKind.CHAR; case FLOAT: return TypeKind.FLOAT; case DOUBLE: return TypeKind.DOUBLE; case VOID: return TypeKind.VOID; default: throw new AssertionError("unknown primitive type " + this); } }
Example 7
Source File: Type.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
public TypeKind getKind() { switch (tag) { case BYTE: return TypeKind.BYTE; case CHAR: return TypeKind.CHAR; case SHORT: return TypeKind.SHORT; case INT: return TypeKind.INT; case LONG: return TypeKind.LONG; case FLOAT: return TypeKind.FLOAT; case DOUBLE: return TypeKind.DOUBLE; case BOOLEAN: return TypeKind.BOOLEAN; case VOID: return TypeKind.VOID; case BOT: return TypeKind.NULL; case NONE: return TypeKind.NONE; default: return TypeKind.OTHER; } }
Example 8
Source File: JCTree.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
public TypeKind getPrimitiveTypeKind() { switch (typetag) { case TypeTags.BOOLEAN: return TypeKind.BOOLEAN; case TypeTags.BYTE: return TypeKind.BYTE; case TypeTags.SHORT: return TypeKind.SHORT; case TypeTags.INT: return TypeKind.INT; case TypeTags.LONG: return TypeKind.LONG; case TypeTags.CHAR: return TypeKind.CHAR; case TypeTags.FLOAT: return TypeKind.FLOAT; case TypeTags.DOUBLE: return TypeKind.DOUBLE; case TypeTags.VOID: return TypeKind.VOID; default: throw new AssertionError("unknown primitive type " + this); } }
Example 9
Source File: ButterKnifeProcessor.java From butterknife with Apache License 2.0 | 5 votes |
private void parseResourceDimen(Element element, Map<TypeElement, BindingSet.Builder> builderMap, Set<TypeElement> erasedTargetNames) { boolean hasError = false; TypeElement enclosingElement = (TypeElement) element.getEnclosingElement(); // Verify that the target type is int or ColorStateList. boolean isInt = false; TypeMirror elementType = element.asType(); if (elementType.getKind() == TypeKind.INT) { isInt = true; } else if (elementType.getKind() != TypeKind.FLOAT) { error(element, "@%s field type must be 'int' or 'float'. (%s.%s)", BindDimen.class.getSimpleName(), enclosingElement.getQualifiedName(), element.getSimpleName()); hasError = true; } // Verify common generated code restrictions. hasError |= isInaccessibleViaGeneratedCode(BindDimen.class, "fields", element); hasError |= isBindingInWrongPackage(BindDimen.class, element); if (hasError) { return; } // Assemble information on the field. String name = element.getSimpleName().toString(); int id = element.getAnnotation(BindDimen.class).value(); Id resourceId = elementToId(element, BindDimen.class, id); BindingSet.Builder builder = getOrCreateBindingBuilder(builderMap, enclosingElement); builder.addResource(new FieldResourceBinding(resourceId, name, isInt ? FieldResourceBinding.Type.DIMEN_AS_INT : FieldResourceBinding.Type.DIMEN_AS_FLOAT)); erasedTargetNames.add(enclosingElement); }
Example 10
Source File: ViewTypeSearcher.java From AnnotatedAdapter with Apache License 2.0 | 5 votes |
private boolean isValidField(Element element) { if (element.getKind() == ElementKind.FIELD) { // Check if its public if (!element.getModifiers().contains(Modifier.PUBLIC)) { logger.error(element, "%s in %s is not public. Only final integer views with public " + "visibility can be annotated with @%s.", element.getSimpleName(), element.getEnclosingElement().getSimpleName(), ViewType.class.getSimpleName()); return false; } // Check if its final if (!element.getModifiers().contains(Modifier.FINAL)) { logger.error(element, "%s in %s is not final. Only final integer views can be annotated with @%s.", element.getSimpleName(), element.getEnclosingElement().getSimpleName(), ViewType.class.getSimpleName()); return false; } // Check if its an int if (element.asType().getKind() != TypeKind.INT) { logger.error(element, "%s in %s is not a integer. Only final public integer views can be annotated with @%s.", element.getSimpleName(), element.getEnclosingElement().getSimpleName(), ViewType.class.getSimpleName()); return false; } // Everything is ok, its a valid integer return true; } else { logger.error(element, "@%s can only be applied on integer views. %s is not a field", ViewType.class.getSimpleName(), element.getSimpleName()); return false; } }
Example 11
Source File: IntroduceLocalExtensionTransformer.java From netbeans with Apache License 2.0 | 5 votes |
private void addMembers(TypeElement source, GeneratorUtilities genUtils, List<Tree> members) throws IllegalStateException { for (ExecutableElement method : ElementFilter.methodsIn(workingCopy.getElements().getAllMembers(source))) { if (!method.getModifiers().contains(Modifier.NATIVE) && method.getModifiers().contains(Modifier.PUBLIC) && !method.getEnclosingElement().equals(workingCopy.getElements().getTypeElement("java.lang.Object"))) { //NOI18N if (!((method.getReturnType().getKind() == TypeKind.BOOLEAN && method.getSimpleName().contentEquals("equals")) || //NOI18N (method.getReturnType().getKind() == TypeKind.INT && method.getSimpleName().contentEquals("hashCode")))) { //NOI18N addMember(source, method, genUtils, members); } } } }
Example 12
Source File: Unbalanced.java From netbeans with Apache License 2.0 | 5 votes |
@TriggerPattern(value="$mods$ $type $name = $init$;") public static ErrorDescription after(HintContext ctx) { if (testElement(ctx) == null) return null; TreePath init = ctx.getVariables().get("$init$"); if (init != null) { if (init.getLeaf().getKind() != Kind.NEW_CLASS) return null; NewClassTree nct = (NewClassTree) init.getLeaf(); if (nct.getClassBody() != null || nct.getArguments().size() > 1) return null; if (nct.getArguments().size() == 1) { TypeMirror tm = ctx.getInfo().getTrees().getTypeMirror(new TreePath(init, nct.getArguments().get(0))); if (tm == null || tm.getKind() != TypeKind.INT) return null; } } if ( ctx.getPath().getParentPath().getLeaf().getKind() == Kind.ENHANCED_FOR_LOOP && ((EnhancedForLoopTree) ctx.getPath().getParentPath().getLeaf()).getVariable() == ctx.getPath().getLeaf()) { return null; } return produceWarning(ctx, "ERR_UnbalancedCollection"); }
Example 13
Source File: MethodModelSupport.java From netbeans with Apache License 2.0 | 5 votes |
private static Tree getTypeTree(WorkingCopy workingCopy, String typeName) { TreeMaker make = workingCopy.getTreeMaker(); TypeKind primitiveTypeKind = null; if ("boolean".equals(typeName)) { // NOI18N primitiveTypeKind = TypeKind.BOOLEAN; } else if ("byte".equals(typeName)) { // NOI18N primitiveTypeKind = TypeKind.BYTE; } else if ("short".equals(typeName)) { // NOI18N primitiveTypeKind = TypeKind.SHORT; } else if ("int".equals(typeName)) { // NOI18N primitiveTypeKind = TypeKind.INT; } else if ("long".equals(typeName)) { // NOI18N primitiveTypeKind = TypeKind.LONG; } else if ("char".equals(typeName)) { // NOI18N primitiveTypeKind = TypeKind.CHAR; } else if ("float".equals(typeName)) { // NOI18N primitiveTypeKind = TypeKind.FLOAT; } else if ("double".equals(typeName)) { // NOI18N primitiveTypeKind = TypeKind.DOUBLE; } else if ("void".equals(typeName)) { // NOI18N primitiveTypeKind = TypeKind.VOID; } if (primitiveTypeKind != null) { return make.PrimitiveType(primitiveTypeKind); } else { return createQualIdent(workingCopy, typeName); } }
Example 14
Source File: ButterKnifeProcessor.java From butterknife with Apache License 2.0 | 5 votes |
private void parseResourceInt(Element element, Map<TypeElement, BindingSet.Builder> builderMap, Set<TypeElement> erasedTargetNames) { boolean hasError = false; TypeElement enclosingElement = (TypeElement) element.getEnclosingElement(); // Verify that the target type is int. if (element.asType().getKind() != TypeKind.INT) { error(element, "@%s field type must be 'int'. (%s.%s)", BindInt.class.getSimpleName(), enclosingElement.getQualifiedName(), element.getSimpleName()); hasError = true; } // Verify common generated code restrictions. hasError |= isInaccessibleViaGeneratedCode(BindInt.class, "fields", element); hasError |= isBindingInWrongPackage(BindInt.class, element); if (hasError) { return; } // Assemble information on the field. String name = element.getSimpleName().toString(); int id = element.getAnnotation(BindInt.class).value(); Id resourceId = elementToId(element, BindInt.class, id); BindingSet.Builder builder = getOrCreateBindingBuilder(builderMap, enclosingElement); builder.addResource( new FieldResourceBinding(resourceId, name, FieldResourceBinding.Type.INT)); erasedTargetNames.add(enclosingElement); }
Example 15
Source File: GenerationUtils.java From netbeans with Apache License 2.0 | 5 votes |
public Tree createType(String typeName, TypeElement scope) { TreeMaker make = getTreeMaker(); TypeKind primitiveTypeKind = null; if ("boolean".equals(typeName)) { // NOI18N primitiveTypeKind = TypeKind.BOOLEAN; } else if ("byte".equals(typeName)) { // NOI18N primitiveTypeKind = TypeKind.BYTE; } else if ("short".equals(typeName)) { // NOI18N primitiveTypeKind = TypeKind.SHORT; } else if ("int".equals(typeName)) { // NOI18N primitiveTypeKind = TypeKind.INT; } else if ("long".equals(typeName)) { // NOI18N primitiveTypeKind = TypeKind.LONG; } else if ("char".equals(typeName)) { // NOI18N primitiveTypeKind = TypeKind.CHAR; } else if ("float".equals(typeName)) { // NOI18N primitiveTypeKind = TypeKind.FLOAT; } else if ("double".equals(typeName)) { // NOI18N primitiveTypeKind = TypeKind.DOUBLE; } else if ("void".equals(typeName)) { // NOI18N primitiveTypeKind = TypeKind.VOID; } if (primitiveTypeKind != null) { return getTreeMaker().PrimitiveType(primitiveTypeKind); } Tree typeTree = tryCreateQualIdent(typeName); if (typeTree == null) { // XXX does not handle imports; temporary until issue 102149 is fixed TypeMirror typeMirror = copy.getTreeUtilities().parseType(typeName, scope); typeTree = make.Type(typeMirror); } return typeTree; }
Example 16
Source File: Marshallers.java From bazel with Apache License 2.0 | 4 votes |
@Override public boolean matches(PrimitiveType type) { return type.getKind() == TypeKind.INT; }
Example 17
Source File: CriteriaModel.java From immutables with Apache License 2.0 | 4 votes |
public boolean isInteger() { return type.getKind() == TypeKind.INT || isSubtypeOf(Integer.class); }
Example 18
Source File: TypeUtils.java From ig-json-parser with MIT License | 4 votes |
public ParseType getParseType( TypeMirror typeMirror, @Nullable Class<? extends Annotation> typeAnnotationClass) { if (typeMirror == null) { return ParseType.UNSUPPORTED; } else if (JAVA_LANG_STRING.equals(typeMirror.toString())) { return ParseType.STRING; } else if (typeMirror.getKind() == TypeKind.BOOLEAN) { return ParseType.BOOLEAN; } else if (JAVA_LANG_BOOLEAN.equals(typeMirror.toString())) { return ParseType.BOOLEAN_OBJECT; } else if (typeMirror.getKind() == TypeKind.INT) { return ParseType.INTEGER; } else if (JAVA_LANG_INTEGER.equals(typeMirror.toString())) { return ParseType.INTEGER_OBJECT; } else if (typeMirror.getKind() == TypeKind.LONG) { return ParseType.LONG; } else if (JAVA_LANG_LONG.equals(typeMirror.toString())) { return ParseType.LONG_OBJECT; } else if (typeMirror.getKind() == TypeKind.FLOAT) { return ParseType.FLOAT; } else if (JAVA_LANG_FLOAT.equals(typeMirror.toString())) { return ParseType.FLOAT_OBJECT; } else if (typeMirror.getKind() == TypeKind.DOUBLE) { return ParseType.DOUBLE; } else if (JAVA_LANG_DOUBLE.equals(typeMirror.toString())) { return ParseType.DOUBLE_OBJECT; } else if (typeMirror instanceof DeclaredType) { DeclaredType type = (DeclaredType) typeMirror; Element element = type.asElement(); Annotation annotation = typeAnnotationClass != null ? element.getAnnotation(typeAnnotationClass) : null; if (annotation != null && EnumSet.of(CLASS, INTERFACE).contains(element.getKind())) { return ParseType.PARSABLE_OBJECT; } // is it an enum? if (element instanceof TypeElement) { TypeElement typeElement = (TypeElement) element; TypeMirror superclass = typeElement.getSuperclass(); if (superclass instanceof DeclaredType) { DeclaredType superclassDeclaredType = (DeclaredType) superclass; if (JAVA_LANG_ENUM.equals(getCanonicalTypeName(superclassDeclaredType))) { return ParseType.ENUM_OBJECT; } } } } return ParseType.UNSUPPORTED; }
Example 19
Source File: FromEntityBase.java From netbeans with Apache License 2.0 | 4 votes |
private static String getConversionFromString(TypeMirror idType, int index, String keyType) { String param = index == -1 ? "value" : "values["+index+"]"; if (TypeKind.BOOLEAN == idType.getKind()) { return "Boolean.parseBoolean("+param+")"; } else if (TypeKind.BYTE == idType.getKind()) { return "Byte.parseByte("+param+")"; } else if (TypeKind.CHAR == idType.getKind()) { return param+".charAt(0)"; } else if (TypeKind.DOUBLE == idType.getKind()) { return "Double.parseDouble("+param+")"; } else if (TypeKind.FLOAT == idType.getKind()) { return "Float.parseFloat("+param+")"; } else if (TypeKind.INT == idType.getKind()) { return "Integer.parseInt("+param+")"; } else if (TypeKind.LONG == idType.getKind()) { return "Long.parseLong("+param+")"; } else if (TypeKind.SHORT == idType.getKind()) { return "Short.parseShort("+param+")"; } else if (TypeKind.DECLARED == idType.getKind()) { if ("Boolean".equals(idType.toString()) || "java.lang.Boolean".equals(idType.toString())) { return "Boolean.valueOf("+param+")"; } else if ("Byte".equals(idType.toString()) || "java.lang.Byte".equals(idType.toString())) { return "Byte.valueOf("+param+")"; } else if ("Character".equals(idType.toString()) || "java.lang.Character".equals(idType.toString())) { return "new Character("+param+".charAt(0))"; } else if ("Double".equals(idType.toString()) || "java.lang.Double".equals(idType.toString())) { return "Double.valueOf("+param+")"; } else if ("Float".equals(idType.toString()) || "java.lang.Float".equals(idType.toString())) { return "Float.valueOf("+param+")"; } else if ("Integer".equals(idType.toString()) || "java.lang.Integer".equals(idType.toString())) { return "Integer.valueOf("+param+")"; } else if ("Long".equals(idType.toString()) || "java.lang.Long".equals(idType.toString())) { return "Long.valueOf("+param+")"; } else if ("Short".equals(idType.toString()) || "java.lang.Short".equals(idType.toString())) { return "Short.valueOf("+param+")"; } else if ("BigDecimal".equals(idType.toString()) || "java.math.BigDecimal".equals(idType.toString())) { return "new java.math.BigDecimal("+param+")"; } else if ("Date".equals(idType.toString()) || "java.util.Date".equals(idType.toString())) { return "java.sql.Date.valueOf("+param+")"; } } return param; }
Example 20
Source File: ValueAttribute.java From immutables with Apache License 2.0 | 4 votes |
public boolean isInt() { return returnType.getKind() == TypeKind.INT; }