mcimadamore@852: /* jjg@1357: * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. mcimadamore@852: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. mcimadamore@852: * mcimadamore@852: * This code is free software; you can redistribute it and/or modify it mcimadamore@852: * under the terms of the GNU General Public License version 2 only, as mcimadamore@852: * published by the Free Software Foundation. Oracle designates this mcimadamore@852: * particular file as subject to the "Classpath" exception as provided mcimadamore@852: * by Oracle in the LICENSE file that accompanied this code. mcimadamore@852: * mcimadamore@852: * This code is distributed in the hope that it will be useful, but WITHOUT mcimadamore@852: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or mcimadamore@852: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License mcimadamore@852: * version 2 for more details (a copy is included in the LICENSE file that mcimadamore@852: * accompanied this code). mcimadamore@852: * mcimadamore@852: * You should have received a copy of the GNU General Public License version mcimadamore@852: * 2 along with this work; if not, write to the Free Software Foundation, mcimadamore@852: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. mcimadamore@852: * mcimadamore@852: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA mcimadamore@852: * or visit www.oracle.com if you need additional information or have any mcimadamore@852: * questions. mcimadamore@852: */ mcimadamore@852: mcimadamore@852: package com.sun.tools.javac.code; mcimadamore@852: mcimadamore@852: import java.util.HashMap; mcimadamore@852: import java.util.Map; mcimadamore@852: mcimadamore@852: import com.sun.tools.javac.util.Assert; mcimadamore@852: import com.sun.tools.javac.util.Context; jjg@1357: import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; mcimadamore@852: import com.sun.tools.javac.util.ListBuffer; mcimadamore@852: mcimadamore@852: /** mcimadamore@852: * mcimadamore@852: *

This is NOT part of any supported API. mcimadamore@852: * If you write code that depends on this, you do so at your own risk. mcimadamore@852: * This code and its internal interfaces are subject to change or mcimadamore@852: * deletion without notice. mcimadamore@852: */ mcimadamore@852: public class DeferredLintHandler { mcimadamore@852: protected static final Context.Key deferredLintHandlerKey = mcimadamore@852: new Context.Key(); mcimadamore@852: mcimadamore@852: public static DeferredLintHandler instance(Context context) { mcimadamore@852: DeferredLintHandler instance = context.get(deferredLintHandlerKey); mcimadamore@852: if (instance == null) mcimadamore@852: instance = new DeferredLintHandler(context); mcimadamore@852: return instance; mcimadamore@852: } mcimadamore@852: mcimadamore@852: protected DeferredLintHandler(Context context) { mcimadamore@852: context.put(deferredLintHandlerKey, this); mcimadamore@852: } mcimadamore@852: mcimadamore@852: private DeferredLintHandler() {} mcimadamore@852: mcimadamore@852: public interface LintLogger { mcimadamore@852: void report(); mcimadamore@852: } mcimadamore@852: mcimadamore@852: private DiagnosticPosition currentPos; mcimadamore@852: private Map> loggersQueue = new HashMap>(); mcimadamore@852: mcimadamore@852: public void report(LintLogger logger) { mcimadamore@852: ListBuffer loggers = loggersQueue.get(currentPos); mcimadamore@852: Assert.checkNonNull(loggers); mcimadamore@852: loggers.append(logger); mcimadamore@852: } mcimadamore@852: mcimadamore@852: public void flush(DiagnosticPosition pos) { mcimadamore@852: ListBuffer loggers = loggersQueue.get(pos); mcimadamore@852: if (loggers != null) { mcimadamore@852: for (LintLogger lintLogger : loggers) { mcimadamore@852: lintLogger.report(); mcimadamore@852: } mcimadamore@852: loggersQueue.remove(pos); mcimadamore@852: } mcimadamore@852: } mcimadamore@852: mcimadamore@852: public DeferredLintHandler setPos(DiagnosticPosition currentPos) { mcimadamore@852: this.currentPos = currentPos; mcimadamore@852: loggersQueue.put(currentPos, ListBuffer.lb()); mcimadamore@852: return this; mcimadamore@852: } mcimadamore@852: mcimadamore@852: public static final DeferredLintHandler immediateHandler = new DeferredLintHandler() { mcimadamore@852: @Override mcimadamore@852: public void report(LintLogger logger) { mcimadamore@852: logger.report(); mcimadamore@852: } mcimadamore@852: }; mcimadamore@852: }