public List<A> intersect(List<A> that) { ListBuffer<A> buf = ListBuffer.lb(); for (A el : this) { if (that.contains(el)) { buf.append(el); } } return buf.toList(); }
void run(Queue<Env<AttrContext>> list, Iterable<? extends TypeElement> classes) { Set<TypeElement> set = new HashSet<TypeElement>(); for (TypeElement item : classes) set.add(item); ListBuffer<Env<AttrContext>> defer = ListBuffer.<Env<AttrContext>>lb(); while (list.peek() != null) { Env<AttrContext> env = list.remove(); ClassSymbol csym = env.enclClass.sym; if (csym != null && set.contains(csym.outermostClass())) process(env); else defer = defer.append(env); } list.addAll(defer); }
/** * A DiagnosticHandler that can defer some or all diagnostics, by buffering them for later * examination and/or reporting. If a diagnostic is not deferred, or is subsequently reported with * reportAllDiagnostics(), it will be reported to the previously active diagnostic handler. */ public static class DeferredDiagnosticHandler extends DiagnosticHandler { private Queue<JCDiagnostic> deferred = ListBuffer.lb(); private final Filter<JCDiagnostic> filter; public DeferredDiagnosticHandler(Log log) { this(log, null); } public DeferredDiagnosticHandler(Log log, Filter<JCDiagnostic> filter) { this.filter = filter; install(log); } public void report(JCDiagnostic diag) { if (filter == null || filter.accepts(diag)) deferred.add(diag); else prev.report(diag); } public Queue<JCDiagnostic> getDiagnostics() { return deferred; } /** Report all deferred diagnostics. */ public void reportDeferredDiagnostics() { reportDeferredDiagnostics(EnumSet.allOf(JCDiagnostic.Kind.class)); } /** Report selected deferred diagnostics. */ public void reportDeferredDiagnostics(Set<JCDiagnostic.Kind> kinds) { JCDiagnostic d; while ((d = deferred.poll()) != null) { if (kinds.contains(d.getKind())) prev.report(d); } deferred = null; // prevent accidental ongoing use } }