Tue, 16 Jun 2009 10:46:37 +0100
6638712: Inference with wildcard types causes selection of inapplicable method
Summary: Added global sanity check in order to make sure that return type inference does not violate bounds constraints
Reviewed-by: jjg
mcimadamore@288 | 1 | /* |
mcimadamore@288 | 2 | * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. |
mcimadamore@288 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
mcimadamore@288 | 4 | * |
mcimadamore@288 | 5 | * This code is free software; you can redistribute it and/or modify it |
mcimadamore@288 | 6 | * under the terms of the GNU General Public License version 2 only, as |
mcimadamore@288 | 7 | * published by the Free Software Foundation. Sun designates this |
mcimadamore@288 | 8 | * particular file as subject to the "Classpath" exception as provided |
mcimadamore@288 | 9 | * by Sun in the LICENSE file that accompanied this code. |
mcimadamore@288 | 10 | * |
mcimadamore@288 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
mcimadamore@288 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mcimadamore@288 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
mcimadamore@288 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
mcimadamore@288 | 15 | * accompanied this code). |
mcimadamore@288 | 16 | * |
mcimadamore@288 | 17 | * You should have received a copy of the GNU General Public License version |
mcimadamore@288 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
mcimadamore@288 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
mcimadamore@288 | 20 | * |
mcimadamore@288 | 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
mcimadamore@288 | 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
mcimadamore@288 | 23 | * have any questions. |
mcimadamore@288 | 24 | */ |
mcimadamore@288 | 25 | package com.sun.tools.javac.util; |
mcimadamore@288 | 26 | |
mcimadamore@288 | 27 | import java.util.Set; |
mcimadamore@288 | 28 | import java.util.Locale; |
mcimadamore@288 | 29 | import javax.tools.Diagnostic; |
mcimadamore@288 | 30 | |
mcimadamore@288 | 31 | import com.sun.tools.javac.api.DiagnosticFormatter; |
mcimadamore@288 | 32 | import com.sun.tools.javac.api.DiagnosticFormatter.Configuration; |
mcimadamore@288 | 33 | import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.DiagnosticPart; |
mcimadamore@288 | 34 | import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.MultilineLimit; |
mcimadamore@288 | 35 | import com.sun.tools.javac.api.DiagnosticFormatter.PositionKind; |
mcimadamore@288 | 36 | |
mcimadamore@288 | 37 | /** |
mcimadamore@288 | 38 | * A delegated diagnostic formatter delegates all formatting |
mcimadamore@288 | 39 | * actions to an underlying formatter (aka the delegated formatter). |
mcimadamore@288 | 40 | */ |
mcimadamore@288 | 41 | public class ForwardingDiagnosticFormatter<D extends Diagnostic<?>, F extends DiagnosticFormatter<D>> |
mcimadamore@288 | 42 | implements DiagnosticFormatter<D> { |
mcimadamore@288 | 43 | |
mcimadamore@288 | 44 | /** |
mcimadamore@288 | 45 | * The delegated formatter |
mcimadamore@288 | 46 | */ |
mcimadamore@288 | 47 | protected F formatter; |
mcimadamore@288 | 48 | |
mcimadamore@288 | 49 | /* |
mcimadamore@288 | 50 | * configuration object used by this formatter |
mcimadamore@288 | 51 | */ |
mcimadamore@288 | 52 | protected ForwardingConfiguration configuration; |
mcimadamore@288 | 53 | |
mcimadamore@288 | 54 | public ForwardingDiagnosticFormatter(F formatter) { |
mcimadamore@288 | 55 | this.formatter = formatter; |
mcimadamore@288 | 56 | this.configuration = new ForwardingConfiguration(formatter.getConfiguration()); |
mcimadamore@288 | 57 | } |
mcimadamore@288 | 58 | |
mcimadamore@288 | 59 | /** |
mcimadamore@288 | 60 | * Returns the underlying delegated formatter |
mcimadamore@288 | 61 | * @return delegate formatter |
mcimadamore@288 | 62 | */ |
mcimadamore@288 | 63 | public F getDelegatedFormatter() { |
mcimadamore@288 | 64 | return formatter; |
mcimadamore@288 | 65 | } |
mcimadamore@288 | 66 | |
mcimadamore@288 | 67 | public Configuration getConfiguration() { |
mcimadamore@288 | 68 | return configuration; |
mcimadamore@288 | 69 | } |
mcimadamore@288 | 70 | |
mcimadamore@288 | 71 | public boolean displaySource(D diag) { |
mcimadamore@288 | 72 | return formatter.displaySource(diag); |
mcimadamore@288 | 73 | } |
mcimadamore@288 | 74 | |
mcimadamore@288 | 75 | public String format(D diag, Locale l) { |
mcimadamore@288 | 76 | return formatter.format(diag, l); |
mcimadamore@288 | 77 | } |
mcimadamore@288 | 78 | |
mcimadamore@288 | 79 | public String formatKind(D diag, Locale l) { |
mcimadamore@288 | 80 | return formatter.formatKind(diag, l); |
mcimadamore@288 | 81 | } |
mcimadamore@288 | 82 | |
mcimadamore@288 | 83 | public String formatMessage(D diag, Locale l) { |
mcimadamore@288 | 84 | return formatter.formatMessage(diag, l); |
mcimadamore@288 | 85 | } |
mcimadamore@288 | 86 | |
mcimadamore@288 | 87 | public String formatPosition(D diag, PositionKind pk, Locale l) { |
mcimadamore@288 | 88 | return formatter.formatPosition(diag, pk, l); |
mcimadamore@288 | 89 | } |
mcimadamore@288 | 90 | |
mcimadamore@288 | 91 | public String formatSource(D diag, boolean fullname, Locale l) { |
mcimadamore@288 | 92 | return formatter.formatSource(diag, fullname, l); |
mcimadamore@288 | 93 | } |
mcimadamore@288 | 94 | |
mcimadamore@288 | 95 | /** |
mcimadamore@288 | 96 | * A delegated formatter configuration delegates all configurations settings |
mcimadamore@288 | 97 | * to an underlying configuration object (aka the delegated configuration). |
mcimadamore@288 | 98 | */ |
mcimadamore@288 | 99 | public static class ForwardingConfiguration implements DiagnosticFormatter.Configuration { |
mcimadamore@288 | 100 | |
mcimadamore@288 | 101 | /** The configurationr object to which the forwarding configuration delegates some settings */ |
mcimadamore@288 | 102 | protected Configuration configuration; |
mcimadamore@288 | 103 | |
mcimadamore@288 | 104 | public ForwardingConfiguration(Configuration configuration) { |
mcimadamore@288 | 105 | this.configuration = configuration; |
mcimadamore@288 | 106 | } |
mcimadamore@288 | 107 | |
mcimadamore@288 | 108 | /** |
mcimadamore@288 | 109 | * Returns the underlying delegated configuration. |
mcimadamore@288 | 110 | * @return delegated configuration |
mcimadamore@288 | 111 | */ |
mcimadamore@288 | 112 | public Configuration getDelegatedConfiguration() { |
mcimadamore@288 | 113 | return configuration; |
mcimadamore@288 | 114 | } |
mcimadamore@288 | 115 | |
mcimadamore@288 | 116 | public int getMultilineLimit(MultilineLimit limit) { |
mcimadamore@288 | 117 | return configuration.getMultilineLimit(limit); |
mcimadamore@288 | 118 | } |
mcimadamore@288 | 119 | |
mcimadamore@288 | 120 | public Set<DiagnosticPart> getVisible() { |
mcimadamore@288 | 121 | return configuration.getVisible(); |
mcimadamore@288 | 122 | } |
mcimadamore@288 | 123 | |
mcimadamore@288 | 124 | public void setMultilineLimit(MultilineLimit limit, int value) { |
mcimadamore@288 | 125 | configuration.setMultilineLimit(limit, value); |
mcimadamore@288 | 126 | } |
mcimadamore@288 | 127 | |
mcimadamore@288 | 128 | public void setVisible(Set<DiagnosticPart> diagParts) { |
mcimadamore@288 | 129 | configuration.setVisible(diagParts); |
mcimadamore@288 | 130 | } |
mcimadamore@288 | 131 | } |
mcimadamore@288 | 132 | } |