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.
*
* This code is free software; you can redistribute it and/or modify it
@ -3600,39 +3600,44 @@ public class Types {
@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);
}
else
visit(t.bound);
return rewriteAsWildcardType(bound, t, EXTENDS);
} 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) {

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.
*
* This code is free software; you can redistribute it and/or modify it
@ -332,25 +332,29 @@ public class Infer {
//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<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();
//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<Type> 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();
}

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.
*
* 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
* 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 @@ public interface Element {
* 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

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.
*
* 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 @@ public interface PackageElement extends Element, QualifiedNameable {
/**
* 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
@ -57,6 +59,18 @@ public interface PackageElement extends Element, QualifiedNameable {
@Override
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
* 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.
*
* 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 {
/**
* {@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
* 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
*/
@Override
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
* @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.*;

View File

@ -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.*;

View File

@ -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.*;