Error out the correct way with nice messages in ConvertDeclaration and ConvertTypeMirror

This commit is contained in:
Travis Burtrum 2018-04-17 16:30:36 -04:00
parent c3e22f44cf
commit b02e035344
3 changed files with 11 additions and 9 deletions

View File

@ -70,6 +70,7 @@ public class ConvertAnnotationProcessorEnvironment implements AnnotationProcesso
elements = internal.getElementUtils();
ConvertDeclaration.elements = elements;
ConvertTypeMirror.types = internal.getTypeUtils();
ConvertDeclaration.messager = ConvertTypeMirror.messager = internal.getMessager();
// now calculate options once, since they are sort-of expensive
// real apt passes them back like so:

View File

@ -26,13 +26,16 @@ import com.sun.mirror.util.DeclarationVisitor;
import com.sun.mirror.util.SourcePosition;
import com.moparisthebest.mirror.log.Debug;
import javax.annotation.processing.Messager;
import javax.lang.model.element.*;
import javax.lang.model.util.Elements;
import javax.tools.Diagnostic;
import java.lang.annotation.Annotation;
import java.util.*;
public class ConvertDeclaration extends Convertable<Element, Declaration> implements com.sun.mirror.declaration.Declaration {
public static Messager messager = null;
public static Elements elements = null;
protected final javax.lang.model.element.Element internalElement;
@ -106,12 +109,9 @@ public class ConvertDeclaration extends Convertable<Element, Declaration> implem
return (T) new ConvertParameterDeclaration((VariableElement) from);
case FIELD:
return (T) new ConvertFieldDeclaration((VariableElement) from);
default:
System.err.println("FATAL ERROR, REACHED DEFAULT!");
System.exit(1);
//throw new RuntimeException("FATAL ERROR, REACHED DEFAULT!");
}
// shouldn't ever get here
messager.printMessage(Diagnostic.Kind.ERROR, "ConvertDeclaration reached default for kind: " + from.getKind(), from);
return (T) new ConvertDeclaration(from);
}

View File

@ -22,12 +22,15 @@ import com.moparisthebest.mirror.convert.Convertable;
import com.sun.mirror.util.TypeVisitor;
import com.moparisthebest.mirror.log.Debug;
import javax.annotation.processing.Messager;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Types;
import javax.tools.Diagnostic;
public class ConvertTypeMirror extends Convertable<TypeMirror, com.sun.mirror.type.TypeMirror> implements com.sun.mirror.type.TypeMirror {
protected final javax.lang.model.type.TypeMirror internalTypeMirror;
public static Messager messager = null;
public static Types types = null;
protected ConvertTypeMirror(javax.lang.model.type.TypeMirror internalTypeMirror) {
@ -100,17 +103,15 @@ public class ConvertTypeMirror extends Convertable<TypeMirror, com.sun.mirror.ty
case ANNOTATION_TYPE:
return (T) new ConvertAnnotationType(dt);
}
//case ERROR:
// return (T) new ConvertDeclaredType((javax.lang.model.type.ErrorType)from);
case NONE:
case NULL:
return null;
default:
System.err.println("FATAL ERROR, REACHED DEFAULT!");
System.exit(1);
//throw new RuntimeException("FATAL ERROR, REACHED DEFAULT!");
}
// shouldn't ever get here
messager.printMessage(Diagnostic.Kind.ERROR, "ConvertTypeMirror reached default for kind: " + from.getKind(), types.asElement(from));
return (T) new ConvertTypeMirror(from);
}
@Override