Class KlassNavigator<C>

  • Type Parameters:
    C - Variable that represents the type of Class like object in this language.

    public abstract class KlassNavigator<C>
    extends Object
    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
    • Constructor Detail

      • KlassNavigator

        public KlassNavigator()
    • Method Detail

      • getResource

        public abstract URL getResource​(C clazz,
                                        String resourceName)
        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

        public abstract Iterable<Klass<?>> getAncestors​(C clazz)
        Lists up all the ancestor classes, from specific to general, without any duplicate. This is used to look up a resource.
      • getSuperClass

        public abstract Klass<?> getSuperClass​(C clazz)
        Gets the super class.
        Returns:
        Can be null.
      • toJavaClass

        public abstract Class toJavaClass​(C clazz)
        For backward compatibility, map the given class to the closest Java equivalent. In the worst case, this is Object.class
      • getDeclaredMethods

        public abstract List<MethodRef> getDeclaredMethods​(C clazz)
        List methods of this class, regardless of access modifier. This list excludes methods from super classes.
        Since:
        1.220
      • getDeclaredFields

        @NonNull
        public List<FieldRef> getDeclaredFields​(C clazz)
        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

        @NonNull
        public List<Function> getFunctions​(C clazz)
        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

        public boolean isArray​(C clazz)
        If the given type is an array that supports index retrieval.
        See Also:
        getArrayElement(Object, int)
      • isMap

        public boolean isMap​(C clazz)
        If the given type is a map/associative array type that supports lookup by a string key
      • getMapElement

        public Object getMapElement​(Object o,
                                    String key)
        Given an instance for which the type reported isMap()==true, obtains the element of the specified index.