ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

javafe.reader
Class StandardTypeReader

java.lang.Object
  extended byjavafe.reader.Reader
      extended byjavafe.reader.TypeReader
          extended byjavafe.reader.StandardTypeReader
Direct Known Subclasses:
EscTypeReader

public class StandardTypeReader
extends TypeReader

A StandardTypeReader is a TypeReader that uses SlowQuery to find type files, and user-supplied Readers to read source and binary files.


Field Summary
 Reader binaryReader
          Our (non-null) reader for use in reading in binary (.class) files.
 Query javaFileSpace
          Our (non-null) Query engine for determining the GenericFiles for files that belong to Java packages.
 Query javaSrcFileSpace
           
 Reader sourceReader
          Our (non-null) reader for use in reading in source files.
 
Constructor Summary
protected StandardTypeReader(Query engine, Query srcEngine, CachedReader srcReader, CachedReader binReader)
          Create a StandardTypeReader from a query engine, a source reader, and a binary reader.
 
Method Summary
 boolean accessable(java.lang.String[] P)
          Return true iff the package P is "accessible".
 void clear()
           
 boolean exists(java.lang.String[] P, java.lang.String T)
          Return true iff the fully-qualified outside type P.T exists.
 java.io.FilenameFilter filter()
           
 java.util.ArrayList findFiles(java.lang.String[] P)
          Returns an enumeration of the GenericFile objects in the given package P.
 GenericFile findType(java.lang.String[] P, java.lang.String T)
          Returns a (source or binary) file for the given type.
 GenericFile locateBinary(java.lang.String[] P, java.lang.String[] N)
          If a binary exists for the exact fully-qualified type P.N (e.g., no inheritance required), then return a GenericFile representing that file.
 GenericFile locateSource(java.lang.String[] P, java.lang.String T, boolean useSrcPtr)
          If a source exists for the fully-qualified outside type P.T, then return a GenericFile representing that file.
static void main(java.lang.String[] args)
           
static StandardTypeReader make()
          Create a StandardTypeReader using the default Java classpath for our underlying Java file space and no pragma parser.
static StandardTypeReader make(PragmaParser pragmaP)
          Create a StandardTypeReader using a the default Java classpath for our underlying Java file space and a given pragma parser.
static StandardTypeReader make(Query Q, Query sourceQ, PragmaParser pragmaP)
          Create a StandardTypeReader from a query engine and a pragma parser.
static StandardTypeReader make(Query engine, Query srcEngine, Reader srcReader, Reader binReader)
          Create a StandardTypeReader from a query engine, a source reader, and a binary reader.
static StandardTypeReader make(java.lang.String path, java.lang.String sourcePath, PragmaParser pragmaP)
          Create a StandardTypeReader using a given Java classpath for our underlying Java file space and a given pragma parser.
static Query queryFromClasspath(java.lang.String path)
          Create a Query for use in creating a StandardTypeReader from a Java classpath.
 CompilationUnit read(GenericFile target, boolean avoidSpec)
          Attempt to read and parse a CompilationUnit from source file target.
 CompilationUnit read(java.lang.String[] P, java.lang.String T, boolean avoidSpec)
          Attempt to read and parse a CompilationUnit from either the binaries for P.T if they are up to date, or from the source for P.T.
 CompilationUnit readTypeBinaries(java.lang.String[] P, java.lang.String T, long after)
          Attempt to read and parse a complete (i.e., no stubs) CompilationUnit from the binaries for the fully-qualified outside type P.T.
 CompilationUnit readTypeSrc(java.lang.String[] P, java.lang.String T, boolean avoidSpec)
          Attempt to read and parse a CompilationUnit from the source for the fully-qualified outside type P.T.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

javaFileSpace

public Query javaFileSpace
Our (non-null) Query engine for determining the GenericFiles for files that belong to Java packages.


javaSrcFileSpace

public Query javaSrcFileSpace

sourceReader

public Reader sourceReader
Our (non-null) reader for use in reading in source files.


binaryReader

public Reader binaryReader
Our (non-null) reader for use in reading in binary (.class) files.

Constructor Detail

StandardTypeReader

protected StandardTypeReader(Query engine,
                             Query srcEngine,
                             CachedReader srcReader,
                             CachedReader binReader)
Create a StandardTypeReader from a query engine, a source reader, and a binary reader. All arguments must be non-null.

Method Detail

clear

public void clear()

make

public static StandardTypeReader make(Query engine,
                                      Query srcEngine,
                                      Reader srcReader,
                                      Reader binReader)
Create a StandardTypeReader from a query engine, a source reader, and a binary reader. All arguments must be non-null.


make

public static StandardTypeReader make(Query Q,
                                      Query sourceQ,
                                      PragmaParser pragmaP)
Create a StandardTypeReader from a query engine and a pragma parser. The pragma parser may be null.


queryFromClasspath

public static Query queryFromClasspath(java.lang.String path)
Create a Query for use in creating a StandardTypeReader from a Java classpath.

A fatal error will be reported via ErrorSet if an I/O error occurs while initially scanning the filesystem.


make

public static StandardTypeReader make(java.lang.String path,
                                      java.lang.String sourcePath,
                                      PragmaParser pragmaP)
Create a StandardTypeReader using a given Java classpath for our underlying Java file space and a given pragma parser. If the given path is null, the default Java classpath is used.

A fatal error will be reported via ErrorSet if an I/O error occurs while initially scanning the filesystem.


make

public static StandardTypeReader make(PragmaParser pragmaP)
Create a StandardTypeReader using a the default Java classpath for our underlying Java file space and a given pragma parser.

A fatal error will be reported via ErrorSet if an I/O error occurs while initially scanning the filesystem.


make

public static StandardTypeReader make()
Create a StandardTypeReader using the default Java classpath for our underlying Java file space and no pragma parser.

A fatal error will be reported via ErrorSet if an I/O error occurs while initially scanning the filesystem.


accessable

public boolean accessable(java.lang.String[] P)
Return true iff the package P is "accessible".

Warning: the definition of accessible is host system dependent and may in fact be defined as always true.

Specified by:
accessable in class TypeReader

exists

public boolean exists(java.lang.String[] P,
                      java.lang.String T)
Return true iff the fully-qualified outside type P.T exists.

Specified by:
exists in class TypeReader

findType

public GenericFile findType(java.lang.String[] P,
                            java.lang.String T)
Description copied from class: TypeReader
Returns a (source or binary) file for the given type.

Specified by:
findType in class TypeReader

locateBinary

public GenericFile locateBinary(java.lang.String[] P,
                                java.lang.String[] N)
If a binary exists for the exact fully-qualified type P.N (e.g., no inheritance required), then return a GenericFile representing that file. Otherwise, return null.

WARNING: if N is not a simple name, then a non-null return result does *not* imply that P.N actually exists. The binary may be left over from a previous compilation. Only if P.N can be reached from its containing clases, is it considered to exist.


locateSource

public GenericFile locateSource(java.lang.String[] P,
                                java.lang.String T,
                                boolean useSrcPtr)
If a source exists for the fully-qualified outside type P.T, then return a GenericFile representing that file. Otherwise, return null.

Exception: If P.T's source file is not called T.java, and no T.class file exists for P.T, then null will also be returned. If useSrcPtr is not set, then null will be returned when P.T's source file is not called T.java, regardless of whether or not there is a T.class file for P.T.

Note: iff useSrcPtr is set, then P.T's binary may be read in in order to obtain it's source pointer.


findFiles

public java.util.ArrayList findFiles(java.lang.String[] P)
Description copied from class: TypeReader
Returns an enumeration of the GenericFile objects in the given package P.

Specified by:
findFiles in class TypeReader

filter

public java.io.FilenameFilter filter()
Overrides:
filter in class TypeReader

read

public CompilationUnit read(GenericFile target,
                            boolean avoidSpec)
Attempt to read and parse a CompilationUnit from source file target. Any errors encountered are reported via ErrorSet. Null is returned iff an error was encountered.

By default, we attempt to read only a spec (e.g., specOnly is set in the resulting CompilationUnit) to save time. If avoidSpec is true, we return a non-spec, except in the case where we have previously read in the same source file with avoidSpec false. (See notes on caching below.)

There are 2 safe ways to ensure source files yield non-spec files: (1) always use avoidSpec, or (2) read all desired non-spec's at the beginning with avoidSpec set. [these instructions apply to both versions of read.]

The result of this function is cached. Note that read(String[], String, boolean) may implicitly call this function, resulting in caching of source files.

Only the value of avoidSpec used the first time a given file is read is used (including implicit calls). This may result in a spec being returned unnecessarily when avoidSpec is true.

Target must be non-null.

Specified by:
read in class TypeReader

readTypeSrc

public CompilationUnit readTypeSrc(java.lang.String[] P,
                                   java.lang.String T,
                                   boolean avoidSpec)
Attempt to read and parse a CompilationUnit from the source for the fully-qualified outside type P.T. Null is returned if no source can be found for P.T or if an error is encountered. Errors are reported via ErrorSet.

If P.T's source is not named T.java and there is no T.class file for P.T., then no source for P.T will be found.

(This is a convenience function.)


readTypeBinaries

public CompilationUnit readTypeBinaries(java.lang.String[] P,
                                        java.lang.String T,
                                        long after)
Attempt to read and parse a complete (i.e., no stubs) CompilationUnit from the binaries for the fully-qualified outside type P.T.

Null is returned if:

Errors are reported via ErrorSet. An incomplete set of binaries (one or more inner classes missing or not up-to-date WRT after) is considered an error.


read

public CompilationUnit read(java.lang.String[] P,
                            java.lang.String T,
                            boolean avoidSpec)
Attempt to read and parse a CompilationUnit from either the binaries for P.T if they are up to date, or from the source for P.T. If both a source and an up-to-date series of binaries are available for P.T, preference is given to the source if srcPreferred is set, and to the binaries otherwise.

Binaries are considered to exist for P.T iff a T.class file exists in package P. The last modified date for these binaries as a whole is considered to be the T.class file's last modified date.

Null is returned if no source or binaries for P.T exist or if an error occurs. Errors are reported via ErrorSet. An incomplete series of binaries (one or more inner classes missing or not up-to-date) generates an error when read in.

If the resulting CompilationUnit is non-null, then it is always complete, having no stubs.

Specified by:
read in class TypeReader

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Throws:
java.io.IOException

ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

The ESC/Java2 Project Homepage