001    /*
002     * Copyright 2010-2016 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.kotlin.types.checker;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.kotlin.types.KotlinType;
021    import org.jetbrains.kotlin.types.TypeConstructor;
022    
023    public class KotlinTypeCheckerImpl implements KotlinTypeChecker {
024    
025    
026        @NotNull
027        public static KotlinTypeChecker withAxioms(@NotNull final TypeConstructorEquality equalityAxioms) {
028            return new KotlinTypeCheckerImpl(new TypeCheckingProcedure(new TypeCheckerProcedureCallbacksImpl() {
029                @Override
030                public boolean assertEqualTypeConstructors(@NotNull TypeConstructor constructor1, @NotNull TypeConstructor constructor2) {
031                    return constructor1.equals(constructor2) || equalityAxioms.equals(constructor1, constructor2);
032                }
033            }));
034        }
035    
036        private final TypeCheckingProcedure procedure;
037    
038        protected KotlinTypeCheckerImpl(@NotNull TypeCheckingProcedure procedure) {
039            this.procedure = procedure;
040        }
041    
042        @Override
043        public boolean isSubtypeOf(@NotNull KotlinType subtype, @NotNull KotlinType supertype) {
044            return procedure.isSubtypeOf(subtype, supertype);
045        }
046    
047        @Override
048        public boolean equalTypes(@NotNull KotlinType a, @NotNull KotlinType b) {
049            return procedure.equalTypes(a, b);
050        }
051    
052    }