1981 ClassSymbol c = finder.loadClass(env.toplevel.modle, name); |
1981 ClassSymbol c = finder.loadClass(env.toplevel.modle, name); |
1982 return isAccessible(env, c) ? c : new AccessError(c); |
1982 return isAccessible(env, c) ? c : new AccessError(c); |
1983 } catch (ClassFinder.BadClassFile err) { |
1983 } catch (ClassFinder.BadClassFile err) { |
1984 throw err; |
1984 throw err; |
1985 } catch (CompletionFailure ex) { |
1985 } catch (CompletionFailure ex) { |
1986 //even if a class cannot be found in the current module and packages in modules it depends on that |
1986 Symbol candidate = recoveryLoadClass.loadClass(env, name); |
1987 //are exported for any or this module, the class may exist internally in some of these modules, |
1987 |
1988 //or may exist in a module on which this module does not depend. Provide better diagnostic in |
1988 if (candidate != null) { |
1989 //such cases by looking for the class in any module: |
1989 return candidate; |
1990 for (ModuleSymbol ms : syms.getAllModules()) { |
1990 } |
1991 //do not load currently unloaded classes, to avoid too eager completion of random things in other modules: |
1991 |
1992 ClassSymbol clazz = syms.getClass(ms, name); |
|
1993 |
|
1994 if (clazz != null) { |
|
1995 return new AccessError(clazz); |
|
1996 } |
|
1997 } |
|
1998 return typeNotFound; |
1992 return typeNotFound; |
1999 } |
1993 } |
|
1994 } |
|
1995 |
|
1996 public static interface RecoveryLoadClass { |
|
1997 Symbol loadClass(Env<AttrContext> env, Name name); |
|
1998 } |
|
1999 |
|
2000 private RecoveryLoadClass recoveryLoadClass = (env, name) -> { |
|
2001 //even if a class cannot be found in the current module and packages in modules it depends on that |
|
2002 //are exported for any or this module, the class may exist internally in some of these modules, |
|
2003 //or may exist in a module on which this module does not depend. Provide better diagnostic in |
|
2004 //such cases by looking for the class in any module: |
|
2005 for (ModuleSymbol ms : syms.getAllModules()) { |
|
2006 //do not load currently unloaded classes, to avoid too eager completion of random things in other modules: |
|
2007 ClassSymbol clazz = syms.getClass(ms, name); |
|
2008 |
|
2009 if (clazz != null) { |
|
2010 return new AccessError(clazz); |
|
2011 } |
|
2012 } |
|
2013 return null; |
|
2014 }; |
|
2015 |
|
2016 public RecoveryLoadClass setRecoveryLoadClass(RecoveryLoadClass recovery) { |
|
2017 RecoveryLoadClass prev = recoveryLoadClass; |
|
2018 recoveryLoadClass = recovery; |
|
2019 return prev; |
2000 } |
2020 } |
2001 |
2021 |
2002 /** |
2022 /** |
2003 * Find a type declared in a scope (not inherited). Return null |
2023 * Find a type declared in a scope (not inherited). Return null |
2004 * if none is found. |
2024 * if none is found. |