001    /*
002     * Copyright 2010-2013 JetBrains s.r.o.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package org.jetbrains.jet.lang.types;
018    
019    import org.jetbrains.annotations.NotNull;
020    
021    public class TypeProjection {
022        private final Variance projection;
023        private final JetType type;
024    
025        public TypeProjection(@NotNull Variance projection, @NotNull JetType type) {
026            this.projection = projection;
027            this.type = type;
028        }
029    
030        public TypeProjection(JetType type) {
031            this(Variance.INVARIANT, type);
032        }
033    
034        @NotNull
035        public Variance getProjectionKind() {
036            return projection;
037        }
038    
039        @NotNull
040        public JetType getType() {
041            return type;
042        }
043    
044        @Override
045        public String toString() {
046            if (projection == Variance.INVARIANT) {
047                return type.toString();
048            }
049            return projection + " " + type;
050        }
051    
052        @Override
053        public boolean equals(Object o) {
054            if (this == o) return true;
055            if (o == null || getClass() != o.getClass()) return false;
056    
057            TypeProjection that = (TypeProjection) o;
058    
059            if (projection != that.projection) return false;
060            if (type != null ? !type.equals(that.type) : that.type != null) return false;
061    
062            return true;
063        }
064    
065        @Override
066        public int hashCode() {
067            int result = projection != null ? projection.hashCode() : 0;
068            result = 31 * result + (type != null ? type.hashCode() : 0);
069            return result;
070        }
071    }