Java Code Examples for javax.lang.model.type.TypeKind#LONG
The following examples show how to use
javax.lang.model.type.TypeKind#LONG .
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: 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 2
Source File: AddWsOperationHelper.java From netbeans with Apache License 2.0 | 6 votes |
private String getMethodBody(Tree returnType) { String body = null; if (Kind.PRIMITIVE_TYPE == returnType.getKind()) { TypeKind type = ((PrimitiveTypeTree)returnType).getPrimitiveTypeKind(); if (TypeKind.VOID == type) body = ""; //NOI18N else if (TypeKind.BOOLEAN == type) body = "return false;"; // NOI18N else if (TypeKind.INT == type) body = "return 0;"; // NOI18N else if (TypeKind.LONG == type) body = "return 0;"; // NOI18N else if (TypeKind.FLOAT == type) body = "return 0.0;"; // NOI18N else if (TypeKind.DOUBLE == type) body = "return 0.0;"; // NOI18N else if (TypeKind.BYTE == type) body = "return 0;"; // NOI18N else if (TypeKind.SHORT == type) body = "return 0;"; // NOI18N else if (TypeKind.CHAR == type) body = "return ' ';"; // NOI18N else body = "return null"; //NOI18N } else body = "return null"; //NOI18N return "{\n\t\t"+NbBundle.getMessage(AddWsOperationHelper.class, "TXT_TodoComment")+"\n"+body+"\n}"; }
Example 3
Source File: RetroFacebookProcessor.java From RetroFacebook with Apache License 2.0 | 6 votes |
private String getSerialVersionUID(TypeElement type) { Types typeUtils = processingEnv.getTypeUtils(); TypeMirror serializable = getTypeMirror(Serializable.class); if (typeUtils.isAssignable(type.asType(), serializable)) { List<VariableElement> fields = ElementFilter.fieldsIn(type.getEnclosedElements()); for (VariableElement field : fields) { if (field.getSimpleName().toString().equals("serialVersionUID")) { Object value = field.getConstantValue(); if (field.getModifiers().containsAll(Arrays.asList(Modifier.STATIC, Modifier.FINAL)) && field.asType().getKind() == TypeKind.LONG && value != null) { return value + "L"; } else { errorReporter.reportError( "serialVersionUID must be a static final long compile-time constant", field); break; } } } } return ""; }
Example 4
Source File: AutoValueOrOneOfProcessor.java From auto with Apache License 2.0 | 6 votes |
/** * Returns a string like {@code "1234L"} if {@code type instanceof Serializable} and defines * {@code serialVersionUID = 1234L}; otherwise {@code ""}. */ final String getSerialVersionUID(TypeElement type) { TypeMirror serializable = elementUtils().getTypeElement(Serializable.class.getName()).asType(); if (typeUtils().isAssignable(type.asType(), serializable)) { List<VariableElement> fields = ElementFilter.fieldsIn(type.getEnclosedElements()); for (VariableElement field : fields) { if (field.getSimpleName().contentEquals("serialVersionUID")) { Object value = field.getConstantValue(); if (field.getModifiers().containsAll(Arrays.asList(Modifier.STATIC, Modifier.FINAL)) && field.asType().getKind() == TypeKind.LONG && value != null) { return value + "L"; } else { errorReporter.reportError( field, "serialVersionUID must be a static final long compile-time constant"); break; } } } } return ""; }
Example 5
Source File: APHotSpotSignature.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Returns the kind from the character describing a primitive or void. * * @param ch the character * @return the kind */ public static TypeKind fromPrimitiveOrVoidTypeChar(char ch) { switch (ch) { case 'Z': return TypeKind.BOOLEAN; case 'C': return TypeKind.CHAR; case 'F': return TypeKind.FLOAT; case 'D': return TypeKind.DOUBLE; case 'B': return TypeKind.BYTE; case 'S': return TypeKind.SHORT; case 'I': return TypeKind.INT; case 'J': return TypeKind.LONG; case 'V': return TypeKind.VOID; } throw new IllegalArgumentException("unknown primitive or void type character: " + ch); }
Example 6
Source File: TypeTag.java From hottub 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: 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 8
Source File: OperatorRewriter.java From j2objc with Apache License 2.0 | 6 votes |
/** * Some operator functions are given a suffix indicating the promotion type of * the operands according to JLS 5.6.2. */ private static String getPromotionSuffix(Assignment node) { if (!needsPromotionSuffix(node.getOperator())) { return ""; } TypeKind lhsKind = node.getLeftHandSide().getTypeMirror().getKind(); TypeKind rhsKind = node.getRightHandSide().getTypeMirror().getKind(); if (lhsKind == TypeKind.DOUBLE || rhsKind == TypeKind.DOUBLE) { return "D"; } if (lhsKind == TypeKind.FLOAT || rhsKind == TypeKind.FLOAT) { return "F"; } if (lhsKind == TypeKind.LONG || rhsKind == TypeKind.LONG) { return "J"; } return "I"; }
Example 9
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 10
Source File: LLNI.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private int doTwoWordFields(FieldDefsRes res, TypeElement clazz, int offset, String cname, boolean padWord) { boolean first = true; List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements()); for (VariableElement field: fields) { TypeKind tk = field.asType().getKind(); boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE); if (twoWords && doField(res, field, cname, first && padWord)) { offset += 8; first = false; } } return offset; }
Example 11
Source File: ValueType.java From immutables with Apache License 2.0 | 5 votes |
private Long findSerialVersionUID() { for (VariableElement field : ElementFilter.fieldsIn(element.getEnclosedElements())) { if (field.getSimpleName().contentEquals(SERIAL_VERSION_FIELD_NAME) && field.asType().getKind() == TypeKind.LONG) { return (Long) field.getConstantValue(); } } return null; }
Example 12
Source File: TypeUtils.java From alchemy with Apache License 2.0 | 5 votes |
boolean isLongFamily(TypeMirror type) { try { TypeKind typeKind = type.getKind(); if (TypeKind.DECLARED == typeKind) { typeKind = unbox(type).getKind(); } return TypeKind.LONG == typeKind || TypeKind.INT == typeKind || TypeKind.SHORT == typeKind; } catch (IllegalArgumentException ignored) { return false; } }
Example 13
Source File: EasyMVPProcessor.java From EasyMVP with Apache License 2.0 | 5 votes |
private void parsePresenterId(Element element, Map<TypeElement, DelegateClassGenerator> delegateClassMap) { if (!SuperficialValidation.validateElement(element)) { error("Superficial validation error for %s", element.getSimpleName()); return; } if (Validator.isPrivate(element)) { error("%s can't be private", element.getSimpleName()); return; } if (Validator.isMethod(element)) { ExecutableType emeth = (ExecutableType) element.asType(); if (!emeth.getReturnType().getKind().equals(TypeKind.LONG) && !emeth.getReturnType().getKind().equals(TypeKind.INT)) { error("%s must have return type int or long", element); } } else { TypeKind kind = element.asType().getKind(); if (kind != TypeKind.INT && kind != TypeKind.LONG) { error("%s must be int or long", element.getSimpleName()); return; } } String presenterId = element.toString(); DelegateClassGenerator delegateClassGenerator = getDelegate((TypeElement) element.getEnclosingElement(), delegateClassMap); delegateClassGenerator.setPresenterId(presenterId); }
Example 14
Source File: LLNI.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private int doTwoWordFields(FieldDefsRes res, TypeElement clazz, int offset, String cname, boolean padWord) { boolean first = true; List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements()); for (VariableElement field: fields) { TypeKind tk = field.asType().getKind(); boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE); if (twoWords && doField(res, field, cname, first && padWord)) { offset += 8; first = false; } } return offset; }
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 = makeQualIdent(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: 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); if ( typeMirror == null || typeMirror.getKind() == TypeKind.ERROR ){ typeTree = getTreeMaker().QualIdent( typeName ); } else { typeTree = make.Type(typeMirror); } } return typeTree; }
Example 17
Source File: AddWsOperationHelper.java From netbeans with Apache License 2.0 | 5 votes |
private String getMethodBody(Tree returnType) { String body = null; if (Kind.PRIMITIVE_TYPE == returnType.getKind()) { TypeKind type = ((PrimitiveTypeTree)returnType).getPrimitiveTypeKind(); if (TypeKind.VOID == type) { body = ""; //NOI18N } else if (TypeKind.BOOLEAN == type) { body = "return false;"; // NOI18N } else if (TypeKind.INT == type) { body = "return 0;"; // NOI18N } else if (TypeKind.LONG == type) { body = "return 0;"; // NOI18N } else if (TypeKind.FLOAT == type) { body = "return 0.0;"; // NOI18N } else if (TypeKind.DOUBLE == type) { body = "return 0.0;"; // NOI18N } else if (TypeKind.BYTE == type) { body = "return 0;"; // NOI18N } else if (TypeKind.SHORT == type) { body = "return 0;"; // NOI18N } else if (TypeKind.CHAR == type) { body = "return ' ';"; // NOI18N } else { body = "return null"; //NOI18N } } else body = "return null"; //NOI18N return "{\n\t\t"+NbBundle.getMessage(AddWsOperationHelper.class, "TXT_TodoComment")+"\n"+body+"\n}"; }
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: LLNI.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
FieldDefsRes fieldDefs(TypeElement clazz, String cname, boolean bottomMost){ FieldDefsRes res; int offset; boolean didTwoWordFields = false; TypeElement superclazz = (TypeElement) types.asElement(clazz.getSuperclass()); if (superclazz != null) { String supername = superclazz.getQualifiedName().toString(); res = new FieldDefsRes(clazz, fieldDefs(superclazz, cname, false), bottomMost); offset = res.parent.byteSize; } else { res = new FieldDefsRes(clazz, null, bottomMost); offset = 0; } List<VariableElement> fields = ElementFilter.fieldsIn(clazz.getEnclosedElements()); for (VariableElement field: fields) { if (doubleAlign && !didTwoWordFields && (offset % 8) == 0) { offset = doTwoWordFields(res, clazz, offset, cname, false); didTwoWordFields = true; } TypeKind tk = field.asType().getKind(); boolean twoWords = (tk == TypeKind.LONG || tk == TypeKind.DOUBLE); if (!doubleAlign || !twoWords) { if (doField(res, field, cname, false)) offset += 4; } } if (doubleAlign && !didTwoWordFields) { if ((offset % 8) != 0) offset += 4; offset = doTwoWordFields(res, clazz, offset, cname, true); } res.byteSize = offset; return res; }
Example 20
Source File: ValueAttribute.java From immutables with Apache License 2.0 | 4 votes |
public boolean isLong() { return returnType.getKind() == TypeKind.LONG; }