-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
722 additions
and
631 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package sci.impl; | ||
|
||
import clojure.lang.RT; | ||
import clojure.lang.IPersistentSet; | ||
import java.util.concurrent.Callable; | ||
import java.lang.reflect.Modifier; | ||
import java.util.Comparator; | ||
|
||
class FISupport { | ||
private static final IPersistentSet AFN_FIS = RT.set(Callable.class, Runnable.class, Comparator.class); | ||
private static final IPersistentSet OBJECT_METHODS = RT.set("equals", "toString", "hashCode"); | ||
|
||
// Return FI method if: | ||
// 1) Target is a functional interface and not already implemented by AFn | ||
// 2) Target method matches one of our fn invoker methods (0 <= arity <= 10) | ||
protected static java.lang.reflect.Method maybeFIMethod(Class target) { | ||
if (target != null && target.isAnnotationPresent(FunctionalInterface.class) | ||
&& !AFN_FIS.contains(target)) { | ||
|
||
java.lang.reflect.Method[] methods = target.getMethods(); | ||
for (java.lang.reflect.Method method : methods) { | ||
if (method.getParameterCount() >= 0 && method.getParameterCount() <= 10 | ||
&& Modifier.isAbstract(method.getModifiers()) | ||
&& !OBJECT_METHODS.contains(method.getName())) | ||
return method; | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.