|
|
@@ -52,23 +52,12 @@ public final class MethodInspectorVM {
|
|
|
*/
|
|
|
|
|
|
/**
|
|
|
- * Ustala typ zwracany przez przekazaną metodę. W przeciwieństwie do
|
|
|
- * Reflection API, obsługuje również typy generyczne, wykrywając generic parameters.
|
|
|
+ * Ustala typ zwracany przez przekazaną metodę, zwracając w miarę możliwości
|
|
|
+ * szczegółowe informacje o typach generycznych.
|
|
|
* @param method
|
|
|
* @return
|
|
|
*/
|
|
|
- public static GenericClass getReturnType(Method method) {
|
|
|
- return AsmUtils.vm2generic( getVMReturn(method) );
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Ustala typ zwracany przez przekazaną metodę, zwracając w formacie używanym
|
|
|
- * wewnętrznie przez JVM. Zwrócony wynik może być przekazany np do metody
|
|
|
- * {@link AsmUtils#vm2generic}.
|
|
|
- * @param method
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static String getVMReturn(final Method method) {
|
|
|
+ public static GenericClass typeof(final Method method) {
|
|
|
try {
|
|
|
final String smethod = AsmUtils.sig(method);
|
|
|
final Wrapper<String> result = Wrapper.make();
|
|
|
@@ -84,14 +73,18 @@ public final class MethodInspectorVM {
|
|
|
}
|
|
|
},0);
|
|
|
if(null == result.get()) {
|
|
|
- return AsmUtils.class2vm(method.getReturnType());
|
|
|
+ return TypeFactory.construct(method.getReturnType());
|
|
|
} else {
|
|
|
- return result.get().substring(result.get().lastIndexOf(")")+1);
|
|
|
+ return AsmUtils.vm2generic(result.get().substring(result.get().lastIndexOf(")")+1));
|
|
|
}
|
|
|
} catch (IOException cause) {
|
|
|
throw new InspectException(cause);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public static Class<?> typeof(Constructor<?> ctor) {
|
|
|
+ return ctor.getDeclaringClass();
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* Zwraca listę argumentów pobieranych przez metodę. Reflection API pozwala
|
|
|
@@ -101,8 +94,12 @@ public final class MethodInspectorVM {
|
|
|
* @param method
|
|
|
* @return
|
|
|
*/
|
|
|
- public static List<GenericParam> getArguments(Method method) {
|
|
|
- List<GenericParam> list = getVMVariables(method);
|
|
|
+ public static List<GenericParam> params(Method method) {
|
|
|
+ List<GenericParam> list = ivariables(
|
|
|
+ method.getDeclaringClass(),
|
|
|
+ method.getName(),
|
|
|
+ AsmUtils.sig(method)
|
|
|
+ );
|
|
|
if(MemberUtils.isStatic(method)) {
|
|
|
return list.subList(0, method.getParameterTypes().length);
|
|
|
} else {
|
|
|
@@ -110,10 +107,14 @@ public final class MethodInspectorVM {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static List<GenericParam> getArguments(Constructor<?> ctor) {
|
|
|
- return getVMVariables(ctor).subList(1, ctor.getParameterTypes().length+1);
|
|
|
+ public static List<GenericParam> params(Constructor<?> ctor) {
|
|
|
+ List<GenericParam> list = ivariables(
|
|
|
+ ctor.getDeclaringClass(), "<init>",
|
|
|
+ AsmUtils.sig(ctor)
|
|
|
+ );
|
|
|
+ return list.subList(1, ctor.getParameterTypes().length+1);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Zwraca listę zmiennych zdefiniowanych w metodzie. Argumenty funkcji również
|
|
|
* są na poziomie bytecode'u reprezentowane jako zmienne. Kolejność zmiennych
|
|
|
@@ -121,24 +122,29 @@ public final class MethodInspectorVM {
|
|
|
* @param method
|
|
|
* @return
|
|
|
*/
|
|
|
- public static List<GenericParam> getVariables(Method method) {
|
|
|
- List<GenericParam> list = getVMVariables(method);
|
|
|
+ public static List<GenericParam> variables(Method method) {
|
|
|
+ List<GenericParam> list = ivariables(
|
|
|
+ method.getDeclaringClass(),
|
|
|
+ method.getName(),
|
|
|
+ AsmUtils.sig(method)
|
|
|
+ );
|
|
|
if(MemberUtils.isStatic(method)) {
|
|
|
return list.subList(method.getParameterTypes().length, list.size());
|
|
|
} else {
|
|
|
return list.subList(method.getParameterTypes().length+1, list.size());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- public static List<GenericParam> getVMVariables(final Method method) {
|
|
|
- return getVMVariables(method.getDeclaringClass(), method.getName(), AsmUtils.sig(method));
|
|
|
- }
|
|
|
|
|
|
- public static List<GenericParam> getVMVariables(final Constructor<?> ctor) {
|
|
|
- return getVMVariables(ctor.getDeclaringClass(), "<init>", AsmUtils.sig(ctor));
|
|
|
+ public static List<GenericParam> variables(final Constructor<?> ctor) {
|
|
|
+ List<GenericParam> list = ivariables(
|
|
|
+ ctor.getDeclaringClass(),
|
|
|
+ "<init>",
|
|
|
+ AsmUtils.sig(ctor)
|
|
|
+ );
|
|
|
+ return list.subList(ctor.getParameterTypes().length+1, list.size());
|
|
|
}
|
|
|
|
|
|
- private static List<GenericParam> getVMVariables(Class<?> clazz, final String cname, final String sig) {
|
|
|
+ private static List<GenericParam> ivariables(Class<?> clazz, final String cname, final String sig) {
|
|
|
try {
|
|
|
final TreeMap<Integer, VMVariable> variables = new TreeMap<>();
|
|
|
final ClassReader creader = new ClassReader(clazz.getName());
|
|
|
@@ -168,7 +174,7 @@ public final class MethodInspectorVM {
|
|
|
* @param clazz
|
|
|
* @return
|
|
|
*/
|
|
|
- public static List<VMMethod> getVMMethods(final Class<?> clazz) {
|
|
|
+ public static List<VMMethod> methods(final Class<?> clazz) {
|
|
|
// @todo (assira # 3) use that in MethodInspector
|
|
|
// it should be better than reflection #getDeclaredMethods
|
|
|
// it returns parameter names & better generic types
|