|
|
@@ -33,20 +33,18 @@ public final class CPInspector {
|
|
|
* @return all methods referenced in class' bytecode
|
|
|
*/
|
|
|
public static Stream<Method> getMethods(Class<?> clazz) {
|
|
|
- throw new UnsupportedOperationException("JDK11");
|
|
|
-// CPP cp = new CPP(clazz);
|
|
|
-// return StreamSupport.stream(new CPSpliterator<>(cp.v.getSize(), cp.v::getMethodAt), false)
|
|
|
-// .filter(m -> m instanceof Method)
|
|
|
-// .map(m -> (Method)m);
|
|
|
+ CPP cp = new CPP(clazz);
|
|
|
+ return StreamSupport.stream(new CPSpliterator<>(cp.v.getSize(), cp.v::getMethodAt), false)
|
|
|
+ .filter(m -> m instanceof Method)
|
|
|
+ .map(m -> (Method)m);
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public static <T> Stream<Constructor<T>> getConstructors(Class<T> clazz) {
|
|
|
- throw new UnsupportedOperationException("JDK11");
|
|
|
-// CPP cp = new CPP(clazz);
|
|
|
-// return StreamSupport.stream(new CPSpliterator<>(cp.v.getSize(), cp.v::getMethodAt), false)
|
|
|
-// .filter(m -> m instanceof Constructor<?>)
|
|
|
-// .map(m -> (Constructor<T>)m);
|
|
|
+ CPP cp = new CPP(clazz);
|
|
|
+ return StreamSupport.stream(new CPSpliterator<>(cp.v.getSize(), cp.v::getMethodAt), false)
|
|
|
+ .filter(m -> m instanceof Constructor<?>)
|
|
|
+ .map(m -> (Constructor<T>)m);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -55,9 +53,8 @@ public final class CPInspector {
|
|
|
* @return fields referenced in class' bytecode
|
|
|
*/
|
|
|
public static Stream<Field> getFields(Class<?> clazz) {
|
|
|
- throw new UnsupportedOperationException("JDK11");
|
|
|
-// CPP cp = new CPP(clazz);
|
|
|
-// return StreamSupport.stream(new CPSpliterator<>(cp.v.getSize(), cp.v::getFieldAt), false);
|
|
|
+ CPP cp = new CPP(clazz);
|
|
|
+ return StreamSupport.stream(new CPSpliterator<>(cp.v.getSize(), cp.v::getFieldAt), false);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -66,9 +63,8 @@ public final class CPInspector {
|
|
|
* @return types referenced in class' bytecode
|
|
|
*/
|
|
|
public static Stream<Class<?>> getClasses(Class<?> clazz) {
|
|
|
- throw new UnsupportedOperationException("JDK11");
|
|
|
-// CPP cp = new CPP(clazz);
|
|
|
-// return StreamSupport.stream(new CPSpliterator<>(cp.v.getSize(), cp.v::getClassAt), false);
|
|
|
+ CPP cp = new CPP(clazz);
|
|
|
+ return StreamSupport.stream(new CPSpliterator<>(cp.v.getSize(), cp.v::getClassAt), false);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -77,64 +73,63 @@ public final class CPInspector {
|
|
|
* @return string constants referenced in class' bytecode
|
|
|
*/
|
|
|
public static Stream<String> getStrings(Class<?> clazz) {
|
|
|
- throw new UnsupportedOperationException("JDK11");
|
|
|
-// CPP cp = new CPP(clazz);
|
|
|
-// return StreamSupport.stream(new CPSpliterator<>(cp.v.getSize(), cp.v::getUTF8At), false);
|
|
|
+ CPP cp = new CPP(clazz);
|
|
|
+ return StreamSupport.stream(new CPSpliterator<>(cp.v.getSize(), cp.v::getUTF8At), false);
|
|
|
}
|
|
|
|
|
|
-// private static final class CPSpliterator<T> extends ForwardSpliterator<T> {
|
|
|
-//
|
|
|
-// private final IntFunction<T> function;
|
|
|
-// private final int max;
|
|
|
-// private int index;
|
|
|
-//
|
|
|
-//
|
|
|
-// public CPSpliterator(int size, IntFunction<T> function) {
|
|
|
-// this.function = function;
|
|
|
-// this.max = size;
|
|
|
-// this.index = 0;
|
|
|
-// }
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// public boolean tryAdvance(Consumer<? super T> action) {
|
|
|
-// while(index<max) {
|
|
|
-// try {
|
|
|
-// action.accept(function.apply(index++));
|
|
|
-// return true;
|
|
|
-// } catch(IllegalArgumentException $0) { // NOPMD
|
|
|
-// // do nothing
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return false;
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
-//
|
|
|
-// 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);
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
-//
|
|
|
-// // Cały cyrk z tym wrapperem tylko po to, aby nie mieć 20 warningów z powodu użycia klasy "sun.reflect".
|
|
|
-// // Mamy jedno użycie (tutaj). A reszta kodu używa typu niejawnie, używając pola "v"
|
|
|
-// private static final class CPP {
|
|
|
-//
|
|
|
-// public final sun.reflect.ConstantPool v;
|
|
|
-//
|
|
|
-// public CPP(Class<?> clazz) {
|
|
|
-// this.v = MethodUtils.$invoke(Li.GET_CONSTANT_POOL, clazz);
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
+ private static final class CPSpliterator<T> extends ForwardSpliterator<T> {
|
|
|
+
|
|
|
+ private final IntFunction<T> function;
|
|
|
+ private final int max;
|
|
|
+ private int index;
|
|
|
+
|
|
|
+
|
|
|
+ public CPSpliterator(int size, IntFunction<T> function) {
|
|
|
+ this.function = function;
|
|
|
+ this.max = size;
|
|
|
+ this.index = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean tryAdvance(Consumer<? super T> action) {
|
|
|
+ while(index<max) {
|
|
|
+ try {
|
|
|
+ action.accept(function.apply(index++));
|
|
|
+ return true;
|
|
|
+ } catch(IllegalArgumentException $0) { // NOPMD
|
|
|
+ // do nothing
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // Cały cyrk z tym wrapperem tylko po to, aby nie mieć 20 warningów z powodu użycia klasy "sun.reflect".
|
|
|
+ // Mamy jedno użycie (tutaj). A reszta kodu używa typu niejawnie, używając pola "v"
|
|
|
+ private static final class CPP {
|
|
|
+
|
|
|
+ public final jdk.internal.reflect.ConstantPool v;
|
|
|
+
|
|
|
+ public CPP(Class<?> clazz) {
|
|
|
+ this.v = MethodUtils.$invoke(Li.GET_CONSTANT_POOL, clazz);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|