src/share/classes/com/sun/tools/javac/code/Types.java

changeset 2382
14979dd5e034
parent 2260
fb870c70e774
child 2384
327122b01a9e
equal deleted inserted replaced
2381:d02e9b7444fe 2382:14979dd5e034
41 import com.sun.tools.javac.comp.AttrContext; 41 import com.sun.tools.javac.comp.AttrContext;
42 import com.sun.tools.javac.comp.Check; 42 import com.sun.tools.javac.comp.Check;
43 import com.sun.tools.javac.comp.Enter; 43 import com.sun.tools.javac.comp.Enter;
44 import com.sun.tools.javac.comp.Env; 44 import com.sun.tools.javac.comp.Env;
45 import com.sun.tools.javac.jvm.ClassReader; 45 import com.sun.tools.javac.jvm.ClassReader;
46 import com.sun.tools.javac.tree.JCTree;
46 import com.sun.tools.javac.util.*; 47 import com.sun.tools.javac.util.*;
47 import static com.sun.tools.javac.code.BoundKind.*; 48 import static com.sun.tools.javac.code.BoundKind.*;
48 import static com.sun.tools.javac.code.Flags.*; 49 import static com.sun.tools.javac.code.Flags.*;
49 import static com.sun.tools.javac.code.Scope.*; 50 import static com.sun.tools.javac.code.Scope.*;
50 import static com.sun.tools.javac.code.Symbol.*; 51 import static com.sun.tools.javac.code.Symbol.*;
303 ? isSubtype(boxedClass(t).type, s) 304 ? isSubtype(boxedClass(t).type, s)
304 : isSubtype(unboxedType(t), s); 305 : isSubtype(unboxedType(t), s);
305 } 306 }
306 307
307 /** 308 /**
308 * Is t a subtype of or convertiable via boxing/unboxing 309 * Is t a subtype of or convertible via boxing/unboxing
309 * convertions to s? 310 * conversions to s?
310 */ 311 */
311 public boolean isConvertible(Type t, Type s) { 312 public boolean isConvertible(Type t, Type s) {
312 return isConvertible(t, s, noWarnings); 313 return isConvertible(t, s, noWarnings);
313 } 314 }
314 // </editor-fold> 315 // </editor-fold>
1932 * 1933 *
1933 * @param t a type 1934 * @param t a type
1934 * @param sym a symbol 1935 * @param sym a symbol
1935 */ 1936 */
1936 public Type asSuper(Type t, Symbol sym) { 1937 public Type asSuper(Type t, Symbol sym) {
1938 /* Some examples:
1939 *
1940 * (Enum<E>, Comparable) => Comparable<E>
1941 * (c.s.s.d.AttributeTree.ValueKind, Enum) => Enum<c.s.s.d.AttributeTree.ValueKind>
1942 * (c.s.s.t.ExpressionTree, c.s.s.t.Tree) => c.s.s.t.Tree
1943 * (j.u.List<capture#160 of ? extends c.s.s.d.DocTree>, Iterable) =>
1944 * Iterable<capture#160 of ? extends c.s.s.d.DocTree>
1945 */
1946 if (sym.type == syms.objectType) { //optimization
1947 return syms.objectType;
1948 }
1937 return asSuper.visit(t, sym); 1949 return asSuper.visit(t, sym);
1938 } 1950 }
1939 // where 1951 // where
1940 private SimpleVisitor<Type,Symbol> asSuper = new SimpleVisitor<Type,Symbol>() { 1952 private SimpleVisitor<Type,Symbol> asSuper = new SimpleVisitor<Type,Symbol>() {
1941 1953
3867 for (Type t : ts) { 3879 for (Type t : ts) {
3868 buf = buf.prepend(capture(t)); 3880 buf = buf.prepend(capture(t));
3869 } 3881 }
3870 return buf.reverse(); 3882 return buf.reverse();
3871 } 3883 }
3884
3872 public Type capture(Type t) { 3885 public Type capture(Type t) {
3873 if (!t.hasTag(CLASS)) 3886 if (!t.hasTag(CLASS)) {
3874 return t; 3887 return t;
3888 }
3875 if (t.getEnclosingType() != Type.noType) { 3889 if (t.getEnclosingType() != Type.noType) {
3876 Type capturedEncl = capture(t.getEnclosingType()); 3890 Type capturedEncl = capture(t.getEnclosingType());
3877 if (capturedEncl != t.getEnclosingType()) { 3891 if (capturedEncl != t.getEnclosingType()) {
3878 Type type1 = memberType(capturedEncl, t.tsym); 3892 Type type1 = memberType(capturedEncl, t.tsym);
3879 t = subst(type1, t.tsym.type.getTypeArguments(), t.getTypeArguments()); 3893 t = subst(type1, t.tsym.type.getTypeArguments(), t.getTypeArguments());

mercurial