use of javax.lang.model.type.PrimitiveType in project requery by requery.
the class AttributeMember method checkMemberType.
private void checkMemberType(ProcessingEnvironment processingEnvironment, Set<ElementValidator> validators) {
builderClass = AttributeBuilder.class;
Types types = processingEnvironment.getTypeUtils();
TypeMirror mirror = typeMirror();
isBoolean = mirror.getKind() == TypeKind.BOOLEAN;
if (mirror.getKind() == TypeKind.DECLARED) {
TypeElement element = (TypeElement) types.asElement(mirror);
if (element != null) {
// only set if the attribute is relational
if (cardinality != null) {
isIterable = Mirrors.isInstance(types, element, Iterable.class);
}
isMap = Mirrors.isInstance(types, element, Map.class);
if (isMap && cardinality != null) {
builderClass = MapAttributeBuilder.class;
}
// check for optional compatible types
String[] names = { Optional.class.getName(), "com.google.common.base.Optional", "java8.util.Optional" };
for (String name : names) {
if (Mirrors.isInstance(types, element, name)) {
isOptional = true;
optionalClassName = name;
break;
}
}
isBoolean = Mirrors.isInstance(types, element, Boolean.class);
}
}
if (isIterable) {
ElementValidator validator = validateCollectionType(processingEnvironment);
if (validator != null) {
validators.add(validator);
}
} else {
TypeElement element = null;
if (mirror.getKind().isPrimitive()) {
element = types.boxedClass((PrimitiveType) mirror);
} else if (mirror.getKind() == TypeKind.DECLARED) {
element = (TypeElement) types.asElement(mirror);
}
if (element != null) {
if (Mirrors.isInstance(types, element, Number.class) || Mirrors.isInstance(types, element, java.util.Date.class) || Mirrors.isInstance(types, element, java.time.temporal.Temporal.class)) {
type = Type.NUMERIC;
} else if (Mirrors.isInstance(types, element, String.class)) {
type = Type.STRING;
}
}
}
}
use of javax.lang.model.type.PrimitiveType in project tiger by google.
the class DependencyCollector method getDependencyInfoForMethod.
@Nullable
public DependencyInfo getDependencyInfoForMethod(ExecutableElement method, DependencySourceType dependencySourceType, @Nullable TypeElement source, @Nullable CoreInjectorInfo coreInjectorInfo) {
BindingKey key = getBindingKeyForMethod(method);
if (key == null) {
return null;
}
// logger.n(TAG + ".getDependencyInfoForMethod: method " + method);
AnnotationMirror annotation = utils.getQualifier(method);
List<BindingKey> keys = utils.getDependenciesFromExecutableElement(method);
// Could be from module or other source like component dependencies.
ProvisionType provideType = utils.isProvisionMethodInModule(method) ? utils.getProvisionType(method) : UNIQUE;
if (SET.equals(provideType)) {
key = BindingKey.get(ParameterizedTypeName.get(ClassName.get(Set.class), key.getTypeName()), annotation);
} else if (MAP.equals(provideType) && !utils.isMultibindsMethod(method)) {
AnnotationMirror mapKeyedMirror = Preconditions.checkNotNull(utils.getMapKey(method), String.format("Map binding %s missed MapKey.", method));
AnnotationMirror mapKeyMirror = utils.getAnnotationMirror(mapKeyedMirror.getAnnotationType().asElement(), MapKey.class);
AnnotationValue unwrapValue = utils.getAnnotationValue(elements, mapKeyMirror, "unwrapValue");
if (unwrapValue != null && !((Boolean) unwrapValue.getValue())) {
logger.e(String.format("MapKey with unwrapValue false is not supported, yet. Biding: %s", method));
}
TypeMirror keyTypeMirror = Preconditions.checkNotNull(utils.getElementTypeMirror(mapKeyedMirror, "value"), String.format("Get key type failed for binding %s", method));
if (keyTypeMirror instanceof PrimitiveType) {
keyTypeMirror = types.boxedClass((PrimitiveType) keyTypeMirror).asType();
}
TypeMirror valueTypeMirror = method.getReturnType();
AnnotationMirror qualifier = utils.getQualifier(method);
key = BindingKey.get(ParameterizedTypeName.get(ClassName.get(Map.class), TypeName.get(keyTypeMirror), TypeName.get(valueTypeMirror)), qualifier);
}
DependencyInfo result = new DependencyInfo(dependencySourceType, key, Sets.newHashSet(keys), source != null ? source : (TypeElement) method.getEnclosingElement(), method, provideType, coreInjectorInfo);
return result;
}
use of javax.lang.model.type.PrimitiveType in project neo4j by neo4j.
the class TypeMirrorUtils method procedureAllowedTypes.
public final Collection<TypeMirror> procedureAllowedTypes() {
PrimitiveType bool = primitive(TypeKind.BOOLEAN);
PrimitiveType longType = primitive(TypeKind.LONG);
PrimitiveType doubleType = primitive(TypeKind.DOUBLE);
return asList(bool, boxed(bool), longType, boxed(longType), doubleType, boxed(doubleType), typeMirror(String.class), typeMirror(Number.class), typeMirror(Object.class), typeMirror(Map.class), typeMirror(List.class), typeMirror(Node.class), typeMirror(Relationship.class), typeMirror(Path.class));
}
Aggregations