JML

org.multijava.util.classfile
Class ClassPath

java.lang.Object
  extended byorg.multijava.util.classfile.ClassPath

public class ClassPath
extends Object

This class implements the conceptual directory structure for .class files


Nested Class Summary
static class ClassPath.ClassDescription
          A File value used to indicate an undefined result.
static class ClassPath.Data
          This class mimics a DataInput, but optimizes the reading of the supplied InputStream.
static class ClassPath.FileClassDescription
           
 
Field Summary
private static HashMap allLoadedFile
           
private static HashMap allLocatedSourceFiles
           
private static String bootclasspath
          Holder for the user set boot class path; if null, the system value of the boot class path is used.
private  ClassDirectory[] dirs
           
private static String finalclasspath
          Holder for the combined classpath and bootclasspath.
private static String[] javasuffix
          Returns a ClassDescription for the java file containing the class with the given name; returns null if can't be found.
private static String lastClassPath
          The classPath argument that was used to construct self.
private static String lastSourcePath
          The sourcePath argument that was used to construct self.
private static ClassPath.ClassDescription NO_CLASS_DESC
          A ClassDescription value used to indicate that the is no file and no class description available.
private static ClassPath self
          A reference to the singleton instance of this class.
private  ClassDirectory[] sourceDirs
           
 
Constructor Summary
private ClassPath(String classPath, String sourcePath)
          Constructs the class path.
 
Method Summary
static String classPath()
          Returns the combined classpath and bootclasspath.
static String findPackage(String name)
          Returns the root directory (on the CLASSPATH) in which the given package can be found.
private  String findPackageLocation(String name)
          Returns a String indicating the location of a package.
static String findPackageSource(String name)
          Returns the root directory in the sourcepath in which the given '.' separated package is found, or null if the package cannot be found.
private  String findPackageSourceLocation(String name)
          Returns the root directory in the sourcepath in which the given '.' separated package is found.
private  ClassPath.ClassDescription findSourceFile(String name, String[] suffixes)
          This function returns the first file found that has one of the given suffixes and is in the sourceDirs directory path.
private  ClassPath.ClassDescription getClassFile(String name, String suffix)
          Returns a class file but don't read it or cache it.
static ClassInfo getClassInfo(String name, boolean interfaceOnly)
          Creates a class info object by reading bytecode from the file named name.class.
static ClassInfo getClassInfo(String name, String suffix, ClassInfoCreator creator, boolean markNotFound, boolean interfaceOnly)
          Creates a class info object by reading bytecode from the file named name.suffix.
static ClassPath.ClassDescription getClassPathFile(String name)
          Returns a ClassDescription for the class file containing the class with the given name (searching each directory on the classpath in turn); returns null if can't be found.
static ClassPath.ClassDescription getClassPathFile(String name, String suffix)
           
static ClassPath.ClassDescription getFile(String name, String suffix)
          Returns a ClassDescription for the file with the given name+suffix; returns null if can't be found.
static ClassPath.ClassDescription getJavaFile(String name)
           
static ClassPath.ClassDescription getSourceFile(String name, String[] suffixes)
          Returns a ClassDescription for the source file containing the class with the given name and one of the given suffixes (searching for any suffix in each directory on the sourcepath in turn); returns null if can't be found.
static void init(String classPath, String sourcePath)
          Initialization from strings that represents the class path and the source path (if sourcePath is null, classPath is used for both files searches).
static void initSession()
          Prepares for a new compilation session by forgetting the locations of known files (since the CLASSPATH and SOURCEPATH may be different for the new session).
static ClassDirectory[] parseClassPath(String classPath)
           
static void setBootClassPath(String b)
          Sets the boot classpath (in palce of the default, which is the system classpath.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

javasuffix

private static String[] javasuffix
Returns a ClassDescription for the java file containing the class with the given name; returns null if can't be found.


self

private static ClassPath self
A reference to the singleton instance of this class.


lastClassPath

private static String lastClassPath
The classPath argument that was used to construct self. Stored to avoid instantiating a new singleton when it would have the same state as the old one.


lastSourcePath

private static String lastSourcePath
The sourcePath argument that was used to construct self. Stored to avoid instantiating a new singleton when it would have the same state as the old one.


allLoadedFile

private static HashMap allLoadedFile

allLocatedSourceFiles

private static HashMap allLocatedSourceFiles

dirs

private ClassDirectory[] dirs

sourceDirs

private ClassDirectory[] sourceDirs

NO_CLASS_DESC

private static ClassPath.ClassDescription NO_CLASS_DESC
A ClassDescription value used to indicate that the is no file and no class description available.


bootclasspath

private static String bootclasspath
Holder for the user set boot class path; if null, the system value of the boot class path is used.


finalclasspath

private static String finalclasspath
Holder for the combined classpath and bootclasspath.

Constructor Detail

ClassPath

private ClassPath(String classPath,
                  String sourcePath)
Constructs the class path. Private since this is a singleton.

Method Detail

parseClassPath

public static ClassDirectory[] parseClassPath(String classPath)

init

public static void init(String classPath,
                        String sourcePath)
Initialization from strings that represents the class path and the source path (if sourcePath is null, classPath is used for both files searches).

Parameters:
classPath - the classpath (used for finding .class files)
sourcePath - the sourcepath (used for finding .java and other source files)

setBootClassPath

public static void setBootClassPath(String b)
Sets the boot classpath (in palce of the default, which is the system classpath. This is appended to the classpath.


classPath

public static String classPath()
Returns the combined classpath and bootclasspath.


getJavaFile

public static ClassPath.ClassDescription getJavaFile(String name)

getSourceFile

public static ClassPath.ClassDescription getSourceFile(String name,
                                                       String[] suffixes)
Returns a ClassDescription for the source file containing the class with the given name and one of the given suffixes (searching for any suffix in each directory on the sourcepath in turn); returns null if can't be found. This is a helper function intended for use in subclasses of FileFinder.


getFile

public static ClassPath.ClassDescription getFile(String name,
                                                 String suffix)
Returns a ClassDescription for the file with the given name+suffix; returns null if can't be found. This is a method intended for use when searching the class path for a file with a specific suffix.


getClassPathFile

public static ClassPath.ClassDescription getClassPathFile(String name)
Returns a ClassDescription for the class file containing the class with the given name (searching each directory on the classpath in turn); returns null if can't be found. This is a helper function intended for use in subclasses of FileFinder.


getClassPathFile

public static ClassPath.ClassDescription getClassPathFile(String name,
                                                          String suffix)

getClassInfo

public static ClassInfo getClassInfo(String name,
                                     boolean interfaceOnly)
                              throws ClassFileReadException
Creates a class info object by reading bytecode from the file named name.class.

Parameters:
name - the name of the class
interfaceOnly - read the signature, but not the code, of the class if true
Returns:
the content of a class file that contains the class named name (null if no such class)
Throws:
ClassFileReadException - if the class file is malformed or an I/O error occurs

getClassInfo

public static ClassInfo getClassInfo(String name,
                                     String suffix,
                                     ClassInfoCreator creator,
                                     boolean markNotFound,
                                     boolean interfaceOnly)
                              throws ClassFileReadException
Creates a class info object by reading bytecode from the file named name.suffix. If the argument creator is not null, use it to create a class info object; otherwise creates an instance of the class ClassInfo.

Parameters:
name - the name of the class
suffix - the file suffix to look for
creator - a factory, or null
markNotFound - if true, then track files already checked
interfaceOnly - read the signature, but not the code, of the class if true
Returns:
the content of a class file that contains the class named name (null if no such class)
Throws:
ClassFileReadException - if the class file is malformed or an I/O error occurs

findPackage

public static String findPackage(String name)
Returns the root directory (on the CLASSPATH) in which the given package can be found. The package name is '.' separated. Returns null if the package is not found as a directory on the on the CLASSPATH + BOOTCLASSPATH. (The package could still exist in a jar.)


findPackageSource

public static String findPackageSource(String name)
Returns the root directory in the sourcepath in which the given '.' separated package is found, or null if the package cannot be found. (Though, the package could still exist in a jar.)


findPackageLocation

private String findPackageLocation(String name)
Returns a String indicating the location of a package. The argment is a '.'-separated fully-qualified package name. For a normal directory-type package, the result is the path to the package root, or null if the package cannot be found.


findPackageSourceLocation

private String findPackageSourceLocation(String name)
Returns the root directory in the sourcepath in which the given '.' separated package is found.


getClassFile

private ClassPath.ClassDescription getClassFile(String name,
                                                String suffix)
Returns a class file but don't read it or cache it. Returns null if can't be found.


findSourceFile

private ClassPath.ClassDescription findSourceFile(String name,
                                                  String[] suffixes)
This function returns the first file found that has one of the given suffixes and is in the sourceDirs directory path. Each directory is searched in turn; within each directory, each suffix is sought, in order; if none are present searching proceeds with the next directory. Returns null if the name cannot be found with one of the suffixes.


initSession

public static void initSession()
Prepares for a new compilation session by forgetting the locations of known files (since the CLASSPATH and SOURCEPATH may be different for the new session).


JML

JML is Copyright (C) 1998-2002 by Iowa State University and is distributed under the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This release depends on code from the MultiJava project and is based in part on the Kopi project Copyright (C) 1990-99 DMS Decision Management Systems Ges.m.b.H.