This commit is contained in:
Lana Steuck 2012-01-24 13:44:01 -08:00
commit 9ffd90edcf
18 changed files with 177 additions and 44 deletions

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -3600,39 +3600,44 @@ public class Types {
@Override @Override
public Type visitCapturedType(CapturedType t, Void s) { public Type visitCapturedType(CapturedType t, Void s) {
Type bound = visitWildcardType(t.wildcard, null); Type w_bound = t.wildcard.type;
return (bound.contains(t)) ? Type bound = w_bound.contains(t) ?
erasure(bound) : erasure(w_bound) :
bound; visit(w_bound);
return rewriteAsWildcardType(visit(bound), t.wildcard.bound, t.wildcard.kind);
} }
@Override @Override
public Type visitTypeVar(TypeVar t, Void s) { public Type visitTypeVar(TypeVar t, Void s) {
if (rewriteTypeVars) { if (rewriteTypeVars) {
Type bound = high ? Type bound = t.bound.contains(t) ?
(t.bound.contains(t) ?
erasure(t.bound) : erasure(t.bound) :
visit(t.bound)) : visit(t.bound);
syms.botType; return rewriteAsWildcardType(bound, t, EXTENDS);
return rewriteAsWildcardType(bound, t); } else {
}
else
return t; return t;
}
} }
@Override @Override
public Type visitWildcardType(WildcardType t, Void s) { public Type visitWildcardType(WildcardType t, Void s) {
Type bound = high ? t.getExtendsBound() : Type bound2 = visit(t.type);
t.getSuperBound(); return t.type == bound2 ? t : rewriteAsWildcardType(bound2, t.bound, t.kind);
if (bound == null)
bound = high ? syms.objectType : syms.botType;
return rewriteAsWildcardType(visit(bound), t.bound);
} }
private Type rewriteAsWildcardType(Type bound, TypeVar formal) { private Type rewriteAsWildcardType(Type bound, TypeVar formal, BoundKind bk) {
return high ? switch (bk) {
makeExtendsWildcard(B(bound), formal) : case EXTENDS: return high ?
makeSuperWildcard(B(bound), formal); 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) { Type B(Type t) {

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -332,25 +332,29 @@ public class Infer {
//replace uninferred type-vars //replace uninferred type-vars
targs = types.subst(targs, targs = types.subst(targs,
that.tvars, that.tvars,
instaniateAsUninferredVars(undetvars, that.tvars)); instantiateAsUninferredVars(undetvars, that.tvars));
} }
return chk.checkType(warn.pos(), that.inst(targs, types), to); return chk.checkType(warn.pos(), that.inst(targs, types), to);
} }
//where //where
private List<Type> instaniateAsUninferredVars(List<Type> undetvars, List<Type> tvars) { private List<Type> instantiateAsUninferredVars(List<Type> undetvars, List<Type> tvars) {
Assert.check(undetvars.length() == tvars.length());
ListBuffer<Type> new_targs = ListBuffer.lb(); ListBuffer<Type> new_targs = ListBuffer.lb();
//step 1 - create syntethic captured vars //step 1 - create synthetic captured vars
for (Type t : undetvars) { for (Type t : undetvars) {
UndetVar uv = (UndetVar)t; UndetVar uv = (UndetVar)t;
Type newArg = new CapturedType(t.tsym.name, t.tsym, uv.inst, syms.botType, null); Type newArg = new CapturedType(t.tsym.name, t.tsym, uv.inst, syms.botType, null);
new_targs = new_targs.append(newArg); new_targs = new_targs.append(newArg);
} }
//step 2 - replace synthetic vars in their bounds //step 2 - replace synthetic vars in their bounds
List<Type> formals = tvars;
for (Type t : new_targs.toList()) { for (Type t : new_targs.toList()) {
CapturedType ct = (CapturedType)t; CapturedType ct = (CapturedType)t;
ct.bound = types.subst(ct.bound, tvars, new_targs.toList()); 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; ct.wildcard = wt;
formals = formals.tail;
} }
return new_targs.toList(); return new_targs.toList();
} }

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -214,14 +214,13 @@ public interface Element {
* Returns the elements that are, loosely speaking, directly * Returns the elements that are, loosely speaking, directly
* enclosed by this element. * enclosed by this element.
* *
* A class or interface is considered to enclose the fields, * A {@linkplain TypeElement#getEnclosedElements class or
* methods, constructors, and member types that it directly * interface} is considered to enclose the fields, methods,
* declares. This includes any (implicit) default constructor and * constructors, and member types that it directly declares.
* the implicit {@code values} and {@code valueOf} methods of an
* enum type.
* *
* A package encloses the top-level classes and interfaces within * A {@linkplain PackageElement#getEnclosedElements package}
* it, but is not considered to enclose subpackages. * 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 * Other kinds of elements are not currently considered to enclose
* any elements; however, that may change as this API or the * any elements; however, that may change as this API or the
@ -231,6 +230,8 @@ public interface Element {
* methods in {@link ElementFilter}. * methods in {@link ElementFilter}.
* *
* @return the enclosed elements, or an empty list if none * @return the enclosed elements, or an empty list if none
* @see PackageElement#getEnclosedElements
* @see TypeElement#getEnclosedElements
* @see Elements#getAllMembers * @see Elements#getAllMembers
* @jls 8.8.9 Default Constructor * @jls 8.8.9 Default Constructor
* @jls 8.9 Enums * @jls 8.9 Enums

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,6 +25,8 @@
package javax.lang.model.element; package javax.lang.model.element;
import java.util.List;
/** /**
* Represents a package program element. Provides access to information * Represents a package program element. Provides access to information
* about the package and its members. * about the package and its members.
@ -49,7 +51,7 @@ public interface PackageElement extends Element, QualifiedNameable {
/** /**
* Returns the simple name of this package. For an unnamed * 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 * @return the simple name of this package or an empty name if
* this is an unnamed package * this is an unnamed package
@ -57,6 +59,18 @@ public interface PackageElement extends Element, QualifiedNameable {
@Override @Override
Name getSimpleName(); Name getSimpleName();
/**
* Returns the {@linkplain NestingKind#TOP_LEVEL top-level}
* classes and interfaces within this package. Note that
* subpackages are <em>not</em> considered to be enclosed by a
* package.
*
* @return the top-level classes and interfaces within this
* package
*/
@Override
List<? extends Element> getEnclosedElements();
/** /**
* Returns {@code true} is this is an unnamed package and {@code * Returns {@code true} is this is an unnamed package and {@code
* false} otherwise. * false} otherwise.

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -61,7 +61,12 @@ import javax.lang.model.util.*;
*/ */
public interface TypeElement extends Element, Parameterizable, QualifiedNameable { 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.
* *
* <p> Note that as a particular instance of the {@linkplain * <p> Note that as a particular instance of the {@linkplain
* javax.lang.model.element general accuracy requirements} and the * javax.lang.model.element general accuracy requirements} and the
@ -75,6 +80,7 @@ public interface TypeElement extends Element, Parameterizable, QualifiedNameable
* *
* @return the enclosed elements in proper order, or an empty list if none * @return the enclosed elements in proper order, or an empty list if none
*/ */
@Override
List<? extends Element> getEnclosedElements(); List<? extends Element> getEnclosedElements();
/** /**

View File

@ -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 extends Enum<E>> E m() {
return null;
}
<Z> void test() {
Z z = (Z)m();
}
}

View File

@ -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

View File

@ -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 {
<Z> void test(Enum<?> e) {
Z z = (Z)e;
}
}

View File

@ -0,0 +1,4 @@
T7123100b.java:10:18: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.lang.Enum<compiler.misc.type.captureof: 1, ?>, Z
- compiler.err.warnings.and.werror
1 error
1 warning

View File

@ -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> E m(E e) {
return null;
}
<Z> void test(Enum<?> e) {
Z z = (Z)m(e);
}
}

View File

@ -0,0 +1,4 @@
T7123100c.java:14:19: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.lang.Enum<compiler.misc.type.captureof: 1, ?>, Z
- compiler.err.warnings.and.werror
1 error
1 warning

View File

@ -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 extends Enum<E>> E m(Enum<E> e) {
return null;
}
<Z> void test(Enum<?> e) {
Z z = (Z)m(e);
}
}

View File

@ -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

View File

@ -0,0 +1,14 @@
/*
* @test /nodynamiccopyright/
* @author mcimadamore
* @bug 7005671
* @summary Generics compilation failure casting List<? extends Set...> to List<Set...>
* @compile/fail/ref=T7126754.out -Xlint:unchecked -Werror -XDrawDiagnostics T7126754.java
*/
import java.util.List;
class T7126754 {
List<? extends List<? extends String>> c = null;
List<List<? extends String>> d = (List<List<? extends String>>)c;
}

View File

@ -0,0 +1,4 @@
T7126754.java:13:68: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.util.List<compiler.misc.type.captureof: 1, ? extends java.util.List<? extends java.lang.String>>, java.util.List<java.util.List<? extends java.lang.String>>
- compiler.err.warnings.and.werror
1 error
1 warning

View File

@ -23,10 +23,13 @@
/* /*
* @test * @test
* @bug 6968063 * @bug 6968063 7127924
* @summary provide examples of code that generate diagnostics * @summary provide examples of code that generate diagnostics
* @build Example CheckExamples * @build Example CheckExamples
* @run main CheckExamples * @run main/othervm CheckExamples
*/
/*
* See CR 7127924 for info on why othervm is used.
*/ */
import java.io.*; import java.io.*;

View File

@ -23,10 +23,13 @@
/** /**
* @test * @test
* @bug 7013272 * @bug 7013272 7127924
* @summary Automatically generate info about how compiler resource keys are used * @summary Automatically generate info about how compiler resource keys are used
* @build Example ArgTypeCompilerFactory MessageFile MessageInfo * @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.*; import java.io.*;

View File

@ -23,10 +23,13 @@
/** /**
* @test * @test
* @bug 6968063 * @bug 6968063 7127924
* @summary provide examples of code that generate diagnostics * @summary provide examples of code that generate diagnostics
* @build ArgTypeCompilerFactory Example HTMLWriter RunExamples * @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.*; import java.io.*;