Home | History | Annotate | Download | only in subst
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package signature.compare.model.subst;
     18 
     19 import signature.model.IClassReference;
     20 import signature.model.IParameterizedType;
     21 import signature.model.ITypeReference;
     22 import signature.model.ITypeVariableDefinition;
     23 import signature.model.impl.SigParameterizedType;
     24 
     25 import java.util.List;
     26 import java.util.Map;
     27 
     28 public class ParameterizedTypeProjection implements IParameterizedType {
     29 
     30     private final IParameterizedType original;
     31 
     32     private final Map<ITypeVariableDefinition, ITypeReference> mappings;
     33 
     34     public ParameterizedTypeProjection(IParameterizedType original,
     35             Map<ITypeVariableDefinition, ITypeReference> mappings) {
     36         this.original = original;
     37         this.mappings = mappings;
     38     }
     39 
     40     public ITypeReference getOwnerType() {
     41         ITypeReference ownerType = original.getOwnerType();
     42         if (ownerType == null) {
     43             return null;
     44         }
     45         return ViewpointAdapter.substitutedTypeReference(ownerType, mappings);
     46     }
     47 
     48     private IClassReference rawType = null;
     49 
     50     /**
     51      * Returns the raw type with substituted type variables.
     52      *
     53      * @return the raw type with substituted type variables
     54      */
     55     public IClassReference getRawType() {
     56         if (rawType == null) {
     57             rawType = (IClassReference) ViewpointAdapter
     58                     .substitutedTypeReference(original.getRawType(),
     59                             ViewpointAdapter.createTypeMapping(this, original
     60                                     .getRawType().getClassDefinition()));
     61         }
     62         return rawType;
     63     }
     64 
     65     private List<ITypeReference> arguments = null;
     66 
     67     public List<ITypeReference> getTypeArguments() {
     68         if (arguments == null) {
     69             arguments = ViewpointAdapter.substitutedTypeReferences(original
     70                     .getTypeArguments(), mappings);
     71         }
     72         return arguments;
     73     }
     74 
     75     @Override
     76     public int hashCode() {
     77         return SigParameterizedType.hashCode(this);
     78     }
     79 
     80     @Override
     81     public boolean equals(Object obj) {
     82         return SigParameterizedType.equals(this, obj);
     83     }
     84 
     85     @Override
     86     public String toString() {
     87         return SigParameterizedType.toString(this);
     88     }
     89 }
     90