Procházet zdrojové kódy

reflection: interfaces

Ranides Atterwim před 10 roky
rodič
revize
b3937a1664

+ 3 - 3
assira/src/main/java/net/ranides/assira/reflection/IClass.java

@@ -6,7 +6,7 @@
  */
 package net.ranides.assira.reflection;
 
-import net.ranides.assira.reflection.impl.FClass;
+import net.ranides.assira.reflection.impl.IClassFactory;
 
 /**
  * @todo (assira #0) IClass#compareTo dziedziczenie
@@ -20,7 +20,7 @@ public interface IClass extends IElement, Comparable<IClass> {
      * @return 
      */
     static IClass typeinfo(Class<?> type) {
-        return FClass.typeinfo(type);
+        return IClassFactory.typeinfo(type);
     }
     
     /**
@@ -29,7 +29,7 @@ public interface IClass extends IElement, Comparable<IClass> {
      * @return 
      */
     static IClass codeinfo(Class<?> type) {
-        return FClass.codeinfo(type);
+        return IClassFactory.codeinfo(type);
     }
 
     IClass[] params();

+ 3 - 3
assira/src/main/java/net/ranides/assira/reflection/IField.java

@@ -9,7 +9,7 @@ package net.ranides.assira.reflection;
 import java.lang.invoke.MethodHandle;
 import java.lang.reflect.Field;
 import net.ranides.assira.generic.Wrapper;
-import net.ranides.assira.reflection.impl.FField;
+import net.ranides.assira.reflection.impl.IFieldFactory;
 
 /**
  *
@@ -18,11 +18,11 @@ import net.ranides.assira.reflection.impl.FField;
 public interface IField extends IElement {
     
     static IField typeinfo(Field field) {
-        return FField.typeinfo(field);
+        return IFieldFactory.typeinfo(field);
     }
     
     static IField codeinfo(Field field) {
-        return FField.codeinfo(field);
+        return IFieldFactory.codeinfo(field);
     }
     
     @Override

+ 4 - 4
assira/src/main/java/net/ranides/assira/reflection/IMethod.java

@@ -9,7 +9,7 @@ package net.ranides.assira.reflection;
 import java.lang.invoke.MethodHandle;
 import java.lang.reflect.Method;
 import java.util.function.Function;
-import net.ranides.assira.reflection.impl.FMethod;
+import net.ranides.assira.reflection.impl.IMethodFactory;
 
 /**
  * @todo (assira #0) IMethod#compareTo dziedziczenie
@@ -24,7 +24,7 @@ public interface IMethod extends IElement, Comparable<IMethod> {
      * @return 
      */
     static IMethod typeinfo(Method method) {
-        return FMethod.typeinfo(method);
+        return IMethodFactory.typeinfo(method);
     }
     
     /**
@@ -33,7 +33,7 @@ public interface IMethod extends IElement, Comparable<IMethod> {
      * @return 
      */
     static IMethod codeinfo(Method method) {
-        return FMethod.codeinfo(method);
+        return IMethodFactory.codeinfo(method);
     }
     
     /**
@@ -42,7 +42,7 @@ public interface IMethod extends IElement, Comparable<IMethod> {
      * @return 
      */
     static IMethod function(Object object) {
-        return FMethod.function(object);
+        return IMethodFactory.function(object);
     }
     
     @Override

+ 0 - 71
assira/src/main/java/net/ranides/assira/reflection/impl/FMethod.java

@@ -1,71 +0,0 @@
-/*
- * @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.reflect.Method;
-import java.util.Optional;
-import net.ranides.assira.reflection.IMethod;
-
-/**
- *
- * @author Ranides Atterwim <ranides@gmail.com>
- */
-public final class FMethod {
-    
-    private FMethod() {
-        /* 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());
-    }
-}

+ 2 - 2
assira/src/main/java/net/ranides/assira/reflection/impl/FClass.java

@@ -12,9 +12,9 @@ import net.ranides.assira.reflection.IClass;
  *
  * @author Ranides Atterwim <ranides@gmail.com>
  */
-public final class FClass {
+public final class IClassFactory {
     
-    private FClass() {
+    private IClassFactory() {
         /* utility class */
     }
     

+ 2 - 2
assira/src/main/java/net/ranides/assira/reflection/impl/FField.java

@@ -13,9 +13,9 @@ import net.ranides.assira.reflection.IField;
  *
  * @author Ranides Atterwim <ranides@gmail.com>
  */
-public final class FField {
+public final class IFieldFactory {
     
-    private FField() {
+    private IFieldFactory() {
         /* utility class */
     }
     

+ 159 - 0
assira/src/main/java/net/ranides/assira/reflection/impl/IMethodFactory.java

@@ -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.
+        }
+        
+    }
+
+}