public void printScope(String label, Scope scope, Details details) { if (scope == null) { printNull(label); } else { switch (details) { case SUMMARY: { indent(); out.print(label); out.print(": ["); String sep = ""; for (Symbol sym : scope.getSymbols()) { out.print(sep); out.print(sym.name); sep = ","; } out.println("]"); break; } case FULL: { indent(); out.println(label); indent(+1); printFullScopeImpl(scope); indent(-1); break; } } } }
/** @return all values of the given enum type, in declaration order. */ public static LinkedHashSet<String> enumValues(TypeSymbol enumType) { if (enumType.getKind() != ElementKind.ENUM) { throw new IllegalStateException(); } Scope scope = enumType.members(); Deque<String> values = new ArrayDeque<>(); for (Symbol sym : scope.getSymbols()) { if (sym instanceof VarSymbol) { VarSymbol var = (VarSymbol) sym; if ((var.flags() & Flags.ENUM) != 0) { /** * Javac gives us the members backwards, apparently. It's worth making an effort to * preserve declaration order because it's useful for diagnostics (e.g. in {@link * MissingCasesInEnumSwitch}). */ values.push(sym.name.toString()); } } } return new LinkedHashSet<>(values); }
void printFullScopeImpl(Scope scope) { indent(); out.println(scope.getClass().getName()); printSymbol("owner", scope.owner, Details.SUMMARY); if (SCOPE_IMPL_CLASS.equals(scope.getClass().getName())) { printScope("next", (Scope) getField(scope, scope.getClass(), "next"), Details.SUMMARY); printObject("shared", getField(scope, scope.getClass(), "shared"), Details.SUMMARY); Object[] table = (Object[]) getField(scope, scope.getClass(), "table"); for (int i = 0; i < table.length; i++) { if (i > 0) out.print(", "); else indent(); out.print(i + ":" + entryToString(table[i], table, false)); } out.println(); } else if (FILTER_SCOPE_CLASS.equals(scope.getClass().getName())) { printScope("origin", (Scope) getField(scope, scope.getClass(), "origin"), Details.FULL); } else if (scope instanceof CompoundScope) { printList("delegates", (List<?>) getField(scope, CompoundScope.class, "subScopes")); } else { for (Symbol sym : scope.getSymbols()) { printSymbol(sym.name.toString(), sym, Details.SUMMARY); } } }