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.filespace
Class Resolve

java.lang.Object
  extended byjavafe.filespace.Resolve

public class Resolve
extends java.lang.Object

This module encapsulates how to resolve an ambiguous multi-part identifier (i.e., X.Y.Z) into a package + (possibly a) reference type + a type field/member multi-part identifier, using the output of ClassPath.

I.e., it would split java.util.zip.Foo.Subclass.x.y into the package java.util.zip, the (inner) type Foo$Subclass, and the field/member identifier x.y.


Field Summary
static Tree namespace
          The current Java namespace; must be a non-null filespace.
 
Constructor Summary
Resolve()
           
 
Method Summary
static java.lang.String combineNames(java.lang.String first, java.lang.String second, java.lang.String separator)
          Combine two names using a separator if both are non-empty.
static Resolve_Result ensureType(Resolve_Result answer)
          Check the result of a lookup to ensure that it refers to an (inner) reference type.
static Resolve_Result ensureUnit(Resolve_Result answer)
          Check the result of a lookup to ensure that it refers to an (inner) reference type or a package.
static void init(boolean complain)
          Attempt to set the current namespace to current classpath (cf.
static Resolve_Result lookup(Tree filespace, java.lang.String[] identifier)
          Lookup a multi-part identifier in a Java filespace in the same way that the Java compiler does so.
static Resolve_Result lookupName(java.lang.String identifier)
          Convenience function: do a lookupName using the current namespace
static Resolve_Result lookupName(Tree filespace, java.lang.String identifier)
          Do a lookup using the result of parseIdentifier extended to allow '$' as an additional separator.
static void main(java.lang.String[] args)
          A simple test driver
static java.lang.String[] parseIdentifier(java.lang.String id)
          Convert a multi-part identifier into a path.
static void set(java.lang.String classpath, boolean complain)
          Attempt to set the current namespace to a new non-null class path.
static java.lang.String tr(java.lang.String input, char from, char to)
          Convert 1 character to another everywhere it appears in a given string.
static boolean typeExists(Tree P, java.lang.String typeName)
          Does a package contain a reference type with a given simple name?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

namespace

public static Tree namespace
The current Java namespace; must be a non-null filespace.

Starts out empty.

Constructor Detail

Resolve

public Resolve()
Method Detail

typeExists

public static boolean typeExists(Tree P,
                                 java.lang.String typeName)
Does a package contain a reference type with a given simple name?

Currently true if a source or a binary for that type exists (directly) in the given package.


lookup

public static Resolve_Result lookup(Tree filespace,
                                    java.lang.String[] identifier)
                             throws Resolve_AmbiguousName
Lookup a multi-part identifier in a Java filespace in the same way that the Java compiler does so.

Precondition: the identifier parts should not contain the '.' or '$' characters, and each must be non-null and non-empty.

The leftmost part of the identifier is assumed to refer to an existing package; the longest such name is used. The returned package will always be non-null because package names may be empty ("" refers to the top package).

The remaining part of the identifier (may be empty) is then assumed to be the concatenation of a (inner) reference-type name and a remainder part. Again, as with the package name, the type name is assumed to be the longest such name that refers to an existing type, with the proviso that a type is considered to exist only if all prefix types (i.e., X and X$Y for X$Y$Z) also exist. If no non-empty prefix names an existing type, then the type name is taken to be empty and the returned typeName will be null. Otherwise, the returned typeName contains the (non-null) name of the type, with its parts separated by '$'s.

The remaining part of the identifier after the package name and type name have been removed is returned as the remainder part.

EXCEPTION: if, while identifying the package name, a package is encountered that has the same name as a reference type, then the exception Resolve_AmbiguousName will be thrown with ambiguousPackage set to the package with the ambiguous name. Such package/type naming conflicts are illegal according to the Java documentation.

Throws:
Resolve_AmbiguousName

combineNames

public static java.lang.String combineNames(java.lang.String first,
                                            java.lang.String second,
                                            java.lang.String separator)
Combine two names using a separator if both are non-empty.


parseIdentifier

public static java.lang.String[] parseIdentifier(java.lang.String id)
Convert a multi-part identifier into a path. Returns null if the identifier is badly formed (i.e., contains empty components). id must be non-null.

Only uses '.' as a separator. If you wish to allow '$' as well, use tr first to map all the '$'s in the name into '.'s.


lookupName

public static Resolve_Result lookupName(Tree filespace,
                                        java.lang.String identifier)
                                 throws Resolve_AmbiguousName
Do a lookup using the result of parseIdentifier extended to allow '$' as an additional separator.

Complains to System.err then returns null if the name is badly formed. identifier and filespace must be non-null.

Throws:
Resolve_AmbiguousName

set

public static void set(java.lang.String classpath,
                       boolean complain)
Attempt to set the current namespace to a new non-null class path.

Complains about any errors to System.err. The current namespace remains unchanged in the case of an error.

Iff complain is set, we complain if non-existent or ill-formed path components are present in the classpath.


init

public static void init(boolean complain)
Attempt to set the current namespace to current classpath (cf. ClassPath).

Complains about any errors to System.err. The current namespace remains unchanged in the case of an error.

Iff complain is set, we complain if non-existent or ill-formed path components are present in the classpath.


lookupName

public static Resolve_Result lookupName(java.lang.String identifier)
                                 throws Resolve_AmbiguousName
Convenience function: do a lookupName using the current namespace

Throws:
Resolve_AmbiguousName

ensureUnit

public static Resolve_Result ensureUnit(Resolve_Result answer)
Check the result of a lookup to ensure that it refers to an (inner) reference type or a package. I.e., that there are no remainder parts.

If the check fails, complains appropriately to System.err and then returns null. If answer is already null, returns null immediately.

Otherwise, returns its argument unchanged; the argument will always have a remainder of length 0 in this case.


ensureType

public static Resolve_Result ensureType(Resolve_Result answer)
Check the result of a lookup to ensure that it refers to an (inner) reference type.

If the check fails, complains appropriately to System.err and then returns null. If answer is already null, returns null immediately.

Otherwise, returns its argument unchanged; the argument will have a non-null myTypeName and a remainder with length 0 in this case.


tr

public static java.lang.String tr(java.lang.String input,
                                  char from,
                                  char to)
Convert 1 character to another everywhere it appears in a given string.


main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
A simple test driver

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