public static boolean isDeFactoPrimitive(TypeKind kind) { return kind.isPrimitive() || HONORARY_PRIMITIVES.contains(kind); }
public boolean isNumberType() { TypeKind kind = returnType.getKind(); return kind.isPrimitive() && kind != TypeKind.CHAR && kind != TypeKind.BOOLEAN; }
public boolean isPrimitive() { return returnType.getKind().isPrimitive(); }
public void doesNotReturnPrimitive(ExecutableElement element, ElementValidation valid) { if (element.getReturnType().getKind().isPrimitive()) { valid.addError("%s cannot return primitive"); } }
public static String toTypeString(TypeMirror type) { if ( type.getKind().isPrimitive() ) { return PRIMITIVE_WRAPPERS.get( type.getKind() ); } return type.toString(); }
@Override public boolean isPrimitive() { return param.asType().getKind().isPrimitive(); }
public boolean isPrimitive() { return element.asType().getKind().isPrimitive(); } }
private static Class propertyClassFor(TypeMirror typeMirror) { if (typeMirror.getKind().isPrimitive()) { switch (typeMirror.getKind()) { case BOOLEAN: return BooleanProperty.class; case BYTE: return ByteProperty.class; case SHORT: return ShortProperty.class; case INT: return IntProperty.class; case LONG: return LongProperty.class; case FLOAT: return FloatProperty.class; case DOUBLE: return DoubleProperty.class; } } return Property.class; }
private static boolean hasPrimitiveType(Node node) { return node.getType().getKind().isPrimitive(); }
private static boolean hasPrimitiveType(Node node) { return node.getType().getKind().isPrimitive(); }
BoundElement(ExecutableElement method) { DeclaringType declaringType = inferDeclaringType(method); this.access = appendAccessModifier(method, new StringBuilder()); this.name = method.getSimpleName(); this.type = method.getReturnType().getKind().isPrimitive() ? wrapType(method.getReturnType().toString()) : appendReturnType(method, new StringBuilder(), declaringType, method.getReturnType()); this.parameters = appendParameters(method, new StringBuilder(), declaringType, true, true); this.arguments = appendParameters(method, new StringBuilder(), declaringType, false, false); } }
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()); }
public RInnerClass(TypeElement rInnerTypeElement) { if (rInnerTypeElement != null) { rInnerQualifiedName = rInnerTypeElement.getQualifiedName().toString(); List<? extends Element> idEnclosedElements = rInnerTypeElement.getEnclosedElements(); List<VariableElement> idFields = ElementFilter.fieldsIn(idEnclosedElements); for (VariableElement idField : idFields) { TypeKind fieldType = idField.asType().getKind(); if (fieldType.isPrimitive() && fieldType.equals(TypeKind.INT)) { String idQualifiedName = rInnerQualifiedName + "." + idField.getSimpleName(); idQualifiedNames.add(idQualifiedName); Integer idFieldId = (Integer) idField.getConstantValue(); if (idFieldId != null) { idQualifiedNamesByIdValues.put(idFieldId, idQualifiedName); } } } } else { rInnerQualifiedName = ""; } }
protected SortedMap<String, JVar> addMethodParams(ExecutableElement executableElement, RestHolder restHolder, JMethod method) { List<? extends VariableElement> params = executableElement.getParameters(); SortedMap<String, JVar> methodParams = new TreeMap<>(); for (VariableElement parameter : params) { String paramName = parameter.getSimpleName().toString(); String paramType = parameter.asType().toString(); JVar param; if (parameter.asType().getKind().isPrimitive()) { param = method.param(getCodeModel().parseType(paramType), paramName); } else { AbstractJClass parameterClass = codeModelHelper.typeMirrorToJClass(parameter.asType()); param = method.param(parameterClass, paramName); } methodParams.put(paramName, param); } return methodParams; }
static AttributeTypeKind from(TypeMirror type) { if (type.getKind() == TypeKind.DECLARED) { TypeElement typeElement = toElement(type); if (typeElement.getKind() == ElementKind.ENUM) { return ENUM; } if (typeElement.getKind() == ElementKind.ANNOTATION_TYPE) { return ANNOTATION; } Name qualifiedName = typeElement.getQualifiedName(); if (qualifiedName.contentEquals(Class.class.getName())) { return TYPE; } if (qualifiedName.contentEquals(String.class.getName())) { return STRING; } } else if (type.getKind().isPrimitive()) { return PRIMITIVE; } throw new AssertionError(); } }
TypeName boxedTypeName(TypeMirror typeMirror) { if (typeMirror.getKind().isPrimitive()) { return TypeName.get(types.boxedClass((PrimitiveType) typeMirror).asType()); } return TypeName.get(typeMirror); }
public static String toArrayTypeString(ArrayType type, Context context) { TypeMirror componentType = type.getComponentType(); if ( componentType.getKind().isPrimitive() ) { return PRIMITIVES.get( componentType.getKind() ) + "[]"; } // When an ArrayType is annotated with an annotation which uses TYPE_USE targets, // we cannot simply take the TypeMirror returned by #getComponentType because it // itself is an AnnotatedType. // // The simplest approach here to get the TypeMirror for both ArrayType use cases // is to use the visitor to retrieve the underlying TypeMirror. TypeMirror component = componentType.accept( new SimpleTypeVisitor6<TypeMirror, Void>() { @Override protected TypeMirror defaultAction(TypeMirror e, Void aVoid) { return e; } }, null ); return extractClosestRealTypeAsString( component, context ) + "[]"; }
void process() { if (startType.getKind().isPrimitive()) { // taking a shortcut for primitives String typeName = Ascii.toLowerCase(startType.getKind().name()); this.rawTypeName = typeName; this.returnTypeName = typeName; List<? extends AnnotationMirror> annotations = AnnotationMirrors.from(startType); if (!annotations.isEmpty()) { returnTypeName = typeAnnotationsToBuffer(annotations, false).append(typeName).toString(); } } else { this.buffer = new StringBuilder(100); caseType(startType); if (workaroundTypeString != null) { // to not mix the mess, we just replace buffer with workaround produced type string this.buffer = new StringBuilder(workaroundTypeString); } // It seems that array type annotations are not exposed in javac // Nested type argument's type annotations are not exposed as well (in javac) // So currently we instert only for top level, declared type (here), // and primitives (see above) TypeKind k = startType.getKind(); if (k == TypeKind.DECLARED || k == TypeKind.ERROR) { insertTypeAnnotationsIfPresent(startType, 0, rawTypeName.length()); } this.returnTypeName = buffer.toString(); } }
public String getWrappedElementType() { if (returnType.getKind().isPrimitive()) { return wrapType(Ascii.toLowerCase(returnType.getKind().name())); } return wrapType(hasContainedElementType() ? firstTypeParameter() : returnTypeName); }
/** * Returns the field (if it exists and is visible) and the setter for a property. If the field is * not available, the first element of the returned pair is {@code null}. */ private Pair<Element, Element> getFieldAndSetterForProperty( Symbol.MethodSymbol symbol, String capPropName) { Element field = null; Element getter = null; String fieldName = decapitalize(capPropName); String getterName = "get" + capPropName; for (Symbol elem : symbol.owner.getEnclosedElements()) { if (elem.getKind().isField() && elem.getSimpleName().toString().equals(fieldName)) { if (field != null) { throw new RuntimeException("already found field " + fieldName); } field = elem; } else if (elem.getKind().equals(ElementKind.METHOD) && elem.getSimpleName().toString().equals(getterName)) { if (getter != null) { throw new RuntimeException("already found getter " + getterName); } getter = elem; } } if (field != null && field.asType().getKind().isPrimitive()) { // ignore primitive properties return Pair.of(null, null); } return Pair.of(field, getter); }