langtools/src/share/classes/com/sun/tools/javac/code/Types.java
changeset 16318 14906f8d3a42
parent 16313 ca91cf83b25c
child 16556 f4adc5bb4652
equal deleted inserted replaced
16317:1b4b06b67ea4 16318:14906f8d3a42
   570             return false;
   570             return false;
   571         }
   571         }
   572     }
   572     }
   573 
   573 
   574     public Type removeWildcards(Type site) {
   574     public Type removeWildcards(Type site) {
   575         if (capture(site) != site) {
   575         Type capturedSite = capture(site);
       
   576         if (capturedSite != site) {
   576             Type formalInterface = site.tsym.type;
   577             Type formalInterface = site.tsym.type;
   577             ListBuffer<Type> typeargs = ListBuffer.lb();
   578             ListBuffer<Type> typeargs = ListBuffer.lb();
   578             List<Type> actualTypeargs = site.getTypeArguments();
   579             List<Type> actualTypeargs = site.getTypeArguments();
       
   580             List<Type> capturedTypeargs = capturedSite.getTypeArguments();
   579             //simply replace the wildcards with its bound
   581             //simply replace the wildcards with its bound
   580             for (Type t : formalInterface.getTypeArguments()) {
   582             for (Type t : formalInterface.getTypeArguments()) {
   581                 if (actualTypeargs.head.hasTag(WILDCARD)) {
   583                 if (actualTypeargs.head.hasTag(WILDCARD)) {
   582                     WildcardType wt = (WildcardType)actualTypeargs.head;
   584                     WildcardType wt = (WildcardType)actualTypeargs.head;
   583                     Type bound;
   585                     Type bound;
   584                     switch (wt.kind) {
   586                     switch (wt.kind) {
       
   587                         case EXTENDS:
   585                         case UNBOUND:
   588                         case UNBOUND:
       
   589                             CapturedType capVar = (CapturedType)capturedTypeargs.head;
   586                             //use declared bound if it doesn't depend on formal type-args
   590                             //use declared bound if it doesn't depend on formal type-args
   587                             bound = wt.bound.bound.containsAny(formalInterface.getTypeArguments()) ?
   591                             bound = capVar.bound.containsAny(capturedSite.getTypeArguments()) ?
   588                                     syms.objectType : wt.bound.bound;
   592                                     syms.objectType : capVar.bound;
   589                             break;
   593                             break;
   590                         default:
   594                         default:
   591                             bound = wt.type;
   595                             bound = wt.type;
   592                     }
   596                     }
   593                     typeargs.append(bound);
   597                     typeargs.append(bound);
   594                 } else {
   598                 } else {
   595                     typeargs.append(actualTypeargs.head);
   599                     typeargs.append(actualTypeargs.head);
   596                 }
   600                 }
   597                 actualTypeargs = actualTypeargs.tail;
   601                 actualTypeargs = actualTypeargs.tail;
       
   602                 capturedTypeargs = capturedTypeargs.tail;
   598             }
   603             }
   599             return subst(formalInterface, formalInterface.getTypeArguments(), typeargs.toList());
   604             return subst(formalInterface, formalInterface.getTypeArguments(), typeargs.toList());
   600         } else {
   605         } else {
   601             return site;
   606             return site;
   602         }
   607         }