001    /*
002     * Copyright 2010-2014 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    import org.jetbrains.annotations.Nullable;
021    import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
022    import org.jetbrains.jet.lang.resolve.scopes.JetScope;
023    import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
024    
025    import java.util.List;
026    
027    public abstract class DelegatingType implements JetType {
028        protected abstract JetType getDelegate();
029    
030        @NotNull
031        @Override
032        public TypeConstructor getConstructor() {
033            return getDelegate().getConstructor();
034        }
035    
036        @NotNull
037        @Override
038        public List<TypeProjection> getArguments() {
039            return getDelegate().getArguments();
040        }
041    
042        @Override
043        public boolean isNullable() {
044            return getDelegate().isNullable();
045        }
046    
047        @NotNull
048        @Override
049        public JetScope getMemberScope() {
050            return getDelegate().getMemberScope();
051        }
052    
053        @Override
054        public boolean isError() {
055            return getDelegate().isError();
056        }
057    
058        @NotNull
059        @Override
060        public Annotations getAnnotations() {
061            return getDelegate().getAnnotations();
062        }
063    
064        @Override
065        @Nullable
066        public <T extends TypeCapability> T getCapability(@NotNull Class<T> capabilityClass) {
067            if (capabilityClass.isInstance(this)) {
068                //noinspection unchecked
069                return (T) this;
070            }
071            return getDelegate().getCapability(capabilityClass);
072        }
073    
074        @Override
075        public int hashCode() {
076            return getDelegate().hashCode();
077        }
078    
079        @Override
080        public boolean equals(Object obj) {
081            if (this == obj) return true;
082            if (!(obj instanceof JetType)) return false;
083    
084            JetType type = (JetType) obj;
085            return JetTypeChecker.FLEXIBLE_UNEQUAL_TO_INFLEXIBLE.equalTypes(this, type);
086        }
087    
088        @Override
089        public String toString() {
090            return getDelegate().toString();
091        }
092    }