polyglot.types
Class SourceClassResolver
java.lang.Object
polyglot.types.ClassResolver
polyglot.types.LoadedClassResolver
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.
- 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.
- 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".
- 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.
- If no source file exists, and no class is found then an error is
reported (skipping the rest of the steps below).
- 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.
- 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).
- (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.
- 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.
- (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.
- (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.
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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.
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