Package org.gjt.sp.jedit.bsh.classpath
Class BshClassPath
- java.lang.Object
-
- org.gjt.sp.jedit.bsh.classpath.BshClassPath
-
- All Implemented Interfaces:
ClassPathListener,NameSource
public class BshClassPath extends java.lang.Object implements ClassPathListener, NameSource
A BshClassPath encapsulates knowledge about a class path of URLs. It can maps all classes the path which may include: jar/zip files and base dirs A BshClassPath may composite other BshClassPaths as components of its path and will reflect changes in those components through its methods and listener interface. Classpath traversal is done lazily when a call is made to getClassesForPackage() or getClassSource() or can be done explicitily through insureInitialized(). Feedback on mapping progress is provided through the MappingFeedback interface. Design notes: Several times here we traverse ourselves and our component paths to produce a composite view of some thing relating to the path. This would be an opportunity for a visitor pattern.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBshClassPath.AmbiguousNamestatic classBshClassPath.ClassSourcestatic classBshClassPath.DirClassSourcestatic classBshClassPath.GeneratedClassSourcestatic classBshClassPath.JarClassSourcestatic interfaceBshClassPath.MappingFeedback-
Nested classes/interfaces inherited from interface org.gjt.sp.jedit.bsh.NameSource
NameSource.Listener
-
-
Constructor Summary
Constructors Constructor Description BshClassPath(java.lang.String name)BshClassPath(java.lang.String name, java.net.URL[] urls)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(java.net.URL url)voidadd(java.net.URL[] urls)voidaddComponent(BshClassPath bcp)Add the specified BshClassPath as a component of our path.voidaddListener(ClassPathListener l)static voidaddMappingFeedback(BshClassPath.MappingFeedback mf)voidaddNameSourceListener(NameSource.Listener listener)Implements NameSource Add a listener who is notified upon changes to names in this space.static java.lang.StringcanonicalizeClassName(java.lang.String name)Create a proper class name from a messy thing.voidclassPathChanged()java.lang.String[]getAllNames()static BshClassPathgetBootClassPath()Get the boot path including the lib/rt.jar if possible.java.util.SetgetClassesForPackage(java.lang.String pack)Return the set of class names in the specified package including all component paths.java.lang.StringgetClassNameByUnqName(java.lang.String name)Support for super import "*"; Get the full name associated with the unqualified name in this classpath.BshClassPath.ClassSourcegetClassSource(java.lang.String className)Return the source of the specified class which may lie in component path.protected java.util.ListgetFullPath()Get the full path including component paths.java.util.SetgetPackagesSet()Get a list of all of the known packagesjava.net.URL[]getPathComponents()Get the path components including any component paths.static BshClassPathgetUserClassPath()A BshClassPath initialized to the user path from java.class.pathstatic java.net.URL[]getUserClassPathComponents()voidinsureInitialized()If the claspath map is not initialized, do it now.protected voidinsureInitialized(boolean topPath)static booleanisArchiveFileName(java.lang.String name)static booleanisClassFileName(java.lang.String name)static voidmain(java.lang.String[] args)static java.util.CollectionremoveInnerClassNames(java.util.Collection col)Return a new collection without any inner class namesvoidremoveListener(ClassPathListener l)voidsetClassSource(java.lang.String className, BshClassPath.ClassSource cs)Explicitly set a class source.voidsetPath(java.net.URL[] urls)static java.lang.String[]splitClassname(java.lang.String classname)Split class name into package and namejava.lang.StringtoString()
-
-
-
Method Detail
-
setPath
public void setPath(java.net.URL[] urls)
-
addComponent
public void addComponent(BshClassPath bcp)
Add the specified BshClassPath as a component of our path. Changes in the bcp will be reflected through us.
-
add
public void add(java.net.URL[] urls)
-
add
public void add(java.net.URL url) throws java.io.IOException- Throws:
java.io.IOException
-
getPathComponents
public java.net.URL[] getPathComponents()
Get the path components including any component paths.
-
getClassesForPackage
public java.util.Set getClassesForPackage(java.lang.String pack)
Return the set of class names in the specified package including all component paths.
-
getClassSource
public BshClassPath.ClassSource getClassSource(java.lang.String className)
Return the source of the specified class which may lie in component path.
-
setClassSource
public void setClassSource(java.lang.String className, BshClassPath.ClassSource cs)Explicitly set a class source. This is used for generated classes, but could potentially be used to allow a user to override which version of a class from the classpath is located.
-
insureInitialized
public void insureInitialized()
If the claspath map is not initialized, do it now. If component maps are not do them as well... Random note: Should this be "insure" or "ensure". I know I've seen "ensure" used in the JDK source. Here's what Webster has to say: Main Entry:ensure Pronunciation:in-'shur Function:transitive verb Inflected Form(s):ensured; ensuring : to make sure, certain, or safe : GUARANTEE synonyms ENSURE, INSURE, ASSURE, SECURE mean to make a thing or person sure. ENSURE, INSURE, and ASSURE are interchangeable in many contexts where they indicate the making certain or inevitable of an outcome, but INSURE sometimes stresses the taking of necessary measures beforehand, and ASSURE distinctively implies the removal of doubt and suspense from a person's mind. SECURE implies action taken to guard against attack or loss.
-
insureInitialized
protected void insureInitialized(boolean topPath)
- Parameters:
topPath- indicates that this is the top level classpath component and it should send the startClassMapping message
-
getFullPath
protected java.util.List getFullPath()
Get the full path including component paths. (component paths listed first, in order) Duplicate path components are removed.
-
getClassNameByUnqName
public java.lang.String getClassNameByUnqName(java.lang.String name) throws ClassPathExceptionSupport for super import "*"; Get the full name associated with the unqualified name in this classpath. Returns either the String name or an AmbiguousName object encapsulating the various names.- Throws:
ClassPathException
-
getAllNames
public java.lang.String[] getAllNames()
- Specified by:
getAllNamesin interfaceNameSource
-
classPathChanged
public void classPathChanged()
- Specified by:
classPathChangedin interfaceClassPathListener
-
isClassFileName
public static boolean isClassFileName(java.lang.String name)
-
isArchiveFileName
public static boolean isArchiveFileName(java.lang.String name)
-
canonicalizeClassName
public static java.lang.String canonicalizeClassName(java.lang.String name)
Create a proper class name from a messy thing. Turn / or \ into ., remove leading class and trailing .class Note: this makes lots of strings... could be faster.
-
splitClassname
public static java.lang.String[] splitClassname(java.lang.String classname)
Split class name into package and name
-
removeInnerClassNames
public static java.util.Collection removeInnerClassNames(java.util.Collection col)
Return a new collection without any inner class names
-
getUserClassPathComponents
public static java.net.URL[] getUserClassPathComponents() throws ClassPathException- Throws:
ClassPathException
-
getPackagesSet
public java.util.Set getPackagesSet()
Get a list of all of the known packages
-
addListener
public void addListener(ClassPathListener l)
-
removeListener
public void removeListener(ClassPathListener l)
-
getUserClassPath
public static BshClassPath getUserClassPath() throws ClassPathException
A BshClassPath initialized to the user path from java.class.path- Throws:
ClassPathException
-
getBootClassPath
public static BshClassPath getBootClassPath() throws ClassPathException
Get the boot path including the lib/rt.jar if possible.- Throws:
ClassPathException
-
main
public static void main(java.lang.String[] args) throws java.lang.Exception- Throws:
java.lang.Exception
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
addNameSourceListener
public void addNameSourceListener(NameSource.Listener listener)
Implements NameSource Add a listener who is notified upon changes to names in this space.- Specified by:
addNameSourceListenerin interfaceNameSource
-
addMappingFeedback
public static void addMappingFeedback(BshClassPath.MappingFeedback mf)
-
-