Unused import trimming. Type parameter cleanup.

This commit is contained in:
Michael Bayne
2010-10-25 19:55:27 +00:00
parent ec04d618c4
commit 5046c1d906
2 changed files with 32 additions and 22 deletions
@@ -60,7 +60,7 @@ public class PersistentRecord
* we hope to make this form of the Key constructor protected. * we hope to make this form of the Key constructor protected.
*/ */
protected static <R extends PersistentRecord> Key<R> newKey ( protected static <R extends PersistentRecord> Key<R> newKey (
Class<R> pClass, Comparable... values) Class<R> pClass, Comparable<?>... values)
{ {
return new Key<R>(pClass, values); return new Key<R>(pClass, values);
} }
@@ -97,10 +97,9 @@ public abstract class FieldMarshaller<T>
} }
try { try {
@SuppressWarnings("unchecked") Transformer<?,?> xformer = Transformer<?,?> xformer = xform.value().newInstance();
xform.value().newInstance(); TransformingMarshaller<?,?> xmarsh =
@SuppressWarnings("unchecked") TransformingMarshaller<?,?> xmarsh = TransformingMarshaller.create(xformer, field, xform);
new TransformingMarshaller(xformer, field, xform);
xmarsh.create(field); xmarsh.create(field);
return xmarsh; return xmarsh;
} catch (InstantiationException e) { } catch (InstantiationException e) {
@@ -381,9 +380,8 @@ public abstract class FieldMarshaller<T>
// special Enum type hackery (it would be nice to handle this with @Transform, but that // special Enum type hackery (it would be nice to handle this with @Transform, but that
// introduces some undesirable samskivert-Depot dependencies) // introduces some undesirable samskivert-Depot dependencies)
} else if (ByteEnum.class.isAssignableFrom(ftype)) { } else if (ByteEnum.class.isAssignableFrom(ftype)) {
@SuppressWarnings("unchecked") ByteEnumMarshaller<?> bem = @SuppressWarnings("unchecked") Class<Dummy> dtype = (Class<Dummy>)ftype;
new ByteEnumMarshaller(ftype); return new ByteEnumMarshaller<Dummy>(dtype);
return bem;
} else { } else {
return null; return null;
@@ -691,20 +689,10 @@ public abstract class FieldMarshaller<T>
} }
protected static class TransformingMarshaller<F,T> extends FieldMarshaller<T> { protected static class TransformingMarshaller<F,T> extends FieldMarshaller<T> {
public TransformingMarshaller ( // simplifies type jockeying
Transformer<F,T> xformer, Field field, Transform annotation) { public static <F,T> TransformingMarshaller<F,T> create (
Class<?> pojoType = getTransformerType(xformer, "from"); Transformer<F,T> xformer, Field field, Transform annotation) {
if (!pojoType.isAssignableFrom(field.getType())) { return new TransformingMarshaller<F,T>(xformer, field, annotation);
throw new IllegalArgumentException(
"@Transform error on " + field.getType().getName() + "." +
field.getName() + ": " + xformer.getClass().getName() + " cannot convert " +
field.getType().getName());
}
@SuppressWarnings("unchecked") FieldMarshaller<T> delegate =
(FieldMarshaller<T>)createMarshaller(getTransformerType(xformer, "to"));
xformer.init(field.getGenericType(), annotation);
_delegate = delegate;
_xformer = xformer;
} }
@Override public void create (Field field) { @Override public void create (Field field) {
@@ -732,10 +720,32 @@ public abstract class FieldMarshaller<T>
_delegate.writeToStatement(ps, column, value); _delegate.writeToStatement(ps, column, value);
} }
protected TransformingMarshaller (
Transformer<F,T> xformer, Field field, Transform annotation) {
Class<?> pojoType = getTransformerType(xformer, "from");
if (!pojoType.isAssignableFrom(field.getType())) {
throw new IllegalArgumentException(
"@Transform error on " + field.getType().getName() + "." +
field.getName() + ": " + xformer.getClass().getName() + " cannot convert " +
field.getType().getName());
}
@SuppressWarnings("unchecked") FieldMarshaller<T> delegate =
(FieldMarshaller<T>)createMarshaller(getTransformerType(xformer, "to"));
xformer.init(field.getGenericType(), annotation);
_delegate = delegate;
_xformer = xformer;
}
protected Transformer<F, T> _xformer; protected Transformer<F, T> _xformer;
protected FieldMarshaller<T> _delegate; protected FieldMarshaller<T> _delegate;
} }
// used to fool the type system when creating ByteEnumMarshallers; look away
protected static enum Dummy implements ByteEnum {
DUMMY;
public byte toByte () { throw new UnsupportedOperationException("Dummy!"); }
}
protected Field _field; protected Field _field;
protected String _columnName; protected String _columnName;
protected ColumnDefinition _columnDefinition; protected ColumnDefinition _columnDefinition;