Ranides Atterwim 10 лет назад
Родитель
Сommit
23a4197eef

+ 10 - 5
assira/src/main/java/net/ranides/assira/reflection/GenericAttribute.java

@@ -56,7 +56,7 @@ public enum GenericAttribute {
 
     PACKAGE         (0x04000000),   // special: !(public | protected | private)
     
-    PARAMETERIZED   (0x10000000),   // special: is generic
+    PARAMETERIZED   (0x10000000),   // special: is generic class
     
     RESOLVED        (0x20000000),   // special: used in GenericClass
     
@@ -85,10 +85,15 @@ public enum GenericAttribute {
         if( 0 == (mask & ACCESS_ANY)) {
             mask |= PACKAGE.mask;
         }
-        if( 0 != ((M_BRIDGE|M_VARARGS) & mask) && (member instanceof Method)) {
-            mask |= (0 != (mask & M_BRIDGE)) ? BRIDGE.mask : 0;
-            mask |= (0 != (mask & M_VARARGS)) ? VARARGS.mask : 0;
-            mask &= ~(M_BRIDGE|M_VARARGS);
+        if(member instanceof Method) {
+            if( 0 != ((M_BRIDGE|M_VARARGS) & mask) ) {
+                mask |= (0 != (mask & M_BRIDGE)) ? BRIDGE.mask : 0;
+                mask |= (0 != (mask & M_VARARGS)) ? VARARGS.mask : 0;
+                mask &= ~(M_BRIDGE|M_VARARGS);
+            }
+            if( 0 != ((Method)member).getTypeParameters().length ) {
+                mask |= PARAMETERIZED.mask;
+            }
         }
         return MAP.valueOf(mask);
     }

+ 19 - 1
assira/src/main/java/net/ranides/assira/reflection/GenericClass.java

@@ -16,8 +16,26 @@ public interface GenericClass extends GenericElement {
     
     GenericFields fields();
     
+    GenericMethods constructors();
+    
     GenericMethods methods();
-
+    
+    GenericClass parent();
+    
+    /**
+     * 
+     * @return implemented interfaces & all parent classes
+     */
+    GenericClasses parents();
+    
+    GenericClass outer();
+    
+    GenericClasses inner();
+    
+    /**
+     * optional
+     * @return 
+     */
     Class<?> reflective();
     
     //java.lang.reflect.Type type();

+ 17 - 0
assira/src/main/java/net/ranides/assira/reflection/GenericClasses.java

@@ -0,0 +1,17 @@
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/assira
+ */
+package net.ranides.assira.reflection;
+
+import java.util.Collection;
+
+/**
+ *
+ * @author Ranides Atterwim <ranides@gmail.com>
+ */
+public interface GenericClasses extends Collection<GenericClass> {
+    
+}

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

@@ -6,6 +6,7 @@
  */
 package net.ranides.assira.reflection;
 
+import java.lang.invoke.MethodHandle;
 import java.lang.reflect.Field;
 import net.ranides.assira.generic.Wrapper;
 
@@ -25,4 +26,6 @@ public interface GenericField extends GenericElement {
     
     Field reflective();
     
+    MethodHandle handle();
+    
 }

+ 14 - 2
assira/src/main/java/net/ranides/assira/reflection/GenericMethod.java

@@ -6,6 +6,8 @@
  */
 package net.ranides.assira.reflection;
 
+import java.lang.invoke.MethodHandle;
+import java.lang.reflect.Method;
 import java.util.function.Function;
 
 /**
@@ -14,12 +16,14 @@ import java.util.function.Function;
  */
 public interface GenericMethod extends GenericElement {
     
+    GenericClass[] params();
+    
     GenericClass returns();
     
     GenericArguments arguments();
     
-    // @todo (assira #1) zrobić klasę MethodCall, parametry in builder-like style
-    
+    GenericClass parent();
+
     Object call();
     
     Object call(Object that);
@@ -27,5 +31,13 @@ public interface GenericMethod extends GenericElement {
     Object call(Object that, Object... arguments);
     
     Function<Object, Object[]> bind(Object that);
+    
+    /**
+     * optional
+     * @return 
+     */
+    Method reflective();
+    
+    MethodHandle handle();
 
 }

+ 26 - 0
assira/src/main/java/net/ranides/assira/reflection/impl/CPReader.java

@@ -0,0 +1,26 @@
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/assira
+ */
+package net.ranides.assira.reflection.impl;
+
+import net.ranides.assira.reflection.GenericClass;
+
+/**
+ *
+ * @author Ranides Atterwim <ranides@gmail.com>
+ */
+public class CPReader {
+
+    public CPReader(Class<?> clazz) {
+        // @todo (assira #0) implement ConstantPool reader
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+    
+    public GenericClass resolve() {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+    
+}

+ 49 - 0
assira/src/main/java/net/ranides/assira/reflection/util/ClassInspector.java

@@ -0,0 +1,49 @@
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/assira
+ */
+package net.ranides.assira.reflection.util;
+
+import net.ranides.assira.reflection.GenericClass;
+import net.ranides.assira.reflection.impl.CPReader;
+
+/**
+ *
+ * @author Ranides Atterwim <ranides@gmail.com>
+ */
+public final class ClassInspector {
+    
+    private ClassInspector() {
+        /* utility class */
+    }
+    
+    /**
+     * Collect information using java.reflection API
+     * @param clazz
+     * @return 
+     */
+    public static GenericClass reflection(Class<?> clazz) {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+    
+    /**
+     * Collect information using ASM bytecode analyzer
+     * @param clazz
+     * @return 
+     */
+    public static GenericClass asm(Class<?> clazz) {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+    
+    /**
+     * Collect information from ConstantPool
+     * @param clazz
+     * @return 
+     */
+    public static GenericClass cp(Class<?> clazz) {
+        return new CPReader(clazz).resolve();
+    }
+    
+}

+ 0 - 2
assira/src/main/java/net/ranides/assira/reflection/util/MethodUtils.java

@@ -17,8 +17,6 @@ import net.ranides.assira.trace.ExceptionUtils;
  */
 public final class MethodUtils {
     
-    // @todo (assira #0) write constant pool inspector
-    
     private MethodUtils() {
         // utility class
     }