# HG changeset patch # User lana # Date 1327441441 28800 # Node ID 601ffcc6551d5414ef871be306c3a26396cf16a7 # Parent f6191bad139ae1dafe46971cd7ea9fc5187df32c# Parent 99261fc7d95d83d0bb628d4da692f61ee1375579 Merge diff -r f6191bad139a -r 601ffcc6551d src/share/classes/com/sun/tools/javac/code/Types.java --- a/src/share/classes/com/sun/tools/javac/code/Types.java Fri Jan 20 13:08:51 2012 -0800 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Tue Jan 24 13:44:01 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, Oracle and/or its affiliates. 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 @@ -3600,39 +3600,44 @@ @Override public Type visitCapturedType(CapturedType t, Void s) { - Type bound = visitWildcardType(t.wildcard, null); - return (bound.contains(t)) ? - erasure(bound) : - bound; + Type w_bound = t.wildcard.type; + Type bound = w_bound.contains(t) ? + erasure(w_bound) : + visit(w_bound); + return rewriteAsWildcardType(visit(bound), t.wildcard.bound, t.wildcard.kind); } @Override public Type visitTypeVar(TypeVar t, Void s) { if (rewriteTypeVars) { - Type bound = high ? - (t.bound.contains(t) ? + Type bound = t.bound.contains(t) ? erasure(t.bound) : - visit(t.bound)) : - syms.botType; - return rewriteAsWildcardType(bound, t); + visit(t.bound); + return rewriteAsWildcardType(bound, t, EXTENDS); + } else { + return t; } - else - return t; } @Override public Type visitWildcardType(WildcardType t, Void s) { - Type bound = high ? t.getExtendsBound() : - t.getSuperBound(); - if (bound == null) - bound = high ? syms.objectType : syms.botType; - return rewriteAsWildcardType(visit(bound), t.bound); + Type bound2 = visit(t.type); + return t.type == bound2 ? t : rewriteAsWildcardType(bound2, t.bound, t.kind); } - private Type rewriteAsWildcardType(Type bound, TypeVar formal) { - return high ? - makeExtendsWildcard(B(bound), formal) : - makeSuperWildcard(B(bound), formal); + private Type rewriteAsWildcardType(Type bound, TypeVar formal, BoundKind bk) { + switch (bk) { + case EXTENDS: return high ? + makeExtendsWildcard(B(bound), formal) : + makeExtendsWildcard(syms.objectType, formal); + case SUPER: return high ? + makeSuperWildcard(syms.botType, formal) : + makeSuperWildcard(B(bound), formal); + case UNBOUND: return makeExtendsWildcard(syms.objectType, formal); + default: + Assert.error("Invalid bound kind " + bk); + return null; + } } Type B(Type t) { diff -r f6191bad139a -r 601ffcc6551d src/share/classes/com/sun/tools/javac/comp/Infer.java --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Fri Jan 20 13:08:51 2012 -0800 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Tue Jan 24 13:44:01 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2012, Oracle and/or its affiliates. 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 @@ -332,25 +332,29 @@ //replace uninferred type-vars targs = types.subst(targs, that.tvars, - instaniateAsUninferredVars(undetvars, that.tvars)); + instantiateAsUninferredVars(undetvars, that.tvars)); } return chk.checkType(warn.pos(), that.inst(targs, types), to); } //where - private List instaniateAsUninferredVars(List undetvars, List tvars) { + private List instantiateAsUninferredVars(List undetvars, List tvars) { + Assert.check(undetvars.length() == tvars.length()); ListBuffer new_targs = ListBuffer.lb(); - //step 1 - create syntethic captured vars + //step 1 - create synthetic captured vars for (Type t : undetvars) { UndetVar uv = (UndetVar)t; Type newArg = new CapturedType(t.tsym.name, t.tsym, uv.inst, syms.botType, null); new_targs = new_targs.append(newArg); } //step 2 - replace synthetic vars in their bounds + List formals = tvars; for (Type t : new_targs.toList()) { CapturedType ct = (CapturedType)t; ct.bound = types.subst(ct.bound, tvars, new_targs.toList()); - WildcardType wt = new WildcardType(ct.bound, BoundKind.EXTENDS, syms.boundClass); + WildcardType wt = new WildcardType(syms.objectType, BoundKind.UNBOUND, syms.boundClass); + wt.bound = (TypeVar)formals.head; ct.wildcard = wt; + formals = formals.tail; } return new_targs.toList(); } diff -r f6191bad139a -r 601ffcc6551d src/share/classes/javax/lang/model/element/Element.java --- a/src/share/classes/javax/lang/model/element/Element.java Fri Jan 20 13:08:51 2012 -0800 +++ b/src/share/classes/javax/lang/model/element/Element.java Tue Jan 24 13:44:01 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. 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 @@ -214,14 +214,13 @@ * Returns the elements that are, loosely speaking, directly * enclosed by this element. * - * A class or interface is considered to enclose the fields, - * methods, constructors, and member types that it directly - * declares. This includes any (implicit) default constructor and - * the implicit {@code values} and {@code valueOf} methods of an - * enum type. + * A {@linkplain TypeElement#getEnclosedElements class or + * interface} is considered to enclose the fields, methods, + * constructors, and member types that it directly declares. * - * A package encloses the top-level classes and interfaces within - * it, but is not considered to enclose subpackages. + * A {@linkplain PackageElement#getEnclosedElements package} + * encloses the top-level classes and interfaces within it, but is + * not considered to enclose subpackages. * * Other kinds of elements are not currently considered to enclose * any elements; however, that may change as this API or the @@ -231,6 +230,8 @@ * methods in {@link ElementFilter}. * * @return the enclosed elements, or an empty list if none + * @see PackageElement#getEnclosedElements + * @see TypeElement#getEnclosedElements * @see Elements#getAllMembers * @jls 8.8.9 Default Constructor * @jls 8.9 Enums diff -r f6191bad139a -r 601ffcc6551d src/share/classes/javax/lang/model/element/PackageElement.java --- a/src/share/classes/javax/lang/model/element/PackageElement.java Fri Jan 20 13:08:51 2012 -0800 +++ b/src/share/classes/javax/lang/model/element/PackageElement.java Tue Jan 24 13:44:01 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. 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 @@ -25,6 +25,8 @@ package javax.lang.model.element; +import java.util.List; + /** * Represents a package program element. Provides access to information * about the package and its members. @@ -49,7 +51,7 @@ /** * Returns the simple name of this package. For an unnamed - * package, an empty name is returned + * package, an empty name is returned. * * @return the simple name of this package or an empty name if * this is an unnamed package @@ -58,6 +60,18 @@ Name getSimpleName(); /** + * Returns the {@linkplain NestingKind#TOP_LEVEL top-level} + * classes and interfaces within this package. Note that + * subpackages are not considered to be enclosed by a + * package. + * + * @return the top-level classes and interfaces within this + * package + */ + @Override + List getEnclosedElements(); + + /** * Returns {@code true} is this is an unnamed package and {@code * false} otherwise. * diff -r f6191bad139a -r 601ffcc6551d src/share/classes/javax/lang/model/element/TypeElement.java --- a/src/share/classes/javax/lang/model/element/TypeElement.java Fri Jan 20 13:08:51 2012 -0800 +++ b/src/share/classes/javax/lang/model/element/TypeElement.java Tue Jan 24 13:44:01 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2012, Oracle and/or its affiliates. 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 @@ -61,7 +61,12 @@ */ public interface TypeElement extends Element, Parameterizable, QualifiedNameable { /** - * {@inheritDoc} + * Returns the fields, methods, constructors, and member types + * that are directly declared in this class or interface. + * + * This includes any (implicit) default constructor and + * the implicit {@code values} and {@code valueOf} methods of an + * enum type. * *

Note that as a particular instance of the {@linkplain * javax.lang.model.element general accuracy requirements} and the @@ -75,6 +80,7 @@ * * @return the enclosed elements in proper order, or an empty list if none */ + @Override List getEnclosedElements(); /** diff -r f6191bad139a -r 601ffcc6551d test/tools/javac/cast/7123100/T7123100a.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/cast/7123100/T7123100a.java Tue Jan 24 13:44:01 2012 -0800 @@ -0,0 +1,16 @@ +/* + * @test /nodynamiccopyright/ + * @bug 7123100 + * @summary javac fails with java.lang.StackOverflowError + * @compile/fail/ref=T7123100a.out -Werror -Xlint:unchecked -XDrawDiagnostics T7123100a.java + */ + +class T7123100a { + > E m() { + return null; + } + + void test() { + Z z = (Z)m(); + } +} diff -r f6191bad139a -r 601ffcc6551d test/tools/javac/cast/7123100/T7123100a.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/cast/7123100/T7123100a.out Tue Jan 24 13:44:01 2012 -0800 @@ -0,0 +1,4 @@ +T7123100a.java:14:19: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), compiler.misc.type.captureof: 1, ?, Z +- compiler.err.warnings.and.werror +1 error +1 warning diff -r f6191bad139a -r 601ffcc6551d test/tools/javac/cast/7123100/T7123100b.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/cast/7123100/T7123100b.java Tue Jan 24 13:44:01 2012 -0800 @@ -0,0 +1,12 @@ +/* + * @test /nodynamiccopyright/ + * @bug 7123100 + * @summary javac fails with java.lang.StackOverflowError + * @compile/fail/ref=T7123100b.out -Werror -Xlint:unchecked -XDrawDiagnostics T7123100b.java + */ + +class T7123100b { + void test(Enum e) { + Z z = (Z)e; + } +} diff -r f6191bad139a -r 601ffcc6551d test/tools/javac/cast/7123100/T7123100b.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/cast/7123100/T7123100b.out Tue Jan 24 13:44:01 2012 -0800 @@ -0,0 +1,4 @@ +T7123100b.java:10:18: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.lang.Enum, Z +- compiler.err.warnings.and.werror +1 error +1 warning diff -r f6191bad139a -r 601ffcc6551d test/tools/javac/cast/7123100/T7123100c.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/cast/7123100/T7123100c.java Tue Jan 24 13:44:01 2012 -0800 @@ -0,0 +1,16 @@ +/* + * @test /nodynamiccopyright/ + * @bug 7123100 + * @summary javac fails with java.lang.StackOverflowError + * @compile/fail/ref=T7123100c.out -Werror -Xlint:unchecked -XDrawDiagnostics T7123100c.java + */ + +class T7123100c { + E m(E e) { + return null; + } + + void test(Enum e) { + Z z = (Z)m(e); + } +} diff -r f6191bad139a -r 601ffcc6551d test/tools/javac/cast/7123100/T7123100c.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/cast/7123100/T7123100c.out Tue Jan 24 13:44:01 2012 -0800 @@ -0,0 +1,4 @@ +T7123100c.java:14:19: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.lang.Enum, Z +- compiler.err.warnings.and.werror +1 error +1 warning diff -r f6191bad139a -r 601ffcc6551d test/tools/javac/cast/7123100/T7123100d.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/cast/7123100/T7123100d.java Tue Jan 24 13:44:01 2012 -0800 @@ -0,0 +1,16 @@ +/* + * @test /nodynamiccopyright/ + * @bug 7123100 + * @summary javac fails with java.lang.StackOverflowError + * @compile/fail/ref=T7123100d.out -Werror -Xlint:unchecked -XDrawDiagnostics T7123100d.java + */ + +class T7123100d { + > E m(Enum e) { + return null; + } + + void test(Enum e) { + Z z = (Z)m(e); + } +} diff -r f6191bad139a -r 601ffcc6551d test/tools/javac/cast/7123100/T7123100d.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/cast/7123100/T7123100d.out Tue Jan 24 13:44:01 2012 -0800 @@ -0,0 +1,4 @@ +T7123100d.java:14:19: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), compiler.misc.type.captureof: 1, ?, Z +- compiler.err.warnings.and.werror +1 error +1 warning diff -r f6191bad139a -r 601ffcc6551d test/tools/javac/cast/7126754/T7126754.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/cast/7126754/T7126754.java Tue Jan 24 13:44:01 2012 -0800 @@ -0,0 +1,14 @@ +/* + * @test /nodynamiccopyright/ + * @author mcimadamore + * @bug 7005671 + * @summary Generics compilation failure casting List to List + * @compile/fail/ref=T7126754.out -Xlint:unchecked -Werror -XDrawDiagnostics T7126754.java + */ + +import java.util.List; + +class T7126754 { + List> c = null; + List> d = (List>)c; +} diff -r f6191bad139a -r 601ffcc6551d test/tools/javac/cast/7126754/T7126754.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/cast/7126754/T7126754.out Tue Jan 24 13:44:01 2012 -0800 @@ -0,0 +1,4 @@ +T7126754.java:13:68: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.util.List>, java.util.List> +- compiler.err.warnings.and.werror +1 error +1 warning diff -r f6191bad139a -r 601ffcc6551d test/tools/javac/diags/CheckExamples.java --- a/test/tools/javac/diags/CheckExamples.java Fri Jan 20 13:08:51 2012 -0800 +++ b/test/tools/javac/diags/CheckExamples.java Tue Jan 24 13:44:01 2012 -0800 @@ -23,10 +23,13 @@ /* * @test - * @bug 6968063 + * @bug 6968063 7127924 * @summary provide examples of code that generate diagnostics * @build Example CheckExamples - * @run main CheckExamples + * @run main/othervm CheckExamples + */ +/* + * See CR 7127924 for info on why othervm is used. */ import java.io.*; diff -r f6191bad139a -r 601ffcc6551d test/tools/javac/diags/MessageInfo.java --- a/test/tools/javac/diags/MessageInfo.java Fri Jan 20 13:08:51 2012 -0800 +++ b/test/tools/javac/diags/MessageInfo.java Tue Jan 24 13:44:01 2012 -0800 @@ -23,10 +23,13 @@ /** * @test - * @bug 7013272 + * @bug 7013272 7127924 * @summary Automatically generate info about how compiler resource keys are used * @build Example ArgTypeCompilerFactory MessageFile MessageInfo - * @run main MessageInfo + * @run main/othervm MessageInfo + */ +/* + * See CR 7127924 for info on why othervm is used. */ import java.io.*; diff -r f6191bad139a -r 601ffcc6551d test/tools/javac/diags/RunExamples.java --- a/test/tools/javac/diags/RunExamples.java Fri Jan 20 13:08:51 2012 -0800 +++ b/test/tools/javac/diags/RunExamples.java Tue Jan 24 13:44:01 2012 -0800 @@ -23,10 +23,13 @@ /** * @test - * @bug 6968063 + * @bug 6968063 7127924 * @summary provide examples of code that generate diagnostics * @build ArgTypeCompilerFactory Example HTMLWriter RunExamples - * @run main RunExamples + * @run main/othervm RunExamples + */ +/* + * See CR 7127924 for info on why othervm is used. */ import java.io.*;