Class ClassResolver


  • public class ClassResolver
    extends Object
    Utility class to resolve a class name to an actual class. Note that loaded classes are not initialized.

    Limitations: this does not handle inner classes very well.

    Author:
    Oliver Burn
    • Constructor Detail

      • ClassResolver

        public ClassResolver​(ClassLoader loader,
                             String pkg,
                             Set<String> imports)
        Creates a new ClassResolver instance.
        Parameters:
        loader - the ClassLoader to load classes with.
        pkg - the name of the package the class may belong to
        imports - set of imports to check if the class belongs to
    • Method Detail

      • resolve

        public Class<?> resolve​(String name,
                                String currentClass)
                         throws ClassNotFoundException
        Attempts to resolve the Class for a specified name. The algorithm is to check: - fully qualified name - explicit imports - enclosing package - star imports
        Parameters:
        name - name of the class to resolve
        currentClass - name of current class (for inner classes).
        Returns:
        the resolved class
        Throws:
        ClassNotFoundException - if unable to resolve the class
      • isLoadable

        public boolean isLoadable​(String name)
        Checks if the given class name can be loaded.
        Parameters:
        name - name of the class to check
        Returns:
        whether a specified class is loadable with safeLoad().