diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2008-12-27 01:40:50 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2008-12-27 01:40:50 +0000 |
commit | 6e894b3ebd0c2d6d2c2551ec013ae8db885d7ab4 (patch) | |
tree | 269850113c14fcedf532d34d2e97da33fe2c885b /src/main/java/com/amazon/carbonado/gen | |
parent | 13fc667eeb9cd108f9d0e8d5019cdbd949d3cab9 (diff) |
Support covariant properties. Cojen must support this feature too in order to work (revision 169).
Diffstat (limited to 'src/main/java/com/amazon/carbonado/gen')
-rw-r--r-- | src/main/java/com/amazon/carbonado/gen/StorableGenerator.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java index d194634..f84748f 100644 --- a/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java +++ b/src/main/java/com/amazon/carbonado/gen/StorableGenerator.java @@ -968,6 +968,8 @@ public final class StorableGenerator<S extends Storable> { b.returnVoid();
}
}
+
+ addPropertyBridges(property);
}
}
@@ -1760,6 +1762,50 @@ public final class StorableGenerator<S extends Storable> { }
}
+ private void addPropertyBridges(StorableProperty<S> property) {
+ Class[] covariantTypes = property.getCovariantTypes();
+ if (covariantTypes == null || covariantTypes.length == 0) {
+ return;
+ }
+
+ // Define copy bridges to allow covariant property types.
+
+ for (Class type : covariantTypes) {
+ TypeDesc desc = TypeDesc.forClass(type);
+
+ if (property.getReadMethod() != null &&
+ property.getReadMethod().getReturnType() != type)
+ {
+ MethodInfo mi = addMethodIfNotFinal
+ (Modifiers.PUBLIC.toBridge(true), property.getReadMethodName(), desc, null);
+
+ if (mi != null) {
+ CodeBuilder b = new CodeBuilder(mi);
+ b.loadThis();
+ b.invoke(property.getReadMethod());
+ b.returnValue(desc);
+ }
+ }
+
+ if (property.getWriteMethod() != null &&
+ property.getWriteMethod().getParameterTypes()[0] != type)
+ {
+ // Not actually defined as a bridge method since parameter type differs.
+ MethodInfo mi = addMethodIfNotFinal
+ (Modifiers.PUBLIC, property.getWriteMethodName(), null, new TypeDesc[] {desc});
+
+ if (mi != null) {
+ CodeBuilder b = new CodeBuilder(mi);
+ b.loadThis();
+ b.loadLocal(b.getParameter(0));
+ b.checkCast(TypeDesc.forClass(property.getType()));
+ b.invoke(property.getWriteMethod());
+ b.returnVoid();
+ }
+ }
+ }
+ }
+
/**
* Generates a copy properties method with several options to control its
* behavior. Although eight combinations can be defined, only four are
|