Symbol findVar ( Env < AttrContext > env , Name name ) { Symbol bestSoFar = varNotFound ; Env < AttrContext > env1 = env ; boolean staticOnly = false ; while ( env1 . outer != null ) { Symbol sym = null ; if ( isStatic ( env1 ) ) staticOnly = true ; for ( Symbol s : env1 . info . scope . getSymbolsByName ( name ) ) { if ( s . kind == VAR && ( s . flags_field & SYNTHETIC ) == 0 ) { sym = s ; break ; } } if ( sym == null ) { sym = findField ( env1 , env1 . enclClass . sym . type , name , env1 . enclClass . sym ) ; } if ( sym . exists ( ) ) { if ( staticOnly && sym . kind == VAR && sym . owner . kind == TYP && ( sym . flags ( ) & STATIC ) == 0 ) return new StaticError ( sym ) ; else return sym ; } else { bestSoFar = bestOf ( bestSoFar , sym ) ; } if ( ( env1 . enclClass . sym . flags ( ) & STATIC ) != 0 ) staticOnly = true ; env1 = env1 . outer ; } Symbol sym = findField ( env , syms . predefClass . type , name , syms . predefClass ) ; if ( sym . exists ( ) ) return sym ; if ( bestSoFar . exists ( ) ) return bestSoFar ; Symbol origin = null ; for ( Scope sc : new Scope [ ] { env . toplevel . namedImportScope , env . toplevel . starImportScope } ) { for ( Symbol currentSymbol : sc . getSymbolsByName ( name ) ) { if ( currentSymbol . kind != VAR ) continue ; // invariant: sym.kind == Symbol.Kind.VAR if ( ! bestSoFar . kind . isResolutionError ( ) && currentSymbol . owner != bestSoFar . owner ) return new AmbiguityError ( bestSoFar , currentSymbol ) ; else if ( ! bestSoFar . kind . betterThan ( VAR ) ) { origin = sc . getOrigin ( currentSymbol ) . owner ; bestSoFar = isAccessible ( env , origin . type , currentSymbol ) ? currentSymbol : new AccessError ( env , origin . type , currentSymbol ) ; } } if ( bestSoFar . exists ( ) ) break ; } if ( bestSoFar . kind == VAR && bestSoFar . owner . type != origin . type ) return bestSoFar . clone ( origin ) ; else return bestSoFar ; }
Find unqualified variable or field with given name . Synthetic fields always skipped .