langtools/src/share/classes/com/sun/tools/javac/code/DeferredLintHandler.java
author rfield
Fri, 15 Feb 2013 18:40:38 -0800
changeset 16300 7cf27559c8df
parent 14258 8d2148961366
child 19942 e9dae0e41075
permissions -rw-r--r--
8004969: Generate $deserializeLambda$ method 8006763: super in method reference used in anonymous class - ClassFormatError is produced 8005632: Inner classes within lambdas cause build failures 8005653: Lambdas containing inner classes referencing external type variables do not correctly parameterize the inner classes Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8236
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
     1
/*
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 8236
diff changeset
     2
 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
8236
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
     4
 *
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    10
 *
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    15
 * accompanied this code).
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    16
 *
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    20
 *
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    23
 * questions.
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    24
 */
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    25
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    26
package com.sun.tools.javac.code;
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    27
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    28
import java.util.HashMap;
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    29
import java.util.Map;
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    30
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    31
import com.sun.tools.javac.util.Assert;
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    32
import com.sun.tools.javac.util.Context;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 8236
diff changeset
    33
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
8236
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    34
import com.sun.tools.javac.util.ListBuffer;
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    35
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    36
/**
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    37
 *
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    38
 * <p><b>This is NOT part of any supported API.
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    39
 * If you write code that depends on this, you do so at your own risk.
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    40
 * This code and its internal interfaces are subject to change or
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    41
 * deletion without notice.</b>
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    42
 */
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    43
public class DeferredLintHandler {
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    44
    protected static final Context.Key<DeferredLintHandler> deferredLintHandlerKey =
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    45
        new Context.Key<DeferredLintHandler>();
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    46
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    47
    public static DeferredLintHandler instance(Context context) {
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    48
        DeferredLintHandler instance = context.get(deferredLintHandlerKey);
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    49
        if (instance == null)
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    50
            instance = new DeferredLintHandler(context);
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    51
        return instance;
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    52
    }
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    53
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    54
    protected DeferredLintHandler(Context context) {
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    55
        context.put(deferredLintHandlerKey, this);
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    56
    }
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    57
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    58
    private DeferredLintHandler() {}
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    59
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    60
    public interface LintLogger {
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    61
        void report();
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    62
    }
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    63
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    64
    private DiagnosticPosition currentPos;
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    65
    private Map<DiagnosticPosition, ListBuffer<LintLogger>> loggersQueue = new HashMap<DiagnosticPosition, ListBuffer<LintLogger>>();
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    66
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    67
    public void report(LintLogger logger) {
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    68
        ListBuffer<LintLogger> loggers = loggersQueue.get(currentPos);
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    69
        Assert.checkNonNull(loggers);
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    70
        loggers.append(logger);
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    71
    }
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    72
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    73
    public void flush(DiagnosticPosition pos) {
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    74
        ListBuffer<LintLogger> loggers = loggersQueue.get(pos);
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    75
        if (loggers != null) {
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    76
            for (LintLogger lintLogger : loggers) {
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    77
                lintLogger.report();
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    78
            }
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    79
            loggersQueue.remove(pos);
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    80
        }
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    81
    }
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    82
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    83
    public DeferredLintHandler setPos(DiagnosticPosition currentPos) {
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    84
        this.currentPos = currentPos;
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    85
        loggersQueue.put(currentPos, ListBuffer.<LintLogger>lb());
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    86
        return this;
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    87
    }
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    88
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    89
    public static final DeferredLintHandler immediateHandler = new DeferredLintHandler() {
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    90
        @Override
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    91
        public void report(LintLogger logger) {
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    92
            logger.report();
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    93
        }
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    94
    };
0d8646b7c602 6594914: @SuppressWarnings("deprecation") does not not work for the type of a variable
mcimadamore
parents:
diff changeset
    95
}