|
|
@@ -1,168 +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.Member;
|
|
|
-import java.lang.reflect.Method;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.Set;
|
|
|
-import java.util.function.IntFunction;
|
|
|
-import net.ranides.assira.reflection.GenericAnnotations;
|
|
|
-import net.ranides.assira.reflection.GenericAttribute;
|
|
|
-import net.ranides.assira.reflection.GenericClass;
|
|
|
-import net.ranides.assira.reflection.GenericClasses;
|
|
|
-import net.ranides.assira.reflection.GenericFields;
|
|
|
-import net.ranides.assira.reflection.GenericMethods;
|
|
|
-import net.ranides.assira.reflection.util.MethodUtils;
|
|
|
-import net.ranides.assira.trace.ExceptionUtils;
|
|
|
-import sun.reflect.ConstantPool;
|
|
|
-
|
|
|
-/**
|
|
|
- *
|
|
|
- * @author Ranides Atterwim <ranides@gmail.com>
|
|
|
- */
|
|
|
-public class CPIClass implements GenericClass{
|
|
|
-
|
|
|
- // @todo (assira #0) implement CPIClass (ConstantPool)
|
|
|
-
|
|
|
- // przerobimy to na GenericMethod lambdaType(Object object)
|
|
|
- public static Class<?> lambdaType(Object object) {
|
|
|
- return ilambdaType(object.getClass());
|
|
|
- }
|
|
|
-
|
|
|
- public static Class<?> ilambdaType(Class<?> clazz) {
|
|
|
- if(!clazz.isSynthetic()) {
|
|
|
- throw new IllegalArgumentException(clazz + " is not lambda");
|
|
|
- }
|
|
|
-
|
|
|
- ConstantPool cp = MethodUtils.$invoke(Li.GET_CONSTANT_POOL, clazz);
|
|
|
-
|
|
|
- for(int i=0, n=cp.getSize(); i<n; i++) {
|
|
|
- try {
|
|
|
- Member member = cp.getMethodAt(i);
|
|
|
- if(member instanceof Method) {
|
|
|
- Method method = (Method)member;
|
|
|
-// System.out.printf(" %s%n", method.getReturnType().getSimpleName());
|
|
|
- return method.getReturnType();
|
|
|
- }
|
|
|
- } catch(IllegalArgumentException $0) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- throw new UnsupportedOperationException(clazz + " is unrecognized");
|
|
|
-
|
|
|
-// for(int i=0, n=cp.getSize(); i<n; i++) {
|
|
|
-//// tryprint(i, "class ", cp::getClassAt); // nudne
|
|
|
-// tryprint(i, "field ", cp::getFieldAt);
|
|
|
-//
|
|
|
-//// tryprint(i, "refinfo", cp::getMemberRefInfoAt); // niepotrzebne
|
|
|
-// tryprint(i, "method ", cp::getMethodAt);
|
|
|
-//
|
|
|
-//// tryprint(i, "string", cp::getStringAt); // może wyjebać VM
|
|
|
-//// tryprint(i, "UTF8 ", cp::getUTF8At); // nudne
|
|
|
-//// tryprint(i, "double ", cp::getDoubleAt); // nudne
|
|
|
-//// tryprint(i, "float ", cp::getFloatAt); // nudne
|
|
|
-//// tryprint(i, "int ", cp::getIntAt); // nudne
|
|
|
-//// tryprint(i, "long ", cp::getLongAt); // nudne
|
|
|
-// }
|
|
|
- }
|
|
|
-
|
|
|
- private static void tryprint(int i, String type, IntFunction<Object> function) {
|
|
|
- try {
|
|
|
- Object object = function.apply(i);
|
|
|
- String text = String.valueOf(object);
|
|
|
- if(object instanceof String[]) {
|
|
|
- text = Arrays.toString((String[])object);
|
|
|
- }
|
|
|
- if((object instanceof Member) && !(object instanceof Method)) {
|
|
|
- text = "? " + text;
|
|
|
- }
|
|
|
-
|
|
|
- System.out.printf(" [%d] %s = %s%n", i, type, text);
|
|
|
- } catch(IllegalArgumentException $0) {
|
|
|
- // ignore
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public GenericClass[] params() {
|
|
|
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public GenericFields fields() {
|
|
|
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public GenericMethods constructors() {
|
|
|
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public GenericMethods methods() {
|
|
|
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public GenericClass parent() {
|
|
|
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public GenericClasses parents() {
|
|
|
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public GenericClass outer() {
|
|
|
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public GenericClasses inner() {
|
|
|
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Class<?> reflective() {
|
|
|
- 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<GenericAttribute> attributes() {
|
|
|
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public GenericAnnotations annotations() {
|
|
|
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
|
- }
|
|
|
-
|
|
|
- private static final class Li { // NOPMD - lazy init idiom
|
|
|
-
|
|
|
- public static final Method GET_CONSTANT_POOL;
|
|
|
-
|
|
|
- static {
|
|
|
- try {
|
|
|
- GET_CONSTANT_POOL = Class.class.getDeclaredMethod("getConstantPool");
|
|
|
- GET_CONSTANT_POOL.setAccessible(true);
|
|
|
- } catch(ReflectiveOperationException cause) {
|
|
|
- throw ExceptionUtils.rethrow(cause);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-}
|