Skip to content

Commit

Permalink
Merge pull request #12 from rdegnan/1.x
Browse files Browse the repository at this point in the history
Fix getParameterTypes for groovy:indy versions
  • Loading branch information
abersnaze committed Nov 4, 2015
2 parents 401dcd4 + d85bf32 commit aa15236
Showing 1 changed file with 52 additions and 16 deletions.
68 changes: 52 additions & 16 deletions src/main/java/rx/lang/groovy/RxGroovyExtensionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,39 @@ public Object invoke(Object object, Object[] arguments) {
}
}

@SuppressWarnings("rawtypes")
@Override
public CachedClass[] getParameterTypes() {
Class[] pts = m.getParameterTypes();
CachedClass[] cc = new CachedClass[pts.length];
for (int i = 0; i < pts.length; i++) {
if (Function.class.isAssignableFrom(pts[i])) {
if (parameterTypes == null) {
getParametersTypes0();
}

return parameterTypes;
}

private synchronized void getParametersTypes0() {
if (parameterTypes != null)
return;

Class [] npt = nativeParamTypes == null ? getPT() : nativeParamTypes;

CachedClass[] pt = new CachedClass [npt.length];
for (int i = 0; i != npt.length; ++i) {
if (Function.class.isAssignableFrom(npt[i])) {
// function type to be replaced by closure
cc[i] = ReflectionCache.getCachedClass(Closure.class);
pt[i] = ReflectionCache.getCachedClass(Closure.class);
} else {
// non-function type
cc[i] = ReflectionCache.getCachedClass(pts[i]);
pt[i] = ReflectionCache.getCachedClass(npt[i]);
}
}
return cc;

nativeParamTypes = npt;
setParametersTypes(pt);
}

@Override
protected Class[] getPT() {
return m.getParameterTypes();
}
};
}
Expand Down Expand Up @@ -188,21 +206,39 @@ public Object invoke(Object object, final Object[] arguments) {
return Observable.create(new GroovyCreateWrapper((Closure) arguments[0]));
}

@SuppressWarnings("rawtypes")
@Override
public CachedClass[] getParameterTypes() {
Class[] pts = m.getParameterTypes();
CachedClass[] cc = new CachedClass[pts.length];
for (int i = 0; i < pts.length; i++) {
if (Function.class.isAssignableFrom(pts[i])) {
if (parameterTypes == null) {
getParametersTypes0();
}

return parameterTypes;
}

private synchronized void getParametersTypes0() {
if (parameterTypes != null)
return;

Class [] npt = nativeParamTypes == null ? getPT() : nativeParamTypes;

CachedClass[] pt = new CachedClass [npt.length];
for (int i = 0; i != npt.length; ++i) {
if (Function.class.isAssignableFrom(npt[i])) {
// function type to be replaced by closure
cc[i] = ReflectionCache.getCachedClass(Closure.class);
pt[i] = ReflectionCache.getCachedClass(Closure.class);
} else {
// non-function type
cc[i] = ReflectionCache.getCachedClass(pts[i]);
pt[i] = ReflectionCache.getCachedClass(npt[i]);
}
}
return cc;

nativeParamTypes = npt;
setParametersTypes(pt);
}

@Override
protected Class[] getPT() {
return m.getParameterTypes();
}
};
}
Expand Down

0 comments on commit aa15236

Please sign in to comment.