langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java
changeset 44186 fe848a208b20
parent 42828 cce89649f958
equal deleted inserted replaced
44185:309b455e3ccc 44186:fe848a208b20
    28 import java.lang.annotation.Annotation;
    28 import java.lang.annotation.Annotation;
    29 import java.util.ArrayDeque;
    29 import java.util.ArrayDeque;
    30 import java.util.Collections;
    30 import java.util.Collections;
    31 import java.util.EnumMap;
    31 import java.util.EnumMap;
    32 import java.util.Map;
    32 import java.util.Map;
    33 import java.util.function.Function;
       
    34 
    33 
    35 import javax.lang.model.type.*;
    34 import javax.lang.model.type.*;
    36 
    35 
    37 import com.sun.tools.javac.code.Symbol.*;
    36 import com.sun.tools.javac.code.Symbol.*;
    38 import com.sun.tools.javac.code.TypeMetadata.Entry;
    37 import com.sun.tools.javac.code.TypeMetadata.Entry;
       
    38 import com.sun.tools.javac.code.Types.TypeMapping;
    39 import com.sun.tools.javac.comp.Infer.IncorporationAction;
    39 import com.sun.tools.javac.comp.Infer.IncorporationAction;
    40 import com.sun.tools.javac.util.*;
    40 import com.sun.tools.javac.util.*;
    41 import com.sun.tools.javac.util.DefinedBy.Api;
    41 import com.sun.tools.javac.util.DefinedBy.Api;
    42 
    42 
    43 import static com.sun.tools.javac.code.BoundKind.*;
    43 import static com.sun.tools.javac.code.BoundKind.*;
   220         Assert.checkNonNull(metadata);
   220         Assert.checkNonNull(metadata);
   221         this.tsym = tsym;
   221         this.tsym = tsym;
   222         this.metadata = metadata;
   222         this.metadata = metadata;
   223     }
   223     }
   224 
   224 
   225     /** An abstract class for mappings from types to types
   225     /**
   226      */
   226      * A subclass of {@link Types.TypeMapping} which applies a mapping recursively to the subterms
   227     public static abstract class TypeMapping<S> extends Types.MapVisitor<S> implements Function<Type, Type> {
   227      * of a given type expression. This mapping returns the original type is no changes occurred
   228 
   228      * when recursively mapping the original type's subterms.
   229         @Override
   229      */
   230         public Type apply(Type type) {
   230     public static abstract class StructuralTypeMapping<S> extends Types.TypeMapping<S> {
   231             return visit(type);
       
   232         }
       
   233 
       
   234         List<Type> visit(List<Type> ts, S s) {
       
   235             return ts.map(t -> visit(t, s));
       
   236         }
       
   237 
   231 
   238         @Override
   232         @Override
   239         public Type visitClassType(ClassType t, S s) {
   233         public Type visitClassType(ClassType t, S s) {
   240             Type outer = t.getEnclosingType();
   234             Type outer = t.getEnclosingType();
   241             Type outer1 = visit(outer, s);
   235             Type outer1 = visit(outer, s);
   297                 }
   291                 }
   298             };
   292             };
   299         }
   293         }
   300 
   294 
   301         @Override
   295         @Override
   302         public Type visitCapturedType(CapturedType t, S s) {
       
   303             return visitTypeVar(t, s);
       
   304         }
       
   305 
       
   306         @Override
       
   307         public Type visitForAll(ForAll t, S s) {
   296         public Type visitForAll(ForAll t, S s) {
   308             return visit(t.qtype, s);
   297             return visit(t.qtype, s);
   309         }
   298         }
   310     }
   299     }
   311 
   300 
   371 
   360 
   372     public Type stripMetadata() {
   361     public Type stripMetadata() {
   373         return accept(stripMetadata, null);
   362         return accept(stripMetadata, null);
   374     }
   363     }
   375     //where
   364     //where
   376         private final static TypeMapping<Void> stripMetadata = new TypeMapping<Void>() {
   365         private final static TypeMapping<Void> stripMetadata = new StructuralTypeMapping<Void>() {
   377             @Override
   366             @Override
   378             public Type visitClassType(ClassType t, Void aVoid) {
   367             public Type visitClassType(ClassType t, Void aVoid) {
   379                 return super.visitClassType((ClassType)t.typeNoMetadata(), aVoid);
   368                 return super.visitClassType((ClassType)t.typeNoMetadata(), aVoid);
   380             }
   369             }
   381 
   370 
  2123                 bounds.put(ib, prevBounds.prepend(bound2));
  2112                 bounds.put(ib, prevBounds.prepend(bound2));
  2124                 notifyBoundChange(ib, bound2, false);
  2113                 notifyBoundChange(ib, bound2, false);
  2125             }
  2114             }
  2126         }
  2115         }
  2127         //where
  2116         //where
  2128             TypeMapping<Void> toTypeVarMap = new TypeMapping<Void>() {
  2117             TypeMapping<Void> toTypeVarMap = new StructuralTypeMapping<Void>() {
  2129                 @Override
  2118                 @Override
  2130                 public Type visitUndetVar(UndetVar uv, Void _unused) {
  2119                 public Type visitUndetVar(UndetVar uv, Void _unused) {
  2131                     return uv.inst != null ? uv.inst : uv.qtype;
  2120                     return uv.inst != null ? uv.inst : uv.qtype;
  2132                 }
  2121                 }
  2133             };
  2122             };