Print proper errors with links to methods instead of throwing exceptions
This commit is contained in:
parent
f58e107ff5
commit
a22e8d6d58
|
@ -1,6 +1,7 @@
|
|||
package com.moparisthebest.jdbc.codegen;
|
||||
|
||||
import com.moparisthebest.jdbc.Finishable;
|
||||
import com.moparisthebest.jdbc.MapperException;
|
||||
import com.moparisthebest.jdbc.ResultSetMapper;
|
||||
import com.moparisthebest.jdbc.TypeMappingsFactory;
|
||||
import com.moparisthebest.jdbc.util.ResultSetIterable;
|
||||
|
@ -15,6 +16,7 @@ import javax.lang.model.type.TypeKind;
|
|||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.util.Elements;
|
||||
import javax.lang.model.util.Types;
|
||||
import javax.tools.Diagnostic;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.sql.ResultSet;
|
||||
|
@ -98,6 +100,7 @@ public class CompileTimeResultSetMapper {
|
|||
//final Class returnType = m.getReturnType();
|
||||
final TypeMirror returnTypeMirror = eeMethod.getReturnType();
|
||||
//final Class returnType = typeMirrorToClass(returnTypeMirror);
|
||||
try {
|
||||
if (returnTypeMirror.getKind() == TypeKind.ARRAY && !types.isSameType(returnTypeMirror, byteArrayType) && eeMethod.getAnnotation(JdbcMapper.SingleRow.class) == null) {
|
||||
final TypeMirror componentType = ((ArrayType) returnTypeMirror).getComponentType();
|
||||
toArray(w, keys, componentType, maxRows, cal, cleaner, reflectionFields);
|
||||
|
@ -135,12 +138,15 @@ public class CompileTimeResultSetMapper {
|
|||
return false;
|
||||
}
|
||||
//IFJAVA8_END
|
||||
else if(types.isAssignable(returnTypeMirror, resultSetType)) {
|
||||
else if (types.isAssignable(returnTypeMirror, resultSetType)) {
|
||||
toResultSet(w, closePs);
|
||||
return false;
|
||||
} else {
|
||||
toObject(w, keys, returnTypeMirror, cal, cleaner, reflectionFields);
|
||||
}
|
||||
} catch(MapperException e) {
|
||||
JdbcMapperProcessor.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage(), eeMethod);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ public class CompileTimeRowToObjectMapper {
|
|||
// but javac 1.8 prints this with -parameters (wrongly):
|
||||
// methodsAndConstructors: FieldPerson(): '', FieldPerson(long,java.util.Date,java.lang.String,java.lang.String): 'long personNo, java.util.Date firstName, java.lang.String lastName, java.lang.String arg3', FieldPerson(com.moparisthebest.jdbc.dto.Person): 'com.moparisthebest.jdbc.dto.Person person'
|
||||
if(_returnTypeClass.toString().equals("com.moparisthebest.jdbc.dto.FieldPerson"))
|
||||
throw new RuntimeException("methodsAndConstructors: " + methodsAndConstructors.stream().filter(e -> e.getKind() == ElementKind.CONSTRUCTOR && e.getModifiers().contains(Modifier.PUBLIC)).map(e -> e.toString() +
|
||||
throw new MapperException("methodsAndConstructors: " + methodsAndConstructors.stream().filter(e -> e.getKind() == ElementKind.CONSTRUCTOR && e.getModifiers().contains(Modifier.PUBLIC)).map(e -> e.toString() +
|
||||
": '" + ((ExecutableElement)e).getParameters().stream().map(param -> param.asType() + " " + param.getSimpleName().toString()).collect(java.util.stream.Collectors.joining(", ")) + "'"
|
||||
).collect(java.util.stream.Collectors.joining(", ")));
|
||||
*/
|
||||
|
@ -136,7 +136,7 @@ public class CompileTimeRowToObjectMapper {
|
|||
_fieldOrder = null; // didn't successfully finish
|
||||
this.resultSetConstructor = resultSetConstructor;
|
||||
if(!resultSetConstructor && !defaultConstructor && !paramConstructor && _columnCount > 2 && componentType == null)
|
||||
throw new RuntimeException("Exception when trying to get constructor for : "+_returnTypeClass.toString() + " Must have default no-arg constructor or one that takes a single ResultSet.");
|
||||
throw new MapperException("Exception when trying to get constructor for : "+_returnTypeClass.toString() + " Must have default no-arg constructor or one that takes a single ResultSet.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ public class CompileTimeRowToObjectMapper {
|
|||
protected void getFieldMappings() {
|
||||
|
||||
if(_returnTypeClass.getKind() != TypeKind.DECLARED)
|
||||
throw new RuntimeException("_returnTypeClass " + _returnTypeClass + " not TypeKind.DECLARED ?? how??");
|
||||
throw new MapperException("_returnTypeClass " + _returnTypeClass + " not TypeKind.DECLARED ?? how??");
|
||||
|
||||
final DeclaredType declaredReturnType = (DeclaredType)_returnTypeClass;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.moparisthebest.jdbc.codegen;
|
||||
|
||||
import com.moparisthebest.jdbc.Cleaner;
|
||||
import com.moparisthebest.jdbc.MapperException;
|
||||
|
||||
import javax.annotation.processing.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
|
@ -703,7 +704,7 @@ public class JdbcMapperProcessor extends AbstractProcessor {
|
|||
case DOUBLE:
|
||||
return double[].class;
|
||||
case ARRAY:
|
||||
throw new RuntimeException("multi-dimensional arrays are not supported");
|
||||
throw new MapperException("multi-dimensional arrays are not supported");
|
||||
default:
|
||||
return Class.forName("[L" + arrayComponentType.toString() + ";");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue