|
|
@@ -0,0 +1,159 @@
|
|
|
+/*
|
|
|
+ * @author Ranides Atterwim <ranides@gmail.com>
|
|
|
+ * @copyright Ranides Atterwim
|
|
|
+ * @license WTFPL
|
|
|
+ * @url http://ranides.net/projects/assira
|
|
|
+ */
|
|
|
+package net.ranides.assira.reflection.impl;
|
|
|
+
|
|
|
+import java.lang.invoke.MethodHandle;
|
|
|
+import java.lang.reflect.Method;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.function.Function;
|
|
|
+import net.ranides.assira.reflection.IAnnotations;
|
|
|
+import net.ranides.assira.reflection.IArguments;
|
|
|
+import net.ranides.assira.reflection.IAttribute;
|
|
|
+import net.ranides.assira.reflection.IClass;
|
|
|
+import net.ranides.assira.reflection.IMethod;
|
|
|
+import net.ranides.assira.reflection.IMethods;
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @author Ranides Atterwim <ranides@gmail.com>
|
|
|
+ */
|
|
|
+public final class IMethodFactory {
|
|
|
+
|
|
|
+ private IMethodFactory() {
|
|
|
+ /* utility class */
|
|
|
+ }
|
|
|
+
|
|
|
+ public static IMethod typeinfo(Method method) {
|
|
|
+ throw new UnsupportedOperationException("Not supported yet.");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static IMethod codeinfo(Method method) {
|
|
|
+ throw new UnsupportedOperationException("Not supported yet.");
|
|
|
+ }
|
|
|
+
|
|
|
+ public static IMethod function(Object object) {
|
|
|
+ // @todo (assira #0) functional interfaces
|
|
|
+ // FI can be detected, because it has only one method.
|
|
|
+ // simple:
|
|
|
+ // 1. get implemented interfaces (must be more than 1)
|
|
|
+ // 3. select all methods from that interfaces
|
|
|
+ // 4. select "unique" by signature (should be exactly 1 method)
|
|
|
+ // 5. select method with that signature from "object"
|
|
|
+ // 6. return it
|
|
|
+ //
|
|
|
+ // something like
|
|
|
+ //
|
|
|
+ // IClasses ic = ClassInspector.reflective()
|
|
|
+ // ASSERT Object.class == ic.parent().reflective()
|
|
|
+ // ASSERT ! ic.attributes.contains(IAttribute.ABSTRACT)
|
|
|
+ //
|
|
|
+ // Set<IMethod> sm = ic
|
|
|
+ // .interfaces()
|
|
|
+ // .methods()
|
|
|
+ // .require(IAttribute.ABSTRACT)
|
|
|
+ // .collect(Collectors.toSet()) // it should work because IMethod#equals is smart
|
|
|
+ //
|
|
|
+ // ASSERT sm.size() == 1
|
|
|
+ // return ic
|
|
|
+ // .methods()
|
|
|
+ // .params( sm.iterator().next().params() )
|
|
|
+ // .first()
|
|
|
+ //
|
|
|
+ //
|
|
|
+
|
|
|
+ Class<?> type = object.getClass();
|
|
|
+ if(!type.isSynthetic()) {
|
|
|
+ throw new IllegalArgumentException(type + " is not lambda");
|
|
|
+ }
|
|
|
+ Optional<Method> method = CPInspector.getMethods(type).findFirst();
|
|
|
+ if( !method.isPresent() ) {
|
|
|
+ throw new IllegalArgumentException(type + " is not lambda");
|
|
|
+ }
|
|
|
+ return codeinfo(method.get());
|
|
|
+ }
|
|
|
+
|
|
|
+ private static class RFMethod implements IMethod {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IMethods asList() {
|
|
|
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IClass[] params() {
|
|
|
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IClass returns() {
|
|
|
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IArguments arguments() {
|
|
|
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IClass parent() {
|
|
|
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object call() {
|
|
|
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object call(Object that) {
|
|
|
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object call(Object that, Object... arguments) {
|
|
|
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Function<Object, Object[]> bind(Object that) {
|
|
|
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Method reflective() {
|
|
|
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MethodHandle handle() {
|
|
|
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String name() {
|
|
|
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Set<IAttribute> attributes() {
|
|
|
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IAnnotations annotations() {
|
|
|
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int compareTo(IMethod o) {
|
|
|
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|