Skip to content

Commit d95439f

Browse files
committed
Merge pull request #5 from benjchristensen/language-adaptor-classes
Support multiple class types for language adaptors
2 parents b66c0d3 + 686fa1f commit d95439f

File tree

5 files changed

+29
-24
lines changed

5 files changed

+29
-24
lines changed

language-adaptors/rxjava-clojure/src/main/java/org/rx/lang/clojure/ClojureAdaptor.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package org.rx.lang.clojure;
1717

18-
import static org.mockito.Mockito.*;
19-
2018
import java.util.Arrays;
2119

2220
import org.junit.Before;
@@ -82,8 +80,8 @@ public Object call(Object function, Object[] args) {
8280
}
8381

8482
@Override
85-
public Class<?> getFunctionClass() {
86-
return IFn.class;
83+
public Class<?>[] getFunctionClass() {
84+
return new Class<?>[] { IFn.class };
8785
}
8886

8987
public static class UnitTest {

language-adaptors/rxjava-groovy/src/main/java/org/rx/lang/groovy/GroovyAdaptor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2013 Netflix, Inc.
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -41,8 +41,8 @@ public Object call(Object function, Object[] args) {
4141
return ((Closure<?>) function).call(args);
4242
}
4343

44-
public Class<?> getFunctionClass() {
45-
return Closure.class;
44+
public Class<?>[] getFunctionClass() {
45+
return new Class<?>[] { Closure.class };
4646
}
4747

4848
public static class UnitTest {

language-adaptors/rxjava-jruby/src/main/java/org/rx/lang/jruby/JRubyAdaptor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2013 Netflix, Inc.
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -49,8 +49,8 @@ public Object call(Object function, Object[] args) {
4949
}
5050

5151
@Override
52-
public Class<?> getFunctionClass() {
53-
return RubyProc.class;
52+
public Class<?>[] getFunctionClass() {
53+
return new Class<?>[] { RubyProc.class };
5454
}
5555

5656
public static class UnitTest {

rxjava-core/src/main/java/org/rx/functions/FunctionLanguageAdaptor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ public interface FunctionLanguageAdaptor {
3030
* The Class of the Function that this adaptor serves.
3131
* <p>
3232
* Example: groovy.lang.Closure
33+
* <p>
34+
* This should not return classes of java.* packages.
3335
*
34-
* @return Class
36+
* @return Class[] of classes that this adaptor should be invoked for.
3537
*/
36-
public Class<?> getFunctionClass();
38+
public Class<?>[] getFunctionClass();
3739
}

rxjava-core/src/main/java/org/rx/functions/Functions.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2013 Netflix, Inc.
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -56,8 +56,13 @@ private static void loadLanguageAdaptor(String name) {
5656
}
5757
}
5858

59-
public static void registerLanguageAdaptor(Class<?> functionClass, FunctionLanguageAdaptor adaptor) {
60-
languageAdaptors.put(functionClass, adaptor);
59+
public static void registerLanguageAdaptor(Class<?>[] functionClasses, FunctionLanguageAdaptor adaptor) {
60+
for (Class<?> functionClass : functionClasses) {
61+
if (functionClass.getPackage().getName().startsWith("java.")) {
62+
throw new IllegalArgumentException("FunctionLanguageAdaptor implementations can not specify java.lang.* classes.");
63+
}
64+
languageAdaptors.put(functionClass, adaptor);
65+
}
6166
}
6267

6368
public static void removeLanguageAdaptor(Class<?> functionClass) {

0 commit comments

Comments
 (0)