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.jet.lang.descriptors.TypeParameterDescriptor;
020import org.jetbrains.jet.lang.resolve.calls.results.ResolutionDebugInfo;
021import org.jetbrains.jet.lang.types.JetType;
022
023import java.util.Set;
024
025public class PrintingConstraintResolutionListener implements ConstraintResolutionListener {
026
027    @Override
028    public void constraintsForUnknown(TypeParameterDescriptor typeParameterDescriptor, BoundsOwner typeValue) {
029        println("Constraints for " + typeParameterDescriptor);
030        printTypeValue(typeValue);
031    }
032
033    @Override
034    public void constraintsForKnownType(JetType type, BoundsOwner typeValue) {
035        println("Constraints for " + type);
036        printTypeValue(typeValue);
037    }
038
039    @Override
040    public void done(ConstraintSystemSolution solution, Set<TypeParameterDescriptor> typeParameterDescriptors) {
041        println("==================================================");
042        println("");
043        println("");
044    }
045
046    @Override
047    public void log(Object... messageFragments) {
048        for (Object fragment : messageFragments) {
049            println(fragment);
050        }
051    }
052
053    @Override
054    public void error(Object... messageFragments) {
055        for (Object fragment : messageFragments) {
056            println(fragment);
057        }
058    }
059
060    private void printTypeValue(BoundsOwner typeValue) {
061        for (BoundsOwner bound : typeValue.getUpperBounds()) {
062            println(" :< " + bound);
063        }
064        for (BoundsOwner bound : typeValue.getLowerBounds()) {
065            println(" :> " + bound);
066        }
067    }
068
069    private static void println(Object message) {
070        ResolutionDebugInfo.println(message);
071    }
072}