Changeset 152:05e66586464a
- Timestamp:
- 08/13/2008 11:52:49 PM
(4 months ago)
- Author:
- marc@f1.local
- branch:
- default
- Message:
brought writeMethodAPT annotation processing up to date (now handles double fields for example)
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r0 |
r152 |
|
| 255 | 255 | construtorOut.println(name + " = " + name + "_s.boundMember(x);"); |
|---|
| 256 | 256 | } |
|---|
| 257 | | } else { |
|---|
| 258 | | // assume float case for now |
|---|
| | 257 | } |
|---|
| | 258 | else if (isFloat(f.getType())) |
|---|
| | 259 | { |
|---|
| 259 | 260 | |
|---|
| 260 | 261 | deferedOut.println("static public final " + prefix + "Mirroring.MirrorFloatMember<" + inside + "> " + name + "_s = new " + prefix + "Mirroring.MirrorFloatMember<" + inside + ">(" + inside + ".class,\"" + name + "\");"); |
|---|
| 261 | 262 | deferedOut.println("public final Mirroring.iBoundFloatMember " + name + ";"); |
|---|
| | 263 | |
|---|
| | 264 | construtorOut.println(name + " = " + name + "_s.boundMember(x);"); |
|---|
| | 265 | } |
|---|
| | 266 | else if (isDouble(f.getType())) |
|---|
| | 267 | { |
|---|
| | 268 | |
|---|
| | 269 | deferedOut.println("static public final " + prefix + "Mirroring.MirrorDoubleMember<" + inside + "> " + name + "_s = new " + prefix + "Mirroring.MirrorDoubleMember<" + inside + ">(" + inside + ".class,\"" + name + "\");"); |
|---|
| | 270 | deferedOut.println("public final Mirroring.iBoundDoubleMember " + name + ";"); |
|---|
| 262 | 271 | |
|---|
| 263 | 272 | construtorOut.println(name + " = " + name + "_s.boundMember(x);"); |
|---|
| … | … | |
| 277 | 286 | |
|---|
| 278 | 287 | private boolean isPrimative(TypeMirror type) { |
|---|
| | 288 | return isFloat(type) || isDouble(type); |
|---|
| | 289 | } |
|---|
| | 290 | |
|---|
| | 291 | private boolean isFloat(TypeMirror type) { |
|---|
| 279 | 292 | final boolean[] isPrimative = { false}; |
|---|
| 280 | 293 | type.accept(new SimpleTypeVisitor(){ |
|---|
| 281 | 294 | public void visitPrimitiveType(PrimitiveType arg0) { |
|---|
| 282 | | isPrimative[0] = true; |
|---|
| 283 | | |
|---|
| 284 | | assert arg0.getKind() == Kind.FLOAT : "unhandled primative type <" + arg0.getKind() + "> not implemented"; |
|---|
| | 295 | isPrimative[0] = arg0.getKind() == Kind.FLOAT; |
|---|
| | 296 | |
|---|
| | 297 | //assert arg0.getKind() == Kind.FLOAT : "unhandled primative type <" + arg0.getKind() + "> not implemented"; |
|---|
| | 298 | } |
|---|
| | 299 | }); |
|---|
| | 300 | return isPrimative[0]; |
|---|
| | 301 | } |
|---|
| | 302 | |
|---|
| | 303 | private boolean isDouble(TypeMirror type) { |
|---|
| | 304 | final boolean[] isPrimative = { false}; |
|---|
| | 305 | type.accept(new SimpleTypeVisitor(){ |
|---|
| | 306 | public void visitPrimitiveType(PrimitiveType arg0) { |
|---|
| | 307 | isPrimative[0] = arg0.getKind() == Kind.DOUBLE; |
|---|
| | 308 | |
|---|
| | 309 | //assert arg0.getKind() == Kind.FLOAT : "unhandled primative type <" + arg0.getKind() + "> not implemented"; |
|---|
| 285 | 310 | } |
|---|
| 286 | 311 | }); |
|---|
| r18 |
r152 |
|
| 30 | 30 | } |
|---|
| 31 | 31 | |
|---|
| | 32 | public interface iBoundDoubleMember extends iDoubleProvider, iBoundMember<Double> { |
|---|
| | 33 | } |
|---|
| | 34 | |
|---|
| 32 | 35 | public interface iBoundMember<t_is> extends iProvider<t_is>, iAcceptor<t_is> { |
|---|
| 33 | 36 | } |
|---|
| … | … | |
| 105 | 108 | |
|---|
| 106 | 109 | } |
|---|
| | 110 | |
|---|
| | 111 | static public class MirrorDoubleMember<t_class> extends MirrorMember<t_class, Double> { |
|---|
| | 112 | |
|---|
| | 113 | public MirrorDoubleMember(Class on, String name) { |
|---|
| | 114 | super(on, name, Double.TYPE); |
|---|
| | 115 | } |
|---|
| | 116 | |
|---|
| | 117 | @Override |
|---|
| | 118 | public <A extends t_class> iBoundDoubleMember boundMember(final A to) { |
|---|
| | 119 | final iAcceptor<Double> a = acceptor(to); |
|---|
| | 120 | final iProvider<Double> p = provider(to); |
|---|
| | 121 | final iDoubleProvider f = doubleProvider(to); |
|---|
| | 122 | |
|---|
| | 123 | return new iBoundDoubleMember() { |
|---|
| | 124 | |
|---|
| | 125 | public double evaluate() { |
|---|
| | 126 | return f.evaluate(); |
|---|
| | 127 | } |
|---|
| | 128 | |
|---|
| | 129 | public Double get() { |
|---|
| | 130 | return p.get(); |
|---|
| | 131 | } |
|---|
| | 132 | |
|---|
| | 133 | public iAcceptor<Double> set(Double to) { |
|---|
| | 134 | a.set(to); |
|---|
| | 135 | return this; |
|---|
| | 136 | } |
|---|
| | 137 | |
|---|
| | 138 | }; |
|---|
| | 139 | } |
|---|
| | 140 | |
|---|
| | 141 | public <A extends t_class> iDoubleProvider doubleProvider(final A to) { |
|---|
| | 142 | return new iDoubleProvider() { |
|---|
| | 143 | public double evaluate() { |
|---|
| | 144 | try { |
|---|
| | 145 | return ((Number) field.get(to)).doubleValue(); |
|---|
| | 146 | } catch (IllegalAccessException e) { |
|---|
| | 147 | throw new IllegalArgumentException(e); |
|---|
| | 148 | } |
|---|
| | 149 | } |
|---|
| | 150 | }; |
|---|
| | 151 | } |
|---|
| | 152 | |
|---|
| | 153 | public <A extends t_class> iFloatProvider floatProvider(final A to) { |
|---|
| | 154 | return new iFloatProvider() { |
|---|
| | 155 | public float evaluate() { |
|---|
| | 156 | try { |
|---|
| | 157 | return ((Number) field.get(to)).floatValue(); |
|---|
| | 158 | } catch (IllegalAccessException e) { |
|---|
| | 159 | throw new IllegalArgumentException(e); |
|---|
| | 160 | } |
|---|
| | 161 | } |
|---|
| | 162 | }; |
|---|
| | 163 | } |
|---|
| | 164 | |
|---|
| | 165 | } |
|---|
| | 166 | |
|---|
| 107 | 167 | |
|---|
| 108 | 168 | static public class MirrorMember<t_class, t_is> implements iMethodMember<t_class, t_is> { |
|---|