Package org.kohsuke.stapler.lang
Class KlassNavigator<C>
java.lang.Object
org.kohsuke.stapler.lang.KlassNavigator<C>
- Type Parameters:
C
- Variable that represents the type ofClass
like object in this language.
Strategy pattern to provide navigation across class-like objects in other languages of JVM.
After removal of JRuby support, JAVA
is the only implementation.
Implementations should be stateless and typically a singleton.
- Author:
- Kohsuke Kawaguchi
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetAncestors
(C clazz) Lists up all the ancestor classes, from specific to general, without any duplicate.getArrayElement
(Object o, int index) Given an instance for which the type reportedisArray()==true
, obtains the element of the specified index.getDeclaredFields
(C clazz) List fields of this class.getDeclaredMethods
(C clazz) List methods of this class, regardless of access modifier.getFunctions
(C clazz) Reports all the methods that can be used for routing requests on this class.getMapElement
(Object o, String key) Given an instance for which the type reportedisMap()==true
, obtains the element of the specified index.abstract URL
getResource
(C clazz, String resourceName) Loads the resources associated with this class.abstract Klass<?>
getSuperClass
(C clazz) Gets the super class.boolean
If the given type is an array that supports index retrieval.boolean
If the given type is a map/associative array type that supports lookup by a string keyabstract Class
toJavaClass
(C clazz) For backward compatibility, map the given class to the closest Java equivalent.
-
Field Details
-
JAVA
-
-
Constructor Details
-
KlassNavigator
public KlassNavigator()
-
-
Method Details
-
getResource
Loads the resources associated with this class.In stapler, the convention is that the "associated" resources live in the directory named after the fully qualified class name (as opposed to the behavior of
Class.getResource(String)
, that looks for resources in the same package as the class.)But other languages can choose their own conventions if it makes more sense to do so. For example, stapler-jruby uses camelized class name.
Implementation must consult
MetaClassLoader.debugLoader
if it's available. Implementation must not look for resources in the base type. That operation is performed by the caller when needed.- Returns:
- non-null if the resource is found. Otherwise null.
-
getAncestors
Lists up all the ancestor classes, from specific to general, without any duplicate. This is used to look up a resource. -
getSuperClass
Gets the super class.- Returns:
- Can be null.
-
toJavaClass
For backward compatibility, map the given class to the closest Java equivalent. In the worst case, this is Object.class -
getDeclaredMethods
List methods of this class, regardless of access modifier. This list excludes methods from super classes.- Since:
- 1.220
-
getDeclaredFields
List fields of this class. This list excludes fields from super classes.- Parameters:
clazz
- Class- Returns:
- List of the fields declared for the class.
By default this list is empty,
KlassNavigator
implementations are responsible to implement it. - Since:
- 1.246
-
getFunctions
Reports all the methods that can be used for routing requests on this class.- Parameters:
clazz
- Class- Returns:
- List of the fields functions declared for the class.
By default this list is empty,
KlassNavigator
implementations are responsible to implement it. - Since:
- 1.246
-
isArray
If the given type is an array that supports index retrieval.- See Also:
-
getArrayElement
Given an instance for which the type reportedisArray()==true
, obtains the element of the specified index.- Throws:
IndexOutOfBoundsException
- See Also:
-
isMap
If the given type is a map/associative array type that supports lookup by a string key -
getMapElement
Given an instance for which the type reportedisMap()==true
, obtains the element of the specified index.
-