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

changeset 30
a1d1f335633f
parent 19
adaa3fc51b60
child 41
6e9a43815df7
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Wed Apr 09 15:04:35 2008 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Wed Apr 09 15:30:44 2008 +0100
     1.3 @@ -1499,47 +1499,68 @@
     1.4       * type parameters in t are deleted.
     1.5       */
     1.6      public Type erasure(Type t) {
     1.7 +        return erasure(t, false);
     1.8 +    }
     1.9 +    //where
    1.10 +    private Type erasure(Type t, boolean recurse) {
    1.11          if (t.tag <= lastBaseTag)
    1.12              return t; /* fast special case */
    1.13          else
    1.14 -            return erasure.visit(t);
    1.15 +            return erasure.visit(t, recurse);
    1.16      }
    1.17      // where
    1.18 -        private UnaryVisitor<Type> erasure = new UnaryVisitor<Type>() {
    1.19 -            public Type visitType(Type t, Void ignored) {
    1.20 +        private SimpleVisitor<Type, Boolean> erasure = new SimpleVisitor<Type, Boolean>() {
    1.21 +            public Type visitType(Type t, Boolean recurse) {
    1.22                  if (t.tag <= lastBaseTag)
    1.23                      return t; /*fast special case*/
    1.24                  else
    1.25 -                    return t.map(erasureFun);
    1.26 +                    return t.map(recurse ? erasureRecFun : erasureFun);
    1.27              }
    1.28  
    1.29              @Override
    1.30 -            public Type visitWildcardType(WildcardType t, Void ignored) {
    1.31 -                return erasure(upperBound(t));
    1.32 +            public Type visitWildcardType(WildcardType t, Boolean recurse) {
    1.33 +                return erasure(upperBound(t), recurse);
    1.34              }
    1.35  
    1.36              @Override
    1.37 -            public Type visitClassType(ClassType t, Void ignored) {
    1.38 -                return t.tsym.erasure(Types.this);
    1.39 +            public Type visitClassType(ClassType t, Boolean recurse) {
    1.40 +                Type erased = t.tsym.erasure(Types.this);
    1.41 +                if (recurse) {
    1.42 +                    erased = new ErasedClassType(erased.getEnclosingType(),erased.tsym);
    1.43 +                }
    1.44 +                return erased;
    1.45              }
    1.46  
    1.47              @Override
    1.48 -            public Type visitTypeVar(TypeVar t, Void ignored) {
    1.49 -                return erasure(t.bound);
    1.50 +            public Type visitTypeVar(TypeVar t, Boolean recurse) {
    1.51 +                return erasure(t.bound, recurse);
    1.52              }
    1.53  
    1.54              @Override
    1.55 -            public Type visitErrorType(ErrorType t, Void ignored) {
    1.56 +            public Type visitErrorType(ErrorType t, Boolean recurse) {
    1.57                  return t;
    1.58              }
    1.59          };
    1.60 +
    1.61      private Mapping erasureFun = new Mapping ("erasure") {
    1.62              public Type apply(Type t) { return erasure(t); }
    1.63          };
    1.64  
    1.65 +    private Mapping erasureRecFun = new Mapping ("erasureRecursive") {
    1.66 +        public Type apply(Type t) { return erasureRecursive(t); }
    1.67 +    };
    1.68 +
    1.69      public List<Type> erasure(List<Type> ts) {
    1.70          return Type.map(ts, erasureFun);
    1.71      }
    1.72 +
    1.73 +    public Type erasureRecursive(Type t) {
    1.74 +        return erasure(t, true);
    1.75 +    }
    1.76 +
    1.77 +    public List<Type> erasureRecursive(List<Type> ts) {
    1.78 +        return Type.map(ts, erasureRecFun);
    1.79 +    }
    1.80      // </editor-fold>
    1.81  
    1.82      // <editor-fold defaultstate="collapsed" desc="makeCompoundType">
    1.83 @@ -1626,15 +1647,14 @@
    1.84                      if (t.supertype_field == null) {
    1.85                          List<Type> actuals = classBound(t).allparams();
    1.86                          List<Type> formals = t.tsym.type.allparams();
    1.87 -                        if (actuals.isEmpty()) {
    1.88 -                            if (formals.isEmpty())
    1.89 -                                // Should not happen.  See comments below in interfaces
    1.90 -                                t.supertype_field = supertype;
    1.91 -                            else
    1.92 -                                t.supertype_field = erasure(supertype);
    1.93 -                        } else {
    1.94 +                        if (t.hasErasedSupertypes()) {
    1.95 +                            t.supertype_field = erasureRecursive(supertype);
    1.96 +                        } else if (formals.nonEmpty()) {
    1.97                              t.supertype_field = subst(supertype, formals, actuals);
    1.98                          }
    1.99 +                        else {
   1.100 +                            t.supertype_field = supertype;
   1.101 +                        }
   1.102                      }
   1.103                  }
   1.104                  return t.supertype_field;
   1.105 @@ -1708,18 +1728,15 @@
   1.106                          assert t != t.tsym.type : t.toString();
   1.107                          List<Type> actuals = t.allparams();
   1.108                          List<Type> formals = t.tsym.type.allparams();
   1.109 -                        if (actuals.isEmpty()) {
   1.110 -                            if (formals.isEmpty()) {
   1.111 -                                // In this case t is not generic (nor raw).
   1.112 -                                // So this should not happen.
   1.113 -                                t.interfaces_field = interfaces;
   1.114 -                            } else {
   1.115 -                                t.interfaces_field = erasure(interfaces);
   1.116 -                            }
   1.117 -                        } else {
   1.118 +                        if (t.hasErasedSupertypes()) {
   1.119 +                            t.interfaces_field = erasureRecursive(interfaces);
   1.120 +                        } else if (formals.nonEmpty()) {
   1.121                              t.interfaces_field =
   1.122                                  upperBounds(subst(interfaces, formals, actuals));
   1.123                          }
   1.124 +                        else {
   1.125 +                            t.interfaces_field = interfaces;
   1.126 +                        }
   1.127                      }
   1.128                  }
   1.129                  return t.interfaces_field;

mercurial