src/share/classes/com/sun/tools/javac/util/AbstractLog.java

Tue, 07 Sep 2010 17:31:54 +0100

author
mcimadamore
date
Tue, 07 Sep 2010 17:31:54 +0100
changeset 673
7ae4016c5938
parent 612
d1bd93028447
child 726
2974d3800eb1
permissions
-rw-r--r--

6337171: javac should create bridge methods when type variable bounds restricted
Summary: javac should add synthetic overrides for inherited abstract methods in order to preserve binary compatibility
Reviewed-by: jjg

jjg@73 1 /*
ohair@554 2 * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
jjg@73 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@73 4 *
jjg@73 5 * This code is free software; you can redistribute it and/or modify it
jjg@73 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
jjg@73 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
jjg@73 10 *
jjg@73 11 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@73 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@73 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@73 14 * version 2 for more details (a copy is included in the LICENSE file that
jjg@73 15 * accompanied this code).
jjg@73 16 *
jjg@73 17 * You should have received a copy of the GNU General Public License version
jjg@73 18 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@73 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@73 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
jjg@73 24 */
jjg@73 25
jjg@73 26 package com.sun.tools.javac.util;
jjg@73 27
jjg@73 28 import java.util.HashMap;
jjg@73 29 import java.util.Map;
jjg@73 30 import javax.tools.JavaFileObject;
jjg@73 31
jjg@612 32 import com.sun.tools.javac.code.Lint.LintCategory;
jjg@73 33 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
jjg@73 34 import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition;
jjg@73 35
jjg@73 36
jjg@73 37 /**
jjg@73 38 * A base class for error logs. Reports errors and warnings, and
jjg@73 39 * keeps track of error numbers and positions.
jjg@73 40 *
jjg@581 41 * <p><b>This is NOT part of any supported API.
jjg@581 42 * If you write code that depends on this, you do so at your own risk.
jjg@73 43 * This code and its internal interfaces are subject to change or
jjg@73 44 * deletion without notice.</b>
jjg@73 45 */
jjg@73 46 public abstract class AbstractLog {
jjg@73 47 AbstractLog(JCDiagnostic.Factory diags) {
jjg@73 48 this.diags = diags;
jjg@73 49 sourceMap = new HashMap<JavaFileObject, DiagnosticSource>();
jjg@73 50 }
jjg@73 51
jjg@73 52 /** Re-assign source, returning previous setting.
jjg@73 53 */
jjg@73 54 public JavaFileObject useSource(JavaFileObject file) {
jjg@73 55 JavaFileObject prev = (source == null ? null : source.getFile());
jjg@73 56 source = getSource(file);
jjg@73 57 return prev;
jjg@73 58 }
jjg@73 59
jjg@73 60 protected DiagnosticSource getSource(JavaFileObject file) {
jjg@73 61 if (file == null)
mcimadamore@303 62 return DiagnosticSource.NO_SOURCE;
jjg@73 63 DiagnosticSource s = sourceMap.get(file);
jjg@73 64 if (s == null) {
jjg@73 65 s = new DiagnosticSource(file, this);
jjg@73 66 sourceMap.put(file, s);
jjg@73 67 }
jjg@73 68 return s;
jjg@73 69 }
jjg@73 70
mcimadamore@168 71 /** Return the underlying diagnostic source
mcimadamore@168 72 */
mcimadamore@168 73 public DiagnosticSource currentSource() {
mcimadamore@168 74 return source;
mcimadamore@168 75 }
mcimadamore@168 76
jjg@73 77 /** Report an error, unless another error was already reported at same
jjg@73 78 * source position.
jjg@73 79 * @param key The key for the localized error message.
jjg@73 80 * @param args Fields of the error message.
jjg@73 81 */
jjg@73 82 public void error(String key, Object ... args) {
jjg@73 83 report(diags.error(source, null, key, args));
jjg@73 84 }
jjg@73 85
jjg@73 86 /** Report an error, unless another error was already reported at same
jjg@73 87 * source position.
jjg@73 88 * @param pos The source position at which to report the error.
jjg@73 89 * @param key The key for the localized error message.
jjg@73 90 * @param args Fields of the error message.
jjg@73 91 */
jjg@73 92 public void error(DiagnosticPosition pos, String key, Object ... args) {
jjg@73 93 report(diags.error(source, pos, key, args));
jjg@73 94 }
jjg@73 95
jjg@73 96 /** Report an error, unless another error was already reported at same
jjg@73 97 * source position.
jjg@73 98 * @param pos The source position at which to report the error.
jjg@73 99 * @param key The key for the localized error message.
jjg@73 100 * @param args Fields of the error message.
jjg@73 101 */
jjg@73 102 public void error(int pos, String key, Object ... args) {
jjg@73 103 report(diags.error(source, wrap(pos), key, args));
jjg@73 104 }
jjg@73 105
jjg@73 106 /** Report a warning, unless suppressed by the -nowarn option or the
jjg@73 107 * maximum number of warnings has been reached.
jjg@73 108 * @param pos The source position at which to report the warning.
jjg@73 109 * @param key The key for the localized warning message.
jjg@73 110 * @param args Fields of the warning message.
jjg@73 111 */
jjg@73 112 public void warning(String key, Object ... args) {
jjg@73 113 report(diags.warning(source, null, key, args));
jjg@73 114 }
jjg@73 115
jjg@612 116 /** Report a lint warning, unless suppressed by the -nowarn option or the
jjg@612 117 * maximum number of warnings has been reached.
jjg@612 118 * @param lc The lint category for the diagnostic
jjg@612 119 * @param key The key for the localized warning message.
jjg@612 120 * @param args Fields of the warning message.
jjg@612 121 */
jjg@612 122 public void warning(LintCategory lc, String key, Object ... args) {
jjg@612 123 report(diags.warning(lc, key, args));
jjg@612 124 }
jjg@612 125
jjg@73 126 /** Report a warning, unless suppressed by the -nowarn option or the
jjg@73 127 * maximum number of warnings has been reached.
jjg@73 128 * @param pos The source position at which to report the warning.
jjg@73 129 * @param key The key for the localized warning message.
jjg@73 130 * @param args Fields of the warning message.
jjg@73 131 */
jjg@73 132 public void warning(DiagnosticPosition pos, String key, Object ... args) {
jjg@73 133 report(diags.warning(source, pos, key, args));
jjg@73 134 }
jjg@73 135
jjg@612 136 /** Report a lint warning, unless suppressed by the -nowarn option or the
jjg@612 137 * maximum number of warnings has been reached.
jjg@612 138 * @param lc The lint category for the diagnostic
jjg@612 139 * @param pos The source position at which to report the warning.
jjg@612 140 * @param key The key for the localized warning message.
jjg@612 141 * @param args Fields of the warning message.
jjg@612 142 */
jjg@612 143 public void warning(LintCategory lc, DiagnosticPosition pos, String key, Object ... args) {
jjg@612 144 report(diags.warning(lc, source, pos, key, args));
jjg@612 145 }
jjg@612 146
jjg@73 147 /** Report a warning, unless suppressed by the -nowarn option or the
jjg@73 148 * maximum number of warnings has been reached.
jjg@73 149 * @param pos The source position at which to report the warning.
jjg@73 150 * @param key The key for the localized warning message.
jjg@73 151 * @param args Fields of the warning message.
jjg@73 152 */
jjg@73 153 public void warning(int pos, String key, Object ... args) {
jjg@73 154 report(diags.warning(source, wrap(pos), key, args));
jjg@73 155 }
jjg@73 156
jjg@73 157 /** Report a warning.
jjg@73 158 * @param pos The source position at which to report the warning.
jjg@73 159 * @param key The key for the localized warning message.
jjg@73 160 * @param args Fields of the warning message.
jjg@73 161 */
jjg@73 162 public void mandatoryWarning(DiagnosticPosition pos, String key, Object ... args) {
jjg@73 163 report(diags.mandatoryWarning(source, pos, key, args));
jjg@73 164 }
jjg@73 165
jjg@612 166 /** Report a warning.
jjg@612 167 * @param lc The lint category for the diagnostic
jjg@612 168 * @param pos The source position at which to report the warning.
jjg@612 169 * @param key The key for the localized warning message.
jjg@612 170 * @param args Fields of the warning message.
jjg@612 171 */
jjg@612 172 public void mandatoryWarning(LintCategory lc, DiagnosticPosition pos, String key, Object ... args) {
jjg@612 173 report(diags.mandatoryWarning(lc, source, pos, key, args));
jjg@612 174 }
jjg@612 175
jjg@73 176 /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
jjg@73 177 * @param key The key for the localized notification message.
jjg@73 178 * @param args Fields of the notint an error or warning message:
jjg@73 179 */
jjg@73 180 public void note(String key, Object ... args) {
jjg@73 181 report(diags.note(source, null, key, args));
jjg@73 182 }
jjg@73 183
jjg@73 184 /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
jjg@73 185 * @param key The key for the localized notification message.
jjg@73 186 * @param args Fields of the notification message.
jjg@73 187 */
jjg@73 188 public void note(DiagnosticPosition pos, String key, Object ... args) {
jjg@73 189 report(diags.note(source, pos, key, args));
jjg@73 190 }
jjg@73 191
jjg@73 192 /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
jjg@73 193 * @param key The key for the localized notification message.
jjg@73 194 * @param args Fields of the notification message.
jjg@73 195 */
jjg@73 196 public void note(int pos, String key, Object ... args) {
jjg@73 197 report(diags.note(source, wrap(pos), key, args));
jjg@73 198 }
jjg@73 199
jjg@73 200 /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
jjg@73 201 * @param key The key for the localized notification message.
jjg@73 202 * @param args Fields of the notification message.
jjg@73 203 */
jjg@73 204 public void note(JavaFileObject file, String key, Object ... args) {
jjg@73 205 report(diags.note(getSource(file), null, key, args));
jjg@73 206 }
jjg@73 207
jjg@73 208 /** Provide a non-fatal notification, unless suppressed by the -nowarn option.
jjg@73 209 * @param key The key for the localized notification message.
jjg@73 210 * @param args Fields of the notification message.
jjg@73 211 */
jjg@73 212 public void mandatoryNote(final JavaFileObject file, String key, Object ... args) {
jjg@73 213 report(diags.mandatoryNote(getSource(file), key, args));
jjg@73 214 }
jjg@73 215
jjg@73 216 protected abstract void report(JCDiagnostic diagnostic);
jjg@73 217
jjg@73 218 protected abstract void directError(String key, Object... args);
jjg@73 219
jjg@73 220 private DiagnosticPosition wrap(int pos) {
jjg@73 221 return (pos == Position.NOPOS ? null : new SimpleDiagnosticPosition(pos));
jjg@73 222 }
jjg@73 223
jjg@73 224 /** Factory for diagnostics
jjg@73 225 */
jjg@73 226 protected JCDiagnostic.Factory diags;
jjg@73 227
jjg@73 228 /** The file that's currently being translated.
jjg@73 229 */
jjg@73 230 protected DiagnosticSource source;
jjg@73 231
jjg@73 232 /** A cache of lightweight DiagnosticSource objects.
jjg@73 233 */
jjg@73 234 protected Map<JavaFileObject, DiagnosticSource> sourceMap;
jjg@73 235 }

mercurial