提交 d154c628 编写于 作者: M mcimadamore

6722234: javac diagnostics need better integration with the type-system

Summary: Added RichDiagnosticFormatter which provides better formatting capabilities for javac types/symbols
Reviewed-by: jjg
上级 cab72098
......@@ -43,6 +43,9 @@ import static com.sun.tools.javac.code.Flags.*;
*/
public abstract class Printer implements Type.Visitor<String, Locale>, Symbol.Visitor<String, Locale> {
List<Type> seenCaptured = List.nil();
static final int PRIME = 997; // largest prime less than 1000
/**
* This method should be overriden in order to provide proper i18n support.
*
......@@ -54,7 +57,18 @@ public abstract class Printer implements Type.Visitor<String, Locale>, Symbol.Vi
protected abstract String localize(Locale locale, String key, Object... args);
/**
* Create a printer with default i18n support provided my Messages.
* Maps a captured type into an unique identifier.
*
* @param t the captured type for which an id is to be retrieved
* @param locale locale settings
* @return unique id representing this captured type
*/
protected abstract String capturedVarId(CapturedType t, Locale locale);
/**
* Create a printer with default i18n support provided by Messages. By default,
* captured types ids are generated using hashcode.
*
* @param messages Messages class to be used for i18n
* @return printer visitor instance
*/
......@@ -63,6 +77,11 @@ public abstract class Printer implements Type.Visitor<String, Locale>, Symbol.Vi
@Override
protected String localize(Locale locale, String key, Object... args) {
return messages.getLocalizedString(locale, key, args);
}
@Override
protected String capturedVarId(CapturedType t, Locale locale) {
return (t.hashCode() & 0xFFFFFFFFL) % PRIME + "";
}};
}
......@@ -120,9 +139,20 @@ public abstract class Printer implements Type.Visitor<String, Locale>, Symbol.Vi
@Override
public String visitCapturedType(CapturedType t, Locale locale) {
return localize(locale, "compiler.misc.type.captureof",
(t.hashCode() & 0xFFFFFFFFL) % Type.CapturedType.PRIME,
visit(t.wildcard, locale));
if (seenCaptured.contains(t))
return localize(locale, "compiler.misc.type.captureof.1",
capturedVarId(t, locale));
else {
try {
seenCaptured = seenCaptured.prepend(t);
return localize(locale, "compiler.misc.type.captureof",
capturedVarId(t, locale),
visit(t.wildcard, locale));
}
finally {
seenCaptured = seenCaptured.tail;
}
}
}
@Override
......
......@@ -1008,11 +1008,10 @@ public class Type implements PrimitiveType {
@Override
public String toString() {
return "capture#"
+ (hashCode() & 0xFFFFFFFFL) % PRIME
+ (hashCode() & 0xFFFFFFFFL) % Printer.PRIME
+ " of "
+ wildcard;
}
static final int PRIME = 997; // largest prime less than 1000
}
public static abstract class DelegatedType extends Type {
......
......@@ -391,6 +391,8 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
(options.get("shouldStopPolicy") != null)
? CompileState.valueOf(options.get("shouldStopPolicy"))
: null;
if (options.get("oldDiags") == null)
log.setDiagnosticFormatter(RichDiagnosticFormatter.instance(context));
}
/* Switches:
......
......@@ -1165,3 +1165,64 @@ compiler.err.static.import.not.supported.in.source=\
compiler.err.enums.not.supported.in.source=\
enums are not supported in -source {0}\n\
(use -source 5 or higher to enable enums)
########################################
# Diagnostics for where clause implementation
# used by the RichDiagnosticFormatter.
########################################
compiler.misc.type.null=\
<null>
# X#n (where n is an int id) is disambiguated tvar name
compiler.misc.type.var=\
{0}#{1}
# CAP#n (where n is an int id) is an abbreviation for 'captured type'
compiler.misc.captured.type=\
CAP#{0}
# <INT#n> (where n is an int id) is an abbreviation for 'intersection type'
compiler.misc.intersection.type=\
INT#{0}
# where clause for captured type: contains upper ('extends {1}') and lower
# ('super {2}') bound along with the wildcard that generated this captured type ({3})
compiler.misc.where.captured=\
{0} extends {1} super: {2} from capture of {3}
# compact where clause for captured type: contains upper ('extends {1}') along
# with the wildcard that generated this captured type ({3})
compiler.misc.where.captured.1=\
{0} extends {1} from capture of {3}
# where clause for type variable: contains upper bound(s) ('extends {1}') along with
# the kindname ({2}) and location ({3}) in which the typevar has been declared
compiler.misc.where.typevar=\
{0} extends {1} declared in {2} {3}
# compact where clause for type variable: contains the kindname ({2}) and location ({3})
# in which the typevar has been declared
compiler.misc.where.typevar.1=\
{0} declared in {2} {3}
# where clause for type variable: contains all the upper bound(s) ('extends {1}')
# of this intersection type
compiler.misc.where.intersection=\
{0} extends {1}
### Where clause headers ###
compiler.misc.where.description.captured=\
where {0} is a fresh type-variable:
compiler.misc.where.description.typevar=\
where {0} is a type-variable:
compiler.misc.where.description.intersection=\
where {0} is an intersection type:
compiler.misc.where.description.captured.1=\
where {0} are fresh type-variables:
compiler.misc.where.description.typevar.1=\
where {0} are type-variables:
compiler.misc.where.description.intersection.1=\
where {0} are intersection types:
......@@ -77,9 +77,11 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
protected int depth = 0;
/**
* Printer instance to be used for formatting types/symbol
* All captured types that have been encountered during diagnostic formatting.
* This info is used by the FormatterPrinter in order to print friendly unique
* ids for captured types
*/
protected Printer printer;
private List<Type> allCaptured = List.nil();
/**
* Initialize an AbstractDiagnosticFormatter by setting its JavacMessages object.
......@@ -88,7 +90,6 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
protected AbstractDiagnosticFormatter(JavacMessages messages, SimpleConfiguration config) {
this.messages = messages;
this.config = config;
this.printer = new FormatterPrinter();
}
public String formatKind(JCDiagnostic d, Locale l) {
......@@ -104,7 +105,7 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
@Override
public String format(JCDiagnostic d, Locale locale) {
printer = new FormatterPrinter();
allCaptured = List.nil();
return formatDiagnostic(d, locale);
}
......@@ -171,6 +172,9 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
return formatIterable(d, (Iterable<?>)arg, l);
}
else if (arg instanceof Type) {
if (!allCaptured.contains(arg)) {
allCaptured = allCaptured.append((Type)arg);
}
return printer.visit((Type)arg, l);
}
else if (arg instanceof Symbol) {
......@@ -291,6 +295,10 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
d.getIntPosition() != Position.NOPOS;
}
public boolean isRaw() {
return false;
}
/**
* Creates a string with a given amount of empty spaces. Useful for
* indenting the text of a diagnostic message.
......@@ -355,26 +363,26 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
String showSource = null;
if ((showSource = options.get("showSource")) != null) {
if (showSource.equals("true"))
visibleParts.add(DiagnosticPart.SOURCE);
setVisiblePart(DiagnosticPart.SOURCE, true);
else if (showSource.equals("false"))
visibleParts.remove(DiagnosticPart.SOURCE);
setVisiblePart(DiagnosticPart.SOURCE, false);
}
String diagOpts = options.get("diags");
if (diagOpts != null) {//override -XDshowSource
Collection<String> args = Arrays.asList(diagOpts.split(","));
if (args.contains("short")) {
visibleParts.remove(DiagnosticPart.DETAILS);
visibleParts.remove(DiagnosticPart.SUBDIAGNOSTICS);
setVisiblePart(DiagnosticPart.DETAILS, false);
setVisiblePart(DiagnosticPart.SUBDIAGNOSTICS, false);
}
if (args.contains("source"))
visibleParts.add(DiagnosticPart.SOURCE);
setVisiblePart(DiagnosticPart.SOURCE, true);
if (args.contains("-source"))
visibleParts.remove(DiagnosticPart.SOURCE);
setVisiblePart(DiagnosticPart.SOURCE, false);
}
String multiPolicy = null;
if ((multiPolicy = options.get("multilinePolicy")) != null) {
if (multiPolicy.equals("disabled"))
visibleParts.remove(DiagnosticPart.SUBDIAGNOSTICS);
setVisiblePart(DiagnosticPart.SUBDIAGNOSTICS, false);
else if (multiPolicy.startsWith("limit:")) {
String limitString = multiPolicy.substring("limit:".length());
String[] limits = limitString.split(":");
......@@ -421,6 +429,13 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
visibleParts = EnumSet.copyOf(diagParts);
}
public void setVisiblePart(DiagnosticPart diagParts, boolean enabled) {
if (enabled)
visibleParts.add(diagParts);
else
visibleParts.remove(diagParts);
}
/**
* Shows a '^' sign under the source line displayed by the formatter
* (if applicable).
......@@ -441,6 +456,14 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
}
}
public Printer getPrinter() {
return printer;
}
public void setPrinter(Printer printer) {
this.printer = printer;
}
/**
* An enhanced printer for formatting types/symbols used by
* AbstractDiagnosticFormatter. Provides alternate numbering of captured
......@@ -450,33 +473,14 @@ public abstract class AbstractDiagnosticFormatter implements DiagnosticFormatter
* type referred by a given captured type C contains C itself) which might
* lead to infinite loops.
*/
protected class FormatterPrinter extends Printer {
List<Type> allCaptured = List.nil();
List<Type> seenCaptured = List.nil();
protected Printer printer = new Printer() {
@Override
protected String localize(Locale locale, String key, Object... args) {
return AbstractDiagnosticFormatter.this.localize(locale, key, args);
}
@Override
public String visitCapturedType(CapturedType t, Locale locale) {
if (seenCaptured.contains(t))
return localize(locale, "compiler.misc.type.captureof.1",
allCaptured.indexOf(t) + 1);
else {
try {
seenCaptured = seenCaptured.prepend(t);
allCaptured = allCaptured.append(t);
return localize(locale, "compiler.misc.type.captureof",
allCaptured.indexOf(t) + 1,
visit(t.wildcard, locale));
}
finally {
seenCaptured = seenCaptured.tail;
}
}
protected String capturedVarId(CapturedType t, Locale locale) {
return "" + (allCaptured.indexOf(t) + 1);
}
}
};
}
......@@ -209,6 +209,7 @@ public class BasicDiagnosticFormatter extends AbstractDiagnosticFormatter {
@Override
public BasicConfiguration getConfiguration() {
//the following cast is always safe - see init
return (BasicConfiguration)super.getConfiguration();
}
......
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.tools.javac.util;
import java.util.Set;
import java.util.Locale;
import javax.tools.Diagnostic;
import com.sun.tools.javac.api.DiagnosticFormatter;
import com.sun.tools.javac.api.DiagnosticFormatter.Configuration;
import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.DiagnosticPart;
import com.sun.tools.javac.api.DiagnosticFormatter.Configuration.MultilineLimit;
import com.sun.tools.javac.api.DiagnosticFormatter.PositionKind;
/**
* A delegated diagnostic formatter delegates all formatting
* actions to an underlying formatter (aka the delegated formatter).
*/
public class ForwardingDiagnosticFormatter<D extends Diagnostic<?>, F extends DiagnosticFormatter<D>>
implements DiagnosticFormatter<D> {
/**
* The delegated formatter
*/
protected F formatter;
/*
* configuration object used by this formatter
*/
protected ForwardingConfiguration configuration;
public ForwardingDiagnosticFormatter(F formatter) {
this.formatter = formatter;
this.configuration = new ForwardingConfiguration(formatter.getConfiguration());
}
/**
* Returns the underlying delegated formatter
* @return delegate formatter
*/
public F getDelegatedFormatter() {
return formatter;
}
public Configuration getConfiguration() {
return configuration;
}
public boolean displaySource(D diag) {
return formatter.displaySource(diag);
}
public String format(D diag, Locale l) {
return formatter.format(diag, l);
}
public String formatKind(D diag, Locale l) {
return formatter.formatKind(diag, l);
}
public String formatMessage(D diag, Locale l) {
return formatter.formatMessage(diag, l);
}
public String formatPosition(D diag, PositionKind pk, Locale l) {
return formatter.formatPosition(diag, pk, l);
}
public String formatSource(D diag, boolean fullname, Locale l) {
return formatter.formatSource(diag, fullname, l);
}
/**
* A delegated formatter configuration delegates all configurations settings
* to an underlying configuration object (aka the delegated configuration).
*/
public static class ForwardingConfiguration implements DiagnosticFormatter.Configuration {
/** The configurationr object to which the forwarding configuration delegates some settings */
protected Configuration configuration;
public ForwardingConfiguration(Configuration configuration) {
this.configuration = configuration;
}
/**
* Returns the underlying delegated configuration.
* @return delegated configuration
*/
public Configuration getDelegatedConfiguration() {
return configuration;
}
public int getMultilineLimit(MultilineLimit limit) {
return configuration.getMultilineLimit(limit);
}
public Set<DiagnosticPart> getVisible() {
return configuration.getVisible();
}
public void setMultilineLimit(MultilineLimit limit, int value) {
configuration.setMultilineLimit(limit, value);
}
public void setVisible(Set<DiagnosticPart> diagParts) {
configuration.setVisible(diagParts);
}
}
}
......@@ -124,4 +124,9 @@ public final class RawDiagnosticFormatter extends AbstractDiagnosticFormatter {
}
return buf.toString();
}
@Override
public boolean isRaw() {
return true;
}
}
/*
* @test (important: no SCCS keywords to affect offsets in golden file.) /nodynamiccopyright/
* @bug 6304921
* @compile/fail/ref=T6304921.out -XDstdout -XDcompilePolicy=bytodo -XDdiags=%b:%s/%o/%e:%_%t%m|%p%m -Xjcov -Xlint:all,-path -Werror T6304921.java
* @compile/fail/ref=T6304921.out -XDstdout -XDcompilePolicy=bytodo -XDrawDiagnostics -Xjcov -Xlint:all,-path -Werror T6304921.java
*/
import java.util.ArrayList;
......
T6304921.java:671/671/680: warning: [rawtypes] found raw type: java.util.ArrayList
List<Integer> list = new ArrayList();
^
missing type parameters for generic class java.util.ArrayList<E>
T6304921.java:667/667/682: warning: [unchecked] unchecked conversion
List<Integer> list = new ArrayList();
^
required: java.util.List<java.lang.Integer>
found: java.util.ArrayList
error: warnings found and -Werror specified
T6304921.java:727/733/737: cannot find symbol
System.orr.println("abc"); // name not found
^
symbol: variable orr
location: class java.lang.System
T6304921.java:812/816/822: operator + cannot be applied to int,boolean
return 123 + true; // bad binary expression
^
T6304921.java:29:34: compiler.warn.raw.class.use: java.util.ArrayList, java.util.ArrayList<E>
T6304921.java:29:30: compiler.warn.prob.found.req: (compiler.misc.unchecked.assign), java.util.ArrayList, java.util.List<java.lang.Integer>
- compiler.err.warnings.and.werror
T6304921.java:35:15: compiler.err.cant.resolve.location: kindname.variable, orr, , , kindname.class, java.lang.System
T6304921.java:38:20: compiler.err.operator.cant.be.applied: +, int,boolean
3 errors
2 warnings
T6491592.java:12:11: compiler.err.operator.cant.be.applied: +, java.lang.Object,<nulltype>
T6491592.java:12:11: compiler.err.operator.cant.be.applied: +, java.lang.Object,compiler.misc.type.null
1 error
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @test
* @bug 6722234
* @summary javac diagnostics need better integration with the type-system
* @author mcimadamore
* @compile/fail/ref=T6722234a_1.out -XDrawDiagnostics -XDdiags=disambiguateTvars T6722234a.java
* @compile/fail/ref=T6722234a_2.out -XDrawDiagnostics -XDdiags=disambiguateTvars,where T6722234a.java
*/
class T6722234a<T extends String> {
<T extends Integer> void test(T t) {
m(t);
}
void m(T t) {}
}
T6722234a.java:35:9: compiler.err.cant.apply.symbol: kindname.method, m, compiler.misc.type.var: T, 1, compiler.misc.type.var: T, 2, kindname.class, T6722234a<compiler.misc.type.var: T, 1>, null
1 error
T6722234a.java:35:9: compiler.err.cant.apply.symbol: kindname.method, m, compiler.misc.type.var: T, 1, compiler.misc.type.var: T, 2, kindname.class, T6722234a<compiler.misc.type.var: T, 1>, null
- compiler.misc.where.description.typevar.1: compiler.misc.type.var: T, 1,compiler.misc.type.var: T, 2,{(compiler.misc.where.typevar: compiler.misc.type.var: T, 1, java.lang.String, kindname.class, T6722234a),(compiler.misc.where.typevar: compiler.misc.type.var: T, 2, java.lang.Integer, kindname.method, <compiler.misc.type.var: T, 2>test(compiler.misc.type.var: T, 2))}
1 error
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @test
* @bug 6722234
* @summary javac diagnostics need better integration with the type-system
* @author mcimadamore
* @compile/fail/ref=T6722234b_1.out -XDrawDiagnostics -XDdiags=simpleNames T6722234b.java
* @compile/fail/ref=T6722234b_2.out -XDrawDiagnostics -XDdiags=simpleNames,where T6722234b.java
*/
import java.util.*;
class T6722234b {
<T> void m(List<T> l1, List<T> l2) {}
void test(List<? extends T6722234b> list) {
m(list, list);
}
}
T6722234b.java:39:9: compiler.err.cant.apply.symbol: kindname.method, m, List<T>,List<T>, List<compiler.misc.type.captureof: 1, ? extends T6722234b>,List<compiler.misc.type.captureof: 2, ? extends T6722234b>, kindname.class, T6722234b, null
1 error
T6722234b.java:39:9: compiler.err.cant.apply.symbol: kindname.method, m, List<T>,List<T>, List<compiler.misc.captured.type: 1>,List<compiler.misc.captured.type: 2>, kindname.class, T6722234b, null
- compiler.misc.where.description.typevar: T,{(compiler.misc.where.typevar: T, Object, kindname.method, <T>m(List<T>,List<T>))}
- compiler.misc.where.description.captured.1: compiler.misc.captured.type: 1,compiler.misc.captured.type: 2,{(compiler.misc.where.captured.1: compiler.misc.captured.type: 1, T6722234b, compiler.misc.type.null, ? extends T6722234b),(compiler.misc.where.captured.1: compiler.misc.captured.type: 2, T6722234b, compiler.misc.type.null, ? extends T6722234b)}
1 error
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @test
* @bug 6722234
* @summary javac diagnostics need better integration with the type-system
* @author mcimadamore
* @compile/fail/ref=T6722234c.out -XDrawDiagnostics -XDdiags=simpleNames T6722234c.java
*/
class T6722234c {
static class String {}
<T> void m(String s2) {}
void test() {
m("");
}
}
T6722234c.java:37:9: compiler.err.cant.apply.symbol: kindname.method, m, T6722234c.String, java.lang.String, kindname.class, T6722234c, null
1 error
/*
* Copyright 2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* @test
* @bug 6722234
* @summary javac diagnostics need better integration with the type-system
* @author mcimadamore
* @compile/fail/ref=T6722234d_1.out -XDrawDiagnostics -XDdiags=where T6722234d.java
* @compile/fail/ref=T6722234d_2.out -XDrawDiagnostics -XDdiags=where,simpleNames T6722234d.java
*/
class T6722234d {
interface I1 {}
interface I2 {}
class A implements I1, I2 {}
class B implements I1, I2 {}
class Test {
<Z> Z m(Z z1, Z z2) { return null; }
void main(){
A a = m(new A(), new B());
}
}
}
T6722234d.java:41:20: compiler.err.prob.found.req: (compiler.misc.incompatible.types), compiler.misc.intersection.type: 1, T6722234d.A
- compiler.misc.where.description.intersection: compiler.misc.intersection.type: 1,{(compiler.misc.where.intersection: compiler.misc.intersection.type: 1, java.lang.Object,T6722234d.I1,T6722234d.I2)}
1 error
T6722234d.java:41:20: compiler.err.prob.found.req: (compiler.misc.incompatible.types), compiler.misc.intersection.type: 1, T6722234d.A
- compiler.misc.where.description.intersection: compiler.misc.intersection.type: 1,{(compiler.misc.where.intersection: compiler.misc.intersection.type: 1, Object,I1,I2)}
1 error
......@@ -3,7 +3,7 @@
* @bug 4336282 4785453
* @summary Verify that extending an erray class does not crash the compiler.
*
* @compile/fail/ref=ExtendArray.out -XDstdout -XDdiags=%b:%l:%_%m ExtendArray.java
* @compile/fail/ref=ExtendArray.out -XDstdout -XDrawDiagnostics ExtendArray.java
*/
// Note that an error is expected, but not a crash.
......
ExtendArray.java:11: unexpected type
public class ExtendArray extends Object[] {}
^
required: class
found: java.lang.Object[]
ExtendArray.java:11:40: compiler.err.type.found.req: java.lang.Object[], (compiler.misc.type.req.class)
1 error
......@@ -4,7 +4,7 @@
* @summary "attemping to assign weaker access" message doesn't give method line number
* @author Neal Gafter
*
* @compile/fail/ref=OverridePosition.out -XDstdout -XDdiags=%b:%l:%_%m OverridePosition.java
* @compile/fail/ref=OverridePosition.out -XDstdout -XDrawDiagnostics OverridePosition.java
*/
package T4524388;
......
OverridePosition.java:17: method() in T4524388.Testa cannot implement method() in T4524388.Interface; attempting to assign weaker access privileges; was public
void method() {}
^
OverridePosition.java:24: method() in T4524388.A cannot implement method() in T4524388.Interface; attempting to assign weaker access privileges; was public
class B extends A implements Interface {
^
OverridePosition.java:17:10: compiler.err.override.weaker.access: (compiler.misc.cant.implement: method(), T4524388.Testa, method(), T4524388.Interface), public
OverridePosition.java:24:1: compiler.err.override.weaker.access: (compiler.misc.cant.implement: method(), T4524388.A, method(), T4524388.Interface), public
2 errors
......@@ -3,7 +3,7 @@
* @bug 4093617
* @summary Object has no superclass
* @author Peter von der Ah\u00e9
* @compile/fail/ref=T4093617.out -XDstdout -XDdiags=%b:%l:%_%m T4093617.java
* @compile/fail/ref=T4093617.out -XDstdout -XDrawDiagnostics T4093617.java
*/
package java.lang;
......
T4093617.java:12: java.lang.Object has no superclass
Object() { super(); }
^
T4093617.java:12:16: compiler.err.no.superclass: java.lang.Object
1 error
......@@ -3,7 +3,7 @@
* @bug 5003235
* @summary Access to private inner classes
* @author Peter von der Ah\u00e9
* @compile/fail/ref=T5003235c.out -XDstdout -XDdiags=%b:%l:%_%m T5003235c.java
* @compile/fail/ref=T5003235c.out -XDstdout -XDrawDiagnostics T5003235c.java
*/
class T5003235c {
......
T5003235c.java:15: T5003235c.B has private access in T5003235c
class C extends T5003235c.B.Inner {}
^
T5003235c.java:15:26: compiler.err.report.access: T5003235c.B, private, T5003235c
1 error
......@@ -4,7 +4,7 @@
* @summary REGRESSION: Generated error message unhelpful for missing methods
* @author gafter
*
* @compile/fail/ref=T4666866.out -XDstdout -XDdiags=%b:%l:%_%m T4666866.java
* @compile/fail/ref=T4666866.out -XDstdout -XDrawDiagnostics T4666866.java
*/
class t implements Runnable {}
T4666866.java:10: t is not abstract and does not override abstract method run() in java.lang.Runnable
class t implements Runnable {}
^
T4666866.java:10:1: compiler.err.does.not.override.abstract: t, run(), java.lang.Runnable
1 error
......@@ -4,7 +4,7 @@
* @summary Verify correct implementation of JLS2e 6.6.2.1
* @author maddox
*
* @compile/fail/ref=ProtectedMemberAccess2.out -XDstdout -XDdiags=%b:%l:%_%m ProtectedMemberAccess2.java
* @compile/fail/ref=ProtectedMemberAccess2.out -XDstdout -XDdiags=-simpleNames -XDdiagsFormat=%b:%l:%_%m ProtectedMemberAccess2.java
*/
// 71 errors expected.
......
......@@ -4,7 +4,7 @@
* @summary Verify correct implementation of JLS2e 6.6.2.1
* @author maddox
*
* @compile/fail/ref=ProtectedMemberAccess3.out -XDstdout -XDdiags=%b:%l:%_%m ProtectedMemberAccess3.java
* @compile/fail/ref=ProtectedMemberAccess3.out -XDstdout -XDdiags=-simpleNames -XDdiagsFormat=%b:%l:%_%m ProtectedMemberAccess3.java
*/
// 46 errors expected.
......
......@@ -4,7 +4,7 @@
* @summary Verify correct implementation of JLS2e 6.6.2.1
* @author maddox
*
* @compile/fail/ref=ProtectedMemberAccess4.out -XDstdout -XDdiags=%b:%l:%_%m ProtectedMemberAccess4.java
* @compile/fail/ref=ProtectedMemberAccess4.out -XDstdout -XDdiags=-simpleNames -XDdiagsFormat=%b:%l:%_%m ProtectedMemberAccess4.java
*/
// 33 errors expected.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册