Java Code Examples for javax.lang.model.type.TypeKind#BOOLEAN
The following examples show how to use
javax.lang.model.type.TypeKind#BOOLEAN .
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 TencentKona-8 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: RefactoringUtil.java From netbeans with Apache License 2.0 | 6 votes |
public static String getPropertyName(String accessor, TypeMirror returnType, boolean includeSetter) { Parameters.notEmpty("accessor", accessor); //NO18N int prefixLength = getPrefixLength(accessor, includeSetter); String withoutPrefix = accessor.substring(prefixLength); if (withoutPrefix.isEmpty()) { // method name is simply is/get/set return accessor; } char firstChar = withoutPrefix.charAt(0); if (!Character.isUpperCase(firstChar)) { return accessor; } //method property which is prefixed by 'is' but doesn't return boolean if (returnType != null && accessor.startsWith("is") && returnType.getKind() != TypeKind.BOOLEAN) { //NOI18N return accessor; } //check the second char, if its also uppercase, the property name must be preserved if(withoutPrefix.length() > 1 && Character.isUpperCase(withoutPrefix.charAt(1))) { return withoutPrefix; } return Character.toLowerCase(firstChar) + withoutPrefix.substring(1); }
Example 3
Source File: GetterFactory.java From firebase-android-sdk with Apache License 2.0 | 6 votes |
private static Optional<String> inferName(ExecutableElement element) { Encodable.Field annotation = element.getAnnotation(Encodable.Field.class); if (annotation != null && !annotation.name().isEmpty()) { return Optional.of(annotation.name()); } String methodName = element.getSimpleName().toString(); ExecutableType method = (ExecutableType) element.asType(); if (methodName.startsWith("is") && methodName.length() != 2 && method.getReturnType().getKind() == TypeKind.BOOLEAN) { return Optional.of(Character.toLowerCase(methodName.charAt(2)) + methodName.substring(3)); } if (methodName.startsWith("get") && methodName.length() != 3 && method.getReturnType().getKind() != TypeKind.VOID) { return Optional.of(Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4)); } return Optional.empty(); }
Example 4
Source File: EnumValueCompleter.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Completer createCompleter(CompletionContext ctx) { FxProperty p = ctx.getEnclosingProperty(); if (p == null || p.getType() == null) { return null; } TypeMirror m = p.getType().resolve(ctx.getCompilationInfo()); if (m.getKind() == TypeKind.BOOLEAN) { return new EnumValueCompleter(ctx); } if (m.getKind() != TypeKind.DECLARED) { return null; } DeclaredType t = (DeclaredType)m; TypeElement tel = (TypeElement)t.asElement(); if (tel.getQualifiedName().contentEquals("java.lang.Boolean")) { return new EnumValueCompleter(ctx); } if (tel.getKind() == ElementKind.ENUM) { return new EnumValueCompleter(ctx, tel); } else { return null; } }
Example 5
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 6
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 7
Source File: JCTree.java From javaide with GNU General Public License v3.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: TypeTag.java From openjdk-8-source 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 9
Source File: ClassChecker.java From java-master with Apache License 2.0 | 5 votes |
@Override public Set<? extends Element> visitExecutable(ExecutableElement e, Element element) { if (e.getReturnType().getKind() == TypeKind.BOOLEAN) { String isPrefix = "is"; if (!e.getSimpleName().toString().startsWith(isPrefix)) { logger.warning(e.getEnclosingElement() + "返回boolean值的方法" + e.getSimpleName() + "应以is开头"); } } return super.visitExecutable(e, element); }
Example 10
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 11
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 12
Source File: ButterKnifeProcessor.java From butterknife with Apache License 2.0 | 5 votes |
private void parseResourceBool(Element element, Map<TypeElement, BindingSet.Builder> builderMap, Set<TypeElement> erasedTargetNames) { boolean hasError = false; TypeElement enclosingElement = (TypeElement) element.getEnclosingElement(); // Verify that the target type is bool. if (element.asType().getKind() != TypeKind.BOOLEAN) { error(element, "@%s field type must be 'boolean'. (%s.%s)", BindBool.class.getSimpleName(), enclosingElement.getQualifiedName(), element.getSimpleName()); hasError = true; } // Verify common generated code restrictions. hasError |= isInaccessibleViaGeneratedCode(BindBool.class, "fields", element); hasError |= isBindingInWrongPackage(BindBool.class, element); if (hasError) { return; } // Assemble information on the field. String name = element.getSimpleName().toString(); int id = element.getAnnotation(BindBool.class).value(); Id resourceId = elementToId(element, BindBool.class, id); BindingSet.Builder builder = getOrCreateBindingBuilder(builderMap, enclosingElement); builder.addResource( new FieldResourceBinding(resourceId, name, FieldResourceBinding.Type.BOOL)); erasedTargetNames.add(enclosingElement); }
Example 13
Source File: SerializerBuilder.java From domino-jackson with Apache License 2.0 | 5 votes |
AbstractJsonMapperGenerator.AccessorInfo getterInfo() { final String upperCaseFirstLetter = upperCaseFirstLetter(field.getSimpleName().toString()); String prefix = field.asType().getKind() == TypeKind.BOOLEAN ? "is" : "get"; Optional<AbstractJsonMapperGenerator.AccessorInfo> accessor = getAccessors(beanType) .stream() .filter(accessorInfo -> accessorInfo.getName().equals(prefix + upperCaseFirstLetter)) .findFirst(); return accessor.orElseGet(() -> new AbstractJsonMapperGenerator.AccessorInfo(field.getSimpleName().toString())); }
Example 14
Source File: InternalDomainMetaFactory.java From doma with Apache License 2.0 | 5 votes |
String inferAccessorMethod(VariableElement field) { String name = field.getSimpleName().toString(); String capitalizedName = StringUtil.capitalize(name); if (field.asType().getKind() == TypeKind.BOOLEAN) { if (name.startsWith("is") && (name.length() > 2 && Character.isUpperCase(name.charAt(2)))) { return name; } return "is" + capitalizedName; } return "get" + capitalizedName; }
Example 15
Source File: TmpPattern.java From netbeans with Apache License 2.0 | 4 votes |
/** Package private constructor. Merges two property descriptors. Where they * conflict, gives the second argument (y) priority over the first argumnet (x). * @param x The first (lower priority) PropertyPattern. * @param y The second (higher priority) PropertyPattern. */ Property( CompilationInfo javac, Property x, Property y ) { // Figure out the merged getterMethod ExecutableElement xr = x.getterMethod; ExecutableElement yr = y.getterMethod; getterMethod = xr; // Normaly give priority to y's getterMethod if ( yr != null ) { getterMethod = yr; } // However, if both x and y reference read method in the same class, // give priority to a boolean "is" method over boolean "get" method. if ( xr != null && yr != null && xr.getEnclosingElement() == yr.getEnclosingElement() && xr.getReturnType().getKind() == TypeKind.BOOLEAN && yr.getReturnType().getKind() == TypeKind.BOOLEAN && nameAsString(xr).indexOf(IS_PREFIX) == 0 && nameAsString(yr).indexOf(GET_PREFIX) == 0 ) { getterMethod = xr; } setterMethod = x.setterMethod; if ( y.setterMethod != null ) { setterMethod = y.setterMethod; } // PENDING bound and constrained /* bound = x.bound | y.bound; constrained = x.constrained | y.constrained */ try { type = findPropertyType(javac); } catch ( IntrospectionException ex ) { //System.out.println (x.getName() + ":" + y.getName()); // NOI18N //System.out.println (x.getType() + ":" + y.getType() ); // NOI18N throw new IllegalStateException("Mixing invalid PropertyPattrens", ex); // NOI18N } name = findPropertyName(); }
Example 16
Source File: ValueAttribute.java From immutables with Apache License 2.0 | 4 votes |
public boolean isBoolean() { return returnType.getKind() == TypeKind.BOOLEAN; }
Example 17
Source File: ValueAttribute.java From immutables with Apache License 2.0 | 4 votes |
public boolean isNumberType() { TypeKind kind = returnType.getKind(); return kind.isPrimitive() && kind != TypeKind.CHAR && kind != TypeKind.BOOLEAN; }
Example 18
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 19
Source File: BeanUtils.java From fastjgame with Apache License 2.0 | 4 votes |
/** * 是否是基本类型的boolean */ public static boolean isPrimitiveBoolean(TypeMirror typeMirror) { return typeMirror.getKind() == TypeKind.BOOLEAN; }
Example 20
Source File: PatternAnalyser.java From netbeans with Apache License 2.0 | 4 votes |
/** Analyses one method for property charcteristics */ Property analyseMethodForProperties( Parameters p, ExecutableElement method ) { // Skip static methods as Introspector does. if( method.getModifiers().contains(STATIC) ) { return null; } String name = nameAsString(method); VariableElement[] params = method.getParameters().toArray(new VariableElement[0]); TypeMirror returnType = method.getReturnType(); Property pp = null; try { if ( params.length == 0 ) { if (name.startsWith( GET_PREFIX )) { // SimpleGetter pp = new Property( p.ci, method, null ); } else if ( returnType.getKind() == TypeKind.BOOLEAN && name.startsWith( IS_PREFIX )) { // Boolean getter pp = new Property( p.ci, method, null ); } } else if ( params.length == 1 ) { if ( params[0].asType().getKind() == TypeKind.INT) { if(name.startsWith( GET_PREFIX )) { pp = new IdxProperty( p.ci, null, null, method, null ); } else if ( returnType.getKind() == TypeKind.BOOLEAN && name.startsWith( IS_PREFIX )) { pp = new IdxProperty( p.ci, null, null, method, null ); } else if (returnType.getKind() == TypeKind.VOID && name.startsWith(SET_PREFIX)) { pp = new Property(p.ci, null, method); // PENDING vetoable => constrained } } else if ( returnType.getKind() == TypeKind.VOID && name.startsWith( SET_PREFIX )) { pp = new Property( p.ci, null, method ); // PENDING vetoable => constrained } } else if ( params.length == 2 ) { if ( params[0].asType().getKind() == TypeKind.INT && name.startsWith( SET_PREFIX )) { pp = new IdxProperty( p.ci, null, null, null, method ); // PENDING vetoable => constrained } } } catch (IntrospectionException ex) { // PropertyPattern constructor found some differencies from design patterns. LOG.log(Level.INFO, ex.getMessage(), ex); pp = null; } return pp; }