use of javax.lang.model.type.DeclaredType in project immutables by immutables.
the class TypeStringProvider method caseType.
void caseType(TypeMirror type) {
if (ended) {
// to prevent additional recursive effects when using workaround
return;
}
switch(type.getKind()) {
case ERROR:
unresolvedTypeHasOccured = true;
//$FALL-THROUGH$
case DECLARED:
DeclaredType declaredType = (DeclaredType) type;
appendResolved(declaredType);
appendTypeArguments(type, declaredType);
break;
case ARRAY:
TypeMirror componentType = ((ArrayType) type).getComponentType();
int mark = buffer.length();
caseType(componentType);
cutTypeArgument(type, mark);
buffer.append('[').append(']');
break;
case WILDCARD:
WildcardType wildcard = (WildcardType) type;
@Nullable TypeMirror extendsBound = wildcard.getExtendsBound();
@Nullable TypeMirror superBound = wildcard.getSuperBound();
if (extendsBound != null) {
buffer.append("? extends ");
caseType(extendsBound);
} else if (superBound != null) {
buffer.append("? super ");
caseType(superBound);
} else {
buffer.append('?');
}
break;
case TYPEVAR:
if (allowedTypevars.length != 0) {
TypeVariable typeVariable = (TypeVariable) type;
String var = typeVariable.toString();
int indexOfVar = Arrays.asList(allowedTypevars).indexOf(var);
if (indexOfVar >= 0) {
if (typevarArguments != null) {
buffer.append(typevarArguments[indexOfVar]);
} else {
hasTypeVariables = true;
buffer.append(var);
}
break;
}
// If we don't have such parameter we consider this is the quirk
// that was witnessed in Eclipse, we let the code below deal with it.
}
// ended flag
if (tryToUseSourceAsAWorkaround()) {
ended = true;
break;
}
reporter.withElement(element).error("It is a compiler/annotation processing bug to receive type variable '%s' here." + " To avoid it — do not use not yet generated types in %s attribute", type, element.getSimpleName());
// just append as toString whatever we have
buffer.append(type);
break;
default:
buffer.append(type);
}
}
use of javax.lang.model.type.DeclaredType in project immutables by immutables.
the class ValueAttribute method introspectType.
@Override
protected void introspectType() {
TypeMirror typeMirror = returnType;
// Special case for primitive Optional, may become a pattern for specialized types
if (typeKind.isOptionalSpecializedJdk()) {
typeParameters = ImmutableList.of(optionalSpecializedType());
// no delegation to introspect further
return;
}
if (isContainerType()) {
if (typeMirror.getKind() == TypeKind.DECLARED || typeMirror.getKind() == TypeKind.ERROR) {
DeclaredType declaredType = (DeclaredType) typeMirror;
List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
if (!typeArguments.isEmpty()) {
final TypeMirror typeArgument = typeArguments.get(0);
if (isSetType() && protoclass().environment().hasOrdinalModule()) {
this.generateOrdinalValueSet = new TypeIntrospectionBase() {
@Override
protected TypeMirror internalTypeMirror() {
return typeArgument;
}
@Override
protected TypeHierarchyCollector collectTypeHierarchy(TypeMirror typeMirror) {
TypeHierarchyCollector collector = containingType.createTypeHierarchyCollector(reporter, element);
collector.collectFrom(typeMirror);
return collector;
}
}.isOrdinalValue();
}
if (isMapType()) {
TypeMirror typeSecondArgument = typeArguments.get(1);
if (typeSecondArgument.getKind() == TypeKind.DECLARED) {
TypeElement typeElement = (TypeElement) ((DeclaredType) typeSecondArgument).asElement();
this.containedSecondaryTypeElement = typeElement;
}
}
typeMirror = typeArgument;
}
}
} else if (isArrayType()) {
arrayComponent = ((ArrayType) typeMirror).getComponentType();
typeMirror = arrayComponent;
}
if (typeMirror.getKind() == TypeKind.DECLARED) {
TypeElement typeElement = (TypeElement) ((DeclaredType) typeMirror).asElement();
this.containedTypeElement = typeElement;
}
introspectTypeMirror(typeMirror);
introspectSupertypes();
}
use of javax.lang.model.type.DeclaredType in project immutables by immutables.
the class TypeHierarchyCollector method collectHierarchyMirrors.
private void collectHierarchyMirrors(TypeMirror typeMirror, String stringRepresentation) {
if (typeMirror.getKind() != TypeKind.DECLARED || typeMirror.toString().equals(Object.class.getName())) {
return;
}
DeclaredType declaredType = toDeclaredType(typeMirror);
TypeElement e = toTypeElement(declaredType);
TypevarContext context = new TypevarContext(e, stringRepresentation);
collectInterfacesMirrors(declaredType, context);
TypeMirror superclassMirror = e.getSuperclass();
if (superclassMirror.getKind() != TypeKind.NONE) {
DeclaredType superclass = toDeclaredType(superclassMirror);
String stringified = stringify(superclass, context);
if (!stringified.equals(Object.class.getName())) {
extendedClasses.add(toTypeElement(superclass));
extendedClassNames.add(stringified);
collectHierarchyMirrors(superclass, stringified);
}
}
for (TypeMirror m : e.getInterfaces()) {
collectUnresolvedInterface(m, context);
collectInterfacesMirrors(m, context);
}
}
use of javax.lang.model.type.DeclaredType in project immutables by immutables.
the class TypeHierarchyCollector method collectInterfacesMirrors.
private void collectInterfacesMirrors(TypeMirror typeMirror, TypevarContext context) {
if (typeMirror.getKind() != TypeKind.DECLARED) {
return;
}
DeclaredType declaredType = toDeclaredType(typeMirror);
TypeElement e = toTypeElement(declaredType);
if (e.getKind().isInterface()) {
implementedInterfaces.add(e);
String stringified = stringify(declaredType, context);
TypevarContext nestedContext = new TypevarContext(e, stringified);
implementedInterfaceNames.add(stringified);
for (TypeMirror m : e.getInterfaces()) {
collectInterfacesMirrors(m, nestedContext);
}
}
}
use of javax.lang.model.type.DeclaredType in project hibernate-orm by hibernate.
the class ClassWriter method findMappedSuperClass.
private static String findMappedSuperClass(MetaEntity entity, Context context) {
TypeMirror superClass = entity.getTypeElement().getSuperclass();
//superclass of Object is of NoType which returns some other kind
while (superClass.getKind() == TypeKind.DECLARED) {
//F..king Ch...t Have those people used their horrible APIs even once?
final Element superClassElement = ((DeclaredType) superClass).asElement();
String superClassName = ((TypeElement) superClassElement).getQualifiedName().toString();
if (extendsSuperMetaModel(superClassElement, entity.isMetaComplete(), context)) {
return superClassName;
}
superClass = ((TypeElement) superClassElement).getSuperclass();
}
return null;
}
Aggregations