|
JML | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.multijava.util.Utils
org.multijava.mjc.TypeLoader
This class acts as a symbol table and a cache for types, type signatures, and external generic functions. It includes methods to load unknown type signatures. It maintains a mapping from fully qualified names to the CClass instances representing their signatures. Specifically the mapping is from a fully qualified type name to a set of instances that can be sorted. In MultiJava that set is a singleton set; however, for tools like JML where a single fully qualified name can refer to a specification and one or more refinements to that specification, the set may contain multiple items.
| Field Summary | |
private HashMap |
compilationSessionRepCache
Maintains a mapping of qualified names to type representations; that is, it maps a fully qualified name to the CClassType instance that represents the type. |
protected MjcHashRelation |
compilationSessionTypeCache
This relation stores a mapping from fully qualified type names to their CClass instances. |
protected FileFinder |
fileFinder
|
private String |
oldClassPath
|
private static TypeLoader |
singletonInstance
|
private HashMap |
vmSessionRepCache
Maintains a mapping of qualified names to type representations; that is, it maps a fully qualified name to the CClassType instance that represents the type. |
protected MjcHashRelation |
vmSessionTypeCache
This relation stores a mapping from fully qualified type names to their CClass instances. |
| Fields inherited from class org.multijava.util.Utils |
DBG_LEVEL_HIGH, DBG_LEVEL_LOW, DBG_LEVEL_NO |
| Constructor Summary | |
private |
TypeLoader()
|
protected |
TypeLoader(FileFinder fileFinder)
This constructor is only for use by subclasses. |
| Method Summary | |
boolean |
addToTypeCache(CClass typ)
Adds the given source class to the table of loaded classes. |
void |
addTypeRep(String qName,
CClassType typeRep)
Adds the given type representation, which must represent a fully qualified type name, to the cache. |
protected boolean |
checkUniqueness(CClass typ,
CClass last)
Returns true if typ is a legal unique type declaration. |
boolean |
classExists(String qName)
Checks whether a class with the given name is available in the class path. |
protected ClassInfo |
createClassInfo(String qName)
Creates and returns a class info object by reading the symbol file for the class with the given fully qualified name qName. |
FileFinder |
fileFinder()
Returns the FileFinder instance that is used by the current loader when searching for classes and generic functions. |
ClassPath.ClassDescription |
find(String name)
This method finds a file for the given class name; it looks for both a java file on the source path and a class file on the class path, returning the newer one if both are found (and null if neither is found). |
ClassPath.ClassDescription |
findSourceFile(String name)
|
protected void |
forgetEverythingAbout(File f,
JCompilationUnitType cunit)
Called by Main when the given file, from which the given compilation unit AST was derived, did not contain an expected result; this method removes all cached info. for the file. |
static TypeLoader |
getSingleton()
|
CClassType |
getTypeRep(String name,
CUniverse univ,
CClassType[][] arguments,
boolean isFullyQualified)
Returns the lightweight type representation of the class with the given name, generating a new one if necessary. |
void |
initSession()
Empties the compilation session caches to prepare for a new compilation session. |
boolean |
isDeclaredInDifferentSourceFiles(boolean isUnique,
CClass clazz)
This method is needed so it can be overridden by JML in order to handle classes that have been refined, e.g., when its specifications have intentionally been declared in a separate file. |
protected boolean |
isTrusted(String qName)
Returns true if the information for the type or package of the given qualified name should be retained for subsequent compilation sessions. |
boolean |
isTypeLoaded(String qName)
Checks whether a class with the given name has already been successfully loaded. |
CClass |
loadType(String qName)
|
CClass |
lookupType(String qName)
Returns the first CClass instance in the set mapped to by the given fully qualified name, or null if no such instance exists. |
CClassType |
lookupTypeRep(String qName)
|
private static boolean |
mayShare(CClassType type,
CUniverse univ,
CClassType[][] arguments)
Returns whether the given type can be shared by another
type having the given univ and type arguments. |
CClass |
reloadType(CClass clazz)
Reloads the specified class if this class has been defined during a previous compilation session. |
protected void |
removeFromTypeCache(CClass typ)
Removes the qualified name of the given source class from the table of loaded classes (so it can be reloaded without causing conflicts). |
void |
signatureCompleted(CClass typ)
Implements CClass.Observer by moving typ from compilationSessionTypeCache to vmSessionTypeCache if typ is trusted. |
| Methods inherited from class org.multijava.util.Utils |
assertTrue, assertTrue, combineArrays, escapeString, escapeString, fail, fail, getFilePath, hasFlag, hasOtherFlags, parsePathParts, relativePathTo, splitQualifiedName, splitQualifiedName, stripJavaModifiers, stripNonJavaModifiers, stripPrivateModifier, unescapeString, vectorToArray, vectorToIntArray |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected MjcHashRelation compilationSessionTypeCache
vmSessionTypeCache,
isTrusted(String)protected MjcHashRelation vmSessionTypeCache
compilationSessionTypeCache,
isTrusted(String)private HashMap compilationSessionRepCache
vmSessionRepCache,
isTrusted(String)private HashMap vmSessionRepCache
compilationSessionRepCache,
isTrusted(String)protected FileFinder fileFinder
private String oldClassPath
private static TypeLoader singletonInstance
| Constructor Detail |
private TypeLoader()
protected TypeLoader(FileFinder fileFinder)
getSingleton()| Method Detail |
public static TypeLoader getSingleton()
public CClassType getTypeRep(String name,
CUniverse univ,
CClassType[][] arguments,
boolean isFullyQualified)
name - the name of the classisFullyQualified - the name is known to be fully qualified
requires name != null; modifies compilationSessionRepCache; ensures isFullyQualified ==> compilationSessionRepCache.containsKey(name) || vmSessionRepCache.containsKey(name);
private static boolean mayShare(CClassType type,
CUniverse univ,
CClassType[][] arguments)
type can be shared by another
type having the given univ and type arguments.
This is the case iff the Universe modifier and the type arguments of the
type are equivalent to the ones provided here.
type - The target type.univ - The Universe modifier.arguments - The generic type arguments.
public CClassType lookupTypeRep(String qName)
public void addTypeRep(String qName,
CClassType typeRep)
requires qName != null && typeRep != null && (* all separators in qName are '/' not '.' *); modifies compilationSessionRepCache, vmSessionRepCache; ensures compilationSessionRepCache.containsKey(qName) || vmSessionRepCache.containsKey(qName);
public ClassPath.ClassDescription findSourceFile(String name)
public ClassPath.ClassDescription find(String name)
public boolean addToTypeCache(CClass typ)
requires typ != null; modifies compilationSessionTypeCache, vmSessionTypeCache;
protected boolean checkUniqueness(CClass typ,
CClass last)
typ - a type to be added to the cachelast - the previous cache entry mapped to by typ.qualifiedName()
protected void forgetEverythingAbout(File f,
JCompilationUnitType cunit)
protected void removeFromTypeCache(CClass typ)
requires typ != null; modifies compilationSessionTypeCache, vmSessionTypeCache;
public CClass lookupType(String qName)
requires qName != null && (* any separators in qName are slashes ('/'), not dots ('.') *);
public CClass loadType(String qName)
protected ClassInfo createClassInfo(String qName)
qName. If no symbol file is found, null is
returned. This method also create a binary class object and
adds it to the system cache. This is a factory method that may
be overridden by subclasses.
public CClass reloadType(CClass clazz)
public boolean isTypeLoaded(String qName)
qName - the fully qualified name of the type with slash separators
not dots
public boolean classExists(String qName)
qName - the fully qualified name of the type with slash separators
not dots
public boolean isDeclaredInDifferentSourceFiles(boolean isUnique,
CClass clazz)
public void signatureCompleted(CClass typ)
also old String qName = typ.qualifiedName(); requires typ != null && isTrusted(qName); ensures \old(compilationSessionTypeCache.getImage(qName).contains(typ)) ==> !compilationSessionTypeCache.getImage(qName).contains(typ) && vmSessionTypeCache.getImage(qName).contains(typ);
signatureCompleted in interface CClass.Observerprotected boolean isTrusted(String qName)
requires qName != null && (* package separators in qName are '/' not '.' *);
public void initSession()
requires (* ClassPath.init() has been called with to set the class path for this upcoming session *);
public FileFinder fileFinder()
|
JML | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||