public synchronized Identifier resolve(Environment env,Identifier nm) throws ClassNotFound {
  if (tracing)   env.dtEnter("Imports.resolve: " + nm);
  if (nm.hasAmbigPrefix()) {
    nm=nm.removeAmbigPrefix();
  }
  if (nm.isQualified()) {
    if (tracing)     env.dtExit("Imports.resolve: QUALIFIED " + nm);
    return nm;
  }
  if (checked <= 0) {
    checked=0;
    resolve(env);
  }
  Identifier className=(Identifier)classes.get(nm);
  if (className != null) {
    if (tracing)     env.dtExit("Imports.resolve: PREVIOUSLY IMPORTED " + nm);
    return className;
  }
  Identifier id=Identifier.lookup(currentPackage,nm);
  if (importable(id,env)) {
    className=id;
  }
 else {
    Enumeration e=packages.elements();
    while (e.hasMoreElements()) {
      IdentifierToken t=(IdentifierToken)e.nextElement();
      id=Identifier.lookup(t.getName(),nm);
      if (importable(id,env)) {
        if (className == null) {
          className=id;
        }
 else {
          if (tracing)           env.dtExit("Imports.resolve: AMBIGUOUS " + nm);
          throw new AmbiguousClass(className,id);
        }
      }
    }
  }
  if (className == null) {
    if (tracing)     env.dtExit("Imports.resolve: NOT FOUND " + nm);
    throw new ClassNotFound(nm);
  }
  classes.put(nm,className);
  if (tracing)   env.dtExit("Imports.resolve: FIRST IMPORT " + nm);
  return className;
}

public synchronized Identifier resolve ( Environment env , Identifier nm ) throws ClassNotFound { if ( tracing ) env . dtEnter ( "Imports.resolve: " + nm ) ; if ( nm . hasAmbigPrefix ( ) ) { nm = nm . removeAmbigPrefix ( ) ; } if ( nm . isQualified ( ) ) { if ( tracing ) env . dtExit ( "Imports.resolve: QUALIFIED " + nm ) ; return nm ; } if ( checked <= 0 ) { checked = 0 ; resolve ( env ) ; } Identifier className = ( Identifier ) classes . get ( nm ) ; if ( className != null ) { if ( tracing ) env . dtExit ( "Imports.resolve: PREVIOUSLY IMPORTED " + nm ) ; return className ; } Identifier id = Identifier . lookup ( currentPackage , nm ) ; if ( importable ( id , env ) ) { className = id ; } else { Enumeration e = packages . elements ( ) ; while ( e . hasMoreElements ( ) ) { IdentifierToken t = ( IdentifierToken ) e . nextElement ( ) ; id = Identifier . lookup ( t . getName ( ) , nm ) ; if ( importable ( id , env ) ) { if ( className == null ) { className = id ; } else { if ( tracing ) env . dtExit ( "Imports.resolve: AMBIGUOUS " + nm ) ; throw new AmbiguousClass ( className , id ) ; } } } } if ( className == null ) { if ( tracing ) env . dtExit ( "Imports.resolve: NOT FOUND " + nm ) ; throw new ClassNotFound ( nm ) ; } classes . put ( nm , className ) ; if ( tracing ) env . dtExit ( "Imports.resolve: FIRST IMPORT " + nm ) ; return className ; }
lookup a class , given the current set of imports , ambiguousclass exception is thrown if the name can be resolved in more than one way . a classnotfound exception is thrown if the class is not found in the imported classes and packages .
