|
16 | 16 | package rx.lang.groovy;
|
17 | 17 |
|
18 | 18 | import groovy.lang.Closure;
|
19 |
| -import groovy.lang.GroovySystem; |
20 | 19 | import groovy.lang.MetaMethod;
|
21 | 20 |
|
22 | 21 | import java.lang.reflect.InvocationTargetException;
|
23 | 22 | import java.lang.reflect.Method;
|
24 | 23 | import java.util.ArrayList;
|
25 |
| -import java.util.HashMap; |
26 | 24 | import java.util.List;
|
27 |
| -import java.util.Map; |
28 |
| -import java.util.Properties; |
29 | 25 |
|
30 | 26 | import org.codehaus.groovy.reflection.CachedClass;
|
31 | 27 | import org.codehaus.groovy.reflection.ReflectionCache;
|
32 | 28 | import org.codehaus.groovy.runtime.m12n.ExtensionModule;
|
33 |
| -import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl; |
34 | 29 |
|
35 | 30 | import rx.Observable;
|
36 | 31 | import rx.Observable.OnSubscribeFunc;
|
@@ -75,6 +70,9 @@ public List<MetaMethod> getMetaMethods() {
|
75 | 70 | }
|
76 | 71 |
|
77 | 72 | private MetaMethod createMetaMethod(final Method m) {
|
| 73 | + if (m.getDeclaringClass().equals(Observable.class) && m.getName().equals("create")) { |
| 74 | + return specialCasedOverrideForCreate(m); |
| 75 | + } |
78 | 76 | return new MetaMethod() {
|
79 | 77 |
|
80 | 78 | @Override
|
@@ -109,12 +107,11 @@ public Object invoke(Object object, Object[] arguments) {
|
109 | 107 | if (o instanceof Closure) {
|
110 | 108 | if (Action.class.isAssignableFrom(m.getParameterTypes()[i])) {
|
111 | 109 | newArgs[i] = new GroovyActionWrapper((Closure) o);
|
112 |
| - } else if(OnSubscribeFunc.class.isAssignableFrom(m.getParameterTypes()[i])) { |
| 110 | + } else if (OnSubscribeFunc.class.isAssignableFrom(m.getParameterTypes()[i])) { |
113 | 111 | newArgs[i] = new GroovyOnSubscribeFuncWrapper((Closure) o);
|
114 | 112 | } else {
|
115 | 113 | newArgs[i] = new GroovyFunctionWrapper((Closure) o);
|
116 | 114 | }
|
117 |
| - |
118 | 115 | } else {
|
119 | 116 | newArgs[i] = o;
|
120 | 117 | }
|
@@ -152,4 +149,55 @@ public CachedClass[] getParameterTypes() {
|
152 | 149 | }
|
153 | 150 | };
|
154 | 151 | }
|
| 152 | + |
| 153 | + /** |
| 154 | + * Special case until we finish migrating off the deprecated 'create' method signature |
| 155 | + */ |
| 156 | + private MetaMethod specialCasedOverrideForCreate(final Method m) { |
| 157 | + return new MetaMethod() { |
| 158 | + |
| 159 | + @Override |
| 160 | + public int getModifiers() { |
| 161 | + return m.getModifiers(); |
| 162 | + } |
| 163 | + |
| 164 | + @Override |
| 165 | + public String getName() { |
| 166 | + return m.getName(); |
| 167 | + } |
| 168 | + |
| 169 | + @Override |
| 170 | + public Class getReturnType() { |
| 171 | + return m.getReturnType(); |
| 172 | + } |
| 173 | + |
| 174 | + @Override |
| 175 | + public CachedClass getDeclaringClass() { |
| 176 | + return ReflectionCache.getCachedClass(m.getDeclaringClass()); |
| 177 | + } |
| 178 | + |
| 179 | + @Override |
| 180 | + public Object invoke(Object object, final Object[] arguments) { |
| 181 | + return Observable.create(new GroovyCreateWrapper((Closure) arguments[0])); |
| 182 | + } |
| 183 | + |
| 184 | + @SuppressWarnings("rawtypes") |
| 185 | + @Override |
| 186 | + public CachedClass[] getParameterTypes() { |
| 187 | + Class[] pts = m.getParameterTypes(); |
| 188 | + CachedClass[] cc = new CachedClass[pts.length]; |
| 189 | + for (int i = 0; i < pts.length; i++) { |
| 190 | + if (Function.class.isAssignableFrom(pts[i])) { |
| 191 | + // function type to be replaced by closure |
| 192 | + cc[i] = ReflectionCache.getCachedClass(Closure.class); |
| 193 | + } else { |
| 194 | + // non-function type |
| 195 | + cc[i] = ReflectionCache.getCachedClass(pts[i]); |
| 196 | + } |
| 197 | + } |
| 198 | + return cc; |
| 199 | + } |
| 200 | + }; |
| 201 | + } |
| 202 | + |
155 | 203 | }
|
0 commit comments