use of javax.lang.model.type.TypeKind in project immutables by immutables.
the class Imports method collectBuiltins.
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());
}
use of javax.lang.model.type.TypeKind in project androidannotations by androidannotations.
the class ValidatorHelper method returnTypeIsVoidOrBoolean.
public void returnTypeIsVoidOrBoolean(ExecutableElement executableElement, ElementValidation valid) {
TypeMirror returnType = executableElement.getReturnType();
TypeKind returnKind = returnType.getKind();
if (returnKind != TypeKind.BOOLEAN && returnKind != TypeKind.VOID && !returnType.toString().equals(CanonicalNameConstants.BOOLEAN)) {
valid.addError("%s can only be used on a method with a boolean or a void return type");
}
}
use of javax.lang.model.type.TypeKind in project realm-java by realm.
the class Utils method getGenericTypeForContainer.
// Note that, because subclassing subclasses of RealmObject is forbidden,
// there is no need to deal with constructs like: <code>RealmResults<? extends Foos<</code>.
public static DeclaredType getGenericTypeForContainer(VariableElement field) {
TypeMirror fieldType = field.asType();
TypeKind kind = fieldType.getKind();
if (kind != TypeKind.DECLARED) {
return null;
}
List<? extends TypeMirror> args = ((DeclaredType) fieldType).getTypeArguments();
if (args.size() <= 0) {
return null;
}
fieldType = args.get(0);
kind = fieldType.getKind();
if (kind != TypeKind.DECLARED) {
return null;
}
return (DeclaredType) fieldType;
}
use of javax.lang.model.type.TypeKind in project spring-boot by spring-projects.
the class TypeUtils method getWrapperOrPrimitiveFor.
public TypeMirror getWrapperOrPrimitiveFor(TypeMirror typeMirror) {
Class<?> candidate = getWrapperFor(typeMirror);
if (candidate != null) {
return this.env.getElementUtils().getTypeElement(candidate.getName()).asType();
}
TypeKind primitiveKind = getPrimitiveFor(typeMirror);
if (primitiveKind != null) {
return this.env.getTypeUtils().getPrimitiveType(primitiveKind);
}
return null;
}
use of javax.lang.model.type.TypeKind in project lwjgl by LWJGL.
the class TypeInfo method getTypeInfos.
private static Collection<TypeInfo> getTypeInfos(TypeMap type_map, VariableElement param) {
List<? extends AnnotationMirror> annotations = Utils.getSortedAnnotations(param.getAnnotationMirrors());
GLvoid void_annotation = param.getAnnotation(GLvoid.class);
Map<Class, TypeInfo> types = new HashMap<Class, TypeInfo>();
Collection<TypeInfo> multityped_result = new ArrayList<TypeInfo>();
boolean add_default_type = true;
for (AnnotationMirror annotation : annotations) {
NativeType native_type_annotation = NativeTypeTranslator.getAnnotation(annotation, NativeType.class);
if (native_type_annotation != null) {
Class<? extends Annotation> annotation_type = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
Signedness signedness = type_map.getSignednessFromType(annotation_type);
Class inverse_type = type_map.getInverseType(annotation_type);
String auto_type = type_map.getAutoTypeFromAnnotation(annotation);
if (inverse_type != null) {
if (types.containsKey(inverse_type)) {
TypeInfo inverse_type_info = types.get(inverse_type);
String inverse_auto_type = inverse_type_info.getAutoType();
auto_type = signedness == Signedness.UNSIGNED ? auto_type + " : " + inverse_auto_type : inverse_auto_type + " : " + auto_type;
auto_type = UNSIGNED_PARAMETER_NAME + " ? " + auto_type;
signedness = Signedness.BOTH;
types.remove(inverse_type);
multityped_result.remove(inverse_type_info);
}
}
Class type;
TypeKind kind;
kind = void_annotation == null ? type_map.getPrimitiveTypeFromNativeType(annotation_type) : void_annotation.value();
if (Utils.getNIOBufferType(param.asType()) != null) {
type = getBufferTypeFromPrimitiveKind(kind, annotation);
} else {
type = getTypeFromPrimitiveKind(kind);
}
TypeInfo type_info = new TypeInfo(type, signedness, auto_type);
types.put(annotation_type, type_info);
multityped_result.add(type_info);
add_default_type = false;
}
}
if (add_default_type) {
TypeInfo default_type_info = getDefaultTypeInfo(param.asType());
Collection<TypeInfo> result = new ArrayList<TypeInfo>();
result.add(default_type_info);
return result;
} else {
return multityped_result;
}
}
Aggregations