| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
See also the ClassGraph API overview.
Holds information about one method of a class. Obtained by calling ClassInfo#getMethodInfo() and similar methods.
🛑 ClassGraph makes no attempt to resolve type variables in the result types or parameter types of methods. If you need concrete types for a specific type context, you will need to do the type substitution yourself.
💡 Every annotation getter comes in an All form and a Direct form. The All form also includes meta-annotations -- the annotations on the method's own annotations, transitively. The Direct form includes only the annotations written on the method itself.
Holds information about one parameter of a method. Obtained by calling MethodInfo#getParameterInfo().
💡 Method parameter names are only available if you invoked javac with the -parameters switch. In Eclipse this setting is Project Properties > Java Compiler > Store information about method parameters (usable via reflection).
🛑 ClassGraph makes no attempt to resolve type variables in the parameter types of methods. If you need concrete types for a specific type context, you will need to do the type substitution yourself.
If you call ClassGraph#ignoreMethodVisibility() before calling scan(), then non-public methods will be scanned, and MethodInfo objects will be added to the ScanResult for any non-public methods encountered while scanning classes.
Note that ClassGraph differs in its behavior from the Java reflection API. You will notice the following differences in behavior:
Java reflection:
ClassGraph:
This difference in behavior is intended to separate the concerns of whether or not to obtain method info from superclasses from whether or not to return non-public methods, making it simpler with the ClassGraph API to find non-public methods in superclasses, and/or to filter out non-public methods from a given base class, if they are not needed. With the Java reflection API, you cannot get non-public methods from superclasses using Sub.class.getMethods() -- if you do want the non-public methods, you have to iterate up through the superclass hierarchy and call .getDeclaredMethods() on each superclass. Conversely, with the Java reflection API you cannot request only public methods that are declared in a base class but not its superclasses (when calling .getDeclaredMethods()).
With ClassGraph, you can separately decide (1) whether or not to include methods from superclasses (by calling .getDeclaredMethodInfo() if you want only the methods of a class but not its superclasses, or .getMethodInfo() if you want the methods of a class and all of its superclasses), and (2) whether or not to include non-public methods in results (by calling .ignoreMethodVisibility() to enable non-public methods).
To illustrate, given the following classes:
public class Super {
public int publicSuper() { }
private int privateSuper() { }
}
public class Sub extends Super {
public int publicSub() { }
private int privateSub() { }
}The following results are obtained:
Non-declared methods of Super:
| Mechanism | Method call | Result |
|---|---|---|
| Java reflection | Super.class.getMethods() | publicSuper |
| ClassGraph | superClassInfo.getMethodInfo() | publicSuper |
| ClassGraph after .ignoreMethodVisibility() | superClassInfo.getMethodInfo() | publicSuper, privateSuper |
Non-declared methods of Sub:
| Mechanism | Method call | Result |
|---|---|---|
| Java reflection | Sub.class.getMethods() | publicSuper, publicSub |
| ClassGraph | subClassInfo.getMethodInfo() | publicSuper, publicSub |
| ClassGraph after .ignoreMethodVisibility() | subClassInfo.getMethodInfo() | publicSuper, publicSub, privateSuper, privateSub |
Declared methods of Super:
| Mechanism | Method call | Result |
|---|---|---|
| Java reflection | Super.class.getDeclaredMethods() | publicSuper, privateSuper |
| ClassGraph | superClassInfo.getDeclaredMethodInfo() | publicSuper |
| ClassGraph after .ignoreMethodVisibility() | superClassInfo.getDeclaredMethodInfo() | publicSuper, privateSuper |
Declared methods of Sub:
| Mechanism | Method call | Result |
|---|---|---|
| Java reflection | Sub.class.getDeclaredMethods() | publicSub, privateSub |
| ClassGraph | subClassInfo.getDeclaredMethodInfo() | publicSub |
| ClassGraph after .ignoreMethodVisibility() | subClassInfo.getDeclaredMethodInfo() | publicSub, privateSub |
Extends ArrayList<MethodInfo> -- unmodifiable when it came from a scan -- with the following convenience methods:
| Back | FazBrowse Home | New Git URL |