private Description check(Tree tree, Name simpleName, VisitorState state) { Symtab symtab = state.getSymtab(); PackageSymbol javaLang = symtab.enterPackage(symtab.java_base, Names.instance(state.context).java_lang); Symbol other = getFirst( javaLang.members().getSymbolsByName(simpleName, s -> s.getModifiers().contains(PUBLIC)), null); Symbol symbol = ASTHelpers.getSymbol(tree); if (other == null || other.equals(symbol)) { return NO_MATCH; } return buildDescription(tree) .setMessage(String.format("%s clashes with %s\n", symbol, other)) .build(); } }
private Description check(Tree tree, Name simpleName, VisitorState state) { Symtab symtab = state.getSymtab(); PackageSymbol javaLang = symtab.enterPackage(symtab.java_base, Names.instance(state.context).java_lang); Symbol other = getFirst( javaLang.members().getSymbolsByName(simpleName, s -> s.getModifiers().contains(PUBLIC)), null); Symbol symbol = ASTHelpers.getSymbol(tree); if (other == null || other.equals(symbol)) { return NO_MATCH; } return buildDescription(tree) .setMessage(String.format("%s clashes with %s\n", symbol, other)) .build(); } }
StarImportScope importScope = new StarImportScope(unit.packge); importScope.prependSubScope(unit.starImportScope); importScope.prependSubScope(((PackageSymbol)toImport).members()); unit.starImportScope = importScope; } else {
q.flags_field |= EXISTS; c = reader.enterClass(tree.name, packge); packge.members().enterIfAbsent(c); if ((tree.mods.flags & PUBLIC) != 0 && !classNameMatchesFileName(c, env)) { log.error(tree.pos(),
q.flags_field |= EXISTS; c = reader.enterClass(tree.name, packge); packge.members().enterIfAbsent(c); if ((tree.mods.flags & PUBLIC) != 0 && !classNameMatchesFileName(c, env)) { log.error(tree.pos(),
q.flags_field |= EXISTS; c = reader.enterClass(tree.name, packge); packge.members().enterIfAbsent(c); if ((tree.mods.flags & PUBLIC) != 0 && !classNameMatchesFileName(c, env)) { log.error(tree.pos(),
q.flags_field |= EXISTS; c = reader.enterClass(tree.name, packge); packge.members().enterIfAbsent(c); if ((tree.mods.flags & PUBLIC) != 0 && !classNameMatchesFileName(c, env)) { log.error(tree.pos(),
else if (sym.kind < bestSoFar.kind) bestSoFar = sym; sym = findGlobalType(env, env.toplevel.packge.members(), name); if (sym.exists()) return sym; else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
else if (sym.kind < bestSoFar.kind) bestSoFar = sym; sym = findGlobalType(env, env.toplevel.packge.members(), name); if (sym.exists()) return sym; else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
else if (sym.kind < bestSoFar.kind) bestSoFar = sym; sym = findGlobalType(env, env.toplevel.packge.members(), name); if (sym.exists()) return sym; else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
else if (sym.kind < bestSoFar.kind) bestSoFar = sym; sym = findGlobalType(env, env.toplevel.packge.members(), name); if (sym.exists()) return sym; else if (sym.kind < bestSoFar.kind) bestSoFar = sym;
e.next().scope == null; e = toplevel.packge.members().lookup(sym.name); if (e.scope != null) { return
e.next().scope == null; e = toplevel.packge.members().lookup(sym.name); if (e.scope != null) { return
/** Can given symbol be referred to in unqualified form? */ boolean isUnqualifiable(Symbol sym) { if (sym.name == names.empty || sym.owner == null || sym.owner.kind == MTH || sym.owner.kind == VAR) { return true; } else if (sym.kind == TYP && toplevel != null) { Scope.Entry e; e = toplevel.namedImportScope.lookup(sym.name); if (e.scope != null) { return e.sym == sym && e.next().scope == null; } e = toplevel.packge.members().lookup(sym.name); if (e.scope != null) { return e.sym == sym && e.next().scope == null; } e = toplevel.starImportScope.lookup(sym.name); if (e.scope != null) { return e.sym == sym && e.next().scope == null; } } return false; }
/** Can given symbol be referred to in unqualified form? */ boolean isUnqualifiable(Symbol sym) { if (sym.name == names.empty || sym.owner == null || sym.owner.kind == MTH || sym.owner.kind == VAR) { return true; } else if (sym.kind == TYP && toplevel != null) { Scope.Entry e; e = toplevel.namedImportScope.lookup(sym.name); if (e.scope != null) { return e.sym == sym && e.next().scope == null; } e = toplevel.packge.members().lookup(sym.name); if (e.scope != null) { return e.sym == sym && e.next().scope == null; } e = toplevel.starImportScope.lookup(sym.name); if (e.scope != null) { return e.sym == sym && e.next().scope == null; } } return false; }
/** * Returns a list of type symbols in the scope enclosing {@code env} guaranteeing that, when two * symbols share a simple name, the shadower precedes the shadow-ee */ private static Iterable<Symbol> typesInEnclosingScope( Env<AttrContext> env, PackageSymbol javaLang) { // Collect all visible type names declared in this source file by ascending lexical scopes // and excluding TypeVariableSymbols (otherwise, every type parameter spuriously shadows itself) Iterable<Symbol> localSymbolsInScope = Streams.stream(env) .map( ctx -> ctx.tree.getTag() == Tag.CLASSDEF ? ((ClassSymbol) ASTHelpers.getSymbol(ctx.tree)).members().getSymbols() : ctx.info.getLocalElements()) .flatMap( symbols -> Streams.stream(symbols).filter(sym -> !(sym instanceof TypeVariableSymbol))) .collect(ImmutableList.toImmutableList()); // Concatenate with all visible type names declared in other source files: // Ignore wildcard imports here since we don't use them and they can cause issues (b/109867096) return Iterables.concat( localSymbolsInScope, // Local symbols env.toplevel.namedImportScope.getSymbols(), // Explicitly named imports javaLang.members().getSymbols(), // implicitly imported java.lang.* symbols env.toplevel.packge.members().getSymbols()); // Siblings in class hierarchy }
/** * Return a list of all classes contained in this package, including * member classes of those classes, and their member classes, etc. */ private List<ClassDocImpl> getClasses(boolean filtered) { if (allClasses != null && !filtered) { return allClasses; } if (allClassesFiltered != null && filtered) { return allClassesFiltered; } ListBuffer<ClassDocImpl> classes = new ListBuffer<ClassDocImpl>(); for (Scope.Entry e = sym.members().elems; e != null; e = e.sibling) { if (e.sym != null) { ClassSymbol s = (ClassSymbol)e.sym; ClassDocImpl c = env.getClassDoc(s); if (c != null && !c.isSynthetic()) c.addAllClasses(classes, filtered); } } if (filtered) return allClassesFiltered = classes.toList(); else return allClasses = classes.toList(); }