polyglot.types
Class SourceClassResolver

java.lang.Object
  extended by polyglot.types.ClassResolver
      extended by polyglot.types.LoadedClassResolver
          extended by polyglot.types.SourceClassResolver
All Implemented Interfaces:
Resolver, TopLevelResolver

public class SourceClassResolver
extends LoadedClassResolver

Loads class information from source files, class files, or serialized class infomation from within class files. An outline of the steps is given below.

  1. When the polyglot translator looks for a class by the name "foo.bar.Quux" it first searches for that class in any file given on the command line. If the class is found one of these files, then this definition is used and the remainder of the steps are skipped.
  2. If none of these files contain the desired class, then the source path is searched next. For example, if the source extension is ".jl" and the source path is "mydir:." then the translator looks for files "mydir/foo/bar/Quux.jl" and "./foo/bar/Quux.jl".
  3. Regardless of whether or not a source file is found, the translator searches the classpath (defined as normal through the environment and command-line options to the interpreter) for the desired class.
  4. If no source file exists, and no class is found then an error is reported (skipping the rest of the steps below).
  5. If a source file is found, but no class, then the source file is parsed. If it contains the desired class definition (which it should) then that definition is used and the remainder of the steps are skipped. (If it does not contain this definition, an error is reported and the remainder of the steps are skipped.
  6. If a class is found but no source file, then the class is examined for jlc class type information. If the class contains no class type information (this is the case if the class file was compiled from raw Java source rather than jlc translated output) then this class is used as the desired class definition (skipping all steps below).
  7. (class, but no still no source) If the class does contain jlc class type information, then the version number of translator used to translate the source which created the given class file is compared against the version of the current instantiation of the translator. If the versions are compatible, then the jlc class type information is used as the desired definiton. If the versions are incompatible (see the documentation in Compiler.java) then an error is reported. In either case, all remaining steps are skipped.
  8. If both a suitable source file and class are found then we have a choice. If the class definition does not contain jlc class type information then the source file is parsed as the definition found in this file is used as desired definiton and we stop here. If the class does contain jlc class type information, then continue.
  9. (source and class with jlc info) Next the last modification date of the source file is compared to the last modification date of the source file used to generate the class file. If the source file is more recent, the it is parsed as used as the desired definition and all remaining steps are skipped.
  10. (source and class with jlc info) Next the jlc version of the class and of the current translator are compared (as in 7.). If the verisions are incompatible, then we use the definition from the parsed source file. If the versions are compatible, then we use the definition given by the jlc class type information.
Finally, if at any point an error occurs while reading jlc class type information (e.g. if this information exists but is corrupted), then an error is reported.


Field Summary
 
Fields inherited from class polyglot.types.LoadedClassResolver
COMPATIBLE, MINOR_NOT_COMPATIBLE, NOT_COMPATIBLE
 
Constructor Summary
SourceClassResolver(Compiler compiler, ExtensionInfo ext, java.lang.String classpath, ClassFileLoader loader, boolean allowRawClasses)
          Create a loaded class resolver.
 
Method Summary
 Named find(java.lang.String name)
          Find a type by name.
protected  Named getTypeFromSource(FileSource source, java.lang.String name)
          Get a type from a source file.
 boolean packageExists(java.lang.String name)
          Check if a package exists.
 
Methods inherited from class polyglot.types.LoadedClassResolver
checkCompilerVersion, getEncodedType, loadFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SourceClassResolver

public SourceClassResolver(Compiler compiler,
                           ExtensionInfo ext,
                           java.lang.String classpath,
                           ClassFileLoader loader,
                           boolean allowRawClasses)
Create a loaded class resolver.

Parameters:
compiler - The compiler.
ext - The extension to load sources for.
classpath - The class path.
loader - The class file loader to use.
allowRawClasses - True if vanilla Java class files without Polyglot-embedded type information should be allowed.
Method Detail

packageExists

public boolean packageExists(java.lang.String name)
Description copied from interface: TopLevelResolver
Check if a package exists.

Specified by:
packageExists in interface TopLevelResolver
Overrides:
packageExists in class LoadedClassResolver

find

public Named find(java.lang.String name)
           throws SemanticException
Find a type by name.

Specified by:
find in interface Resolver
Overrides:
find in class LoadedClassResolver
Throws:
SemanticException

getTypeFromSource

protected Named getTypeFromSource(FileSource source,
                                  java.lang.String name)
                           throws SemanticException
Get a type from a source file.

Throws:
SemanticException