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 017package org.jetbrains.jet.lang.resolve.calls.inference; 018 019import org.jetbrains.annotations.NotNull; 020import org.jetbrains.jet.lang.types.JetType; 021 022import java.text.MessageFormat; 023 024/** 025 * A specific type for subtype constraint of types. 026 */ 027public enum ConstraintType implements Comparable<ConstraintType> { 028 // The order of these constants DOES matter 029 // they are compared according to ordinal() values 030 // First element has the highest priority 031 RECEIVER("{0} is not a subtype of the expected receiver type {1}"), 032 VALUE_ARGUMENT("Type mismatch: argument type is {0}, but {1} was expected"), 033 EXPECTED_TYPE("Resulting type is {0} but {1} was expected"), 034 PARAMETER_BOUND("Type parameter bound is not satisfied: {0} is not a subtype of {1}"); 035 036 private final String errorMessageTemplate; // {0} is subtype, {1} is supertype 037 038 private ConstraintType(@NotNull String errorMessageTemplate) { 039 this.errorMessageTemplate = errorMessageTemplate; 040 } 041 042 @NotNull 043 public SubtypingConstraint assertSubtyping(@NotNull JetType subtype, @NotNull JetType supertype) { 044 return new SubtypingConstraint(this, subtype, supertype); 045 } 046 047 @NotNull 048 public String makeErrorMessage(@NotNull SubtypingConstraint constraint) { 049 return MessageFormat.format(errorMessageTemplate, constraint.getSubtype(), constraint.getSupertype()); 050 } 051}