Closed heyuxiang1996 closed 1 year ago
The field or method are the target of the corresponding JavaAccess
.
You need to look at specific subclasses of this generic class in order to make full sense it:
JavaAccess<TARGET>
├─ JavaFieldAccess extends JavaAccess<FieldAccessTarget>
└─ JavaCodeUnitAccess<T extends CodeUnitAccessTarget> extends JavaAccess<T>
├─ JavaCall<T extends CodeUnitCallTarget> extends JavaCodeUnitAccess<T>
│ ├─ JavaMethodCall extends JavaCall<AccessTarget.MethodCallTarget>
│ └─ JavaConstructorCall extends JavaCall<AccessTarget.ConstructorCallTarget>
└─ JavaCodeUnitReference<T extends CodeUnitReferenceTarget> extends JavaCodeUnitAccess<T>
├─ JavaMethodReference extends JavaCodeUnitReference<MethodReferenceTarget>
└─ JavaConstructorReference extends JavaCodeUnitReference<ConstructorReferenceTarget>
So if you're only interested in method return types or field types:
System.out.println(javaAccess.getDescription());
// Can I obtain the return type or field type in JavaAccess?
// => YES, we can!
if (javaAccess instanceof JavaMethodCall) {
System.out.println("Method return type: " + ((JavaMethodCall) javaAccess).getTarget().getReturnType());
}
if (javaAccess instanceof JavaFieldAccess) {
System.out.println("Field type: " + ((JavaFieldAccess) javaAccess).getTarget().getType());
}
very detailed response I forgot about the inheritance relationship of JavaAccess, Thank you very much!!!
I am making a rule to check if the application calls Google HideApi, This seems to require obtaining more detailed information from JavaAccess Can I obtain the return type or field type in JavaAccess? Examples similar to the following: