use of com.google.auto.value.processor.MissingTypes.MissingTypeException in project auto by google.
the class TypeSimplifier method ambiguousNames.
private static Set<String> ambiguousNames(Types typeUtils, Set<TypeMirror> types) {
Set<String> ambiguous = new HashSet<>();
Map<String, Name> simpleNamesToQualifiedNames = new HashMap<>();
for (TypeMirror type : types) {
if (type.getKind() == TypeKind.ERROR) {
throw new MissingTypeException(MoreTypes.asError(type));
}
String simpleName = typeUtils.asElement(type).getSimpleName().toString();
/*
* Compare by qualified names, because in Eclipse JDT, if Java 8 type annotations are used,
* the same (unannotated) type may appear multiple times in the Set<TypeMirror>.
* TODO(emcmanus): investigate further, because this might cause problems elsewhere.
*/
Name qualifiedName = ((QualifiedNameable) typeUtils.asElement(type)).getQualifiedName();
Name previous = simpleNamesToQualifiedNames.put(simpleName, qualifiedName);
if (previous != null && !previous.equals(qualifiedName)) {
ambiguous.add(simpleName);
}
}
return ambiguous;
}
use of com.google.auto.value.processor.MissingTypes.MissingTypeException in project auto by google.
the class AutoBuilderProcessor method findOfClassValue.
private TypeElement findOfClassValue(AnnotationMirror autoBuilderAnnotation) {
AnnotationValue ofClassValue = AnnotationMirrors.getAnnotationValue(autoBuilderAnnotation, "ofClass");
Object value = ofClassValue.getValue();
if (value instanceof TypeMirror) {
TypeMirror ofClassType = (TypeMirror) value;
switch(ofClassType.getKind()) {
case DECLARED:
return MoreTypes.asTypeElement(ofClassType);
case ERROR:
throw new MissingTypeException(MoreTypes.asError(ofClassType));
default:
break;
}
}
throw new MissingTypeException(null);
}
use of com.google.auto.value.processor.MissingTypes.MissingTypeException in project auto by google.
the class AutoValueishProcessor method process.
@Override
public final boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (annotationType == null) {
// This should not happen. If the annotation type is not found, how did the processor get
// triggered?
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Did not process @" + annotationClassName + " because the annotation class was not found");
return false;
}
List<TypeElement> deferredTypes = deferredTypeNames.stream().map(name -> elementUtils().getTypeElement(name)).collect(toList());
if (roundEnv.processingOver()) {
// was in deferredTypes.
for (TypeElement type : deferredTypes) {
errorReporter.reportError(type, "[%sUndefined] Did not generate @%s class for %s because it references" + " undefined types", simpleAnnotationName, simpleAnnotationName, type.getQualifiedName());
}
return false;
}
Collection<? extends Element> annotatedElements = roundEnv.getElementsAnnotatedWith(annotationType);
List<TypeElement> types = new ImmutableList.Builder<TypeElement>().addAll(deferredTypes).addAll(ElementFilter.typesIn(annotatedElements)).build();
deferredTypeNames.clear();
for (TypeElement type : types) {
try {
validateType(type);
processType(type);
} catch (AbortProcessingException e) {
// We abandoned this type; continue with the next.
} catch (MissingTypeException e) {
// We abandoned this type, but only because we needed another type that it references and
// that other type was missing. It is possible that the missing type will be generated by
// further annotation processing, so we will try again on the next round (perhaps failing
// again and adding it back to the list).
addDeferredType(type);
} catch (RuntimeException e) {
String trace = Throwables.getStackTraceAsString(e);
errorReporter.reportError(type, "[%sException] @%s processor threw an exception: %s", simpleAnnotationName, simpleAnnotationName, trace);
throw e;
}
}
// never claim annotation, because who knows what other processors want?
return false;
}
use of com.google.auto.value.processor.MissingTypes.MissingTypeException in project auto by google.
the class AutoOneOfProcessor method mirrorForKindType.
private DeclaredType mirrorForKindType(TypeElement autoOneOfType) {
// The annotation is guaranteed to be present by the contract of Processor#process
AnnotationMirror oneOfAnnotation = getAnnotationMirror(autoOneOfType, AUTO_ONE_OF_NAME).get();
AnnotationValue kindValue = AnnotationMirrors.getAnnotationValue(oneOfAnnotation, "value");
Object value = kindValue.getValue();
if (value instanceof TypeMirror) {
TypeMirror kindType = (TypeMirror) value;
switch(kindType.getKind()) {
case DECLARED:
return MoreTypes.asDeclared(kindType);
case ERROR:
throw new MissingTypeException(MoreTypes.asError(kindType));
default:
break;
}
}
throw new MissingTypeException(null);
}
Aggregations