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.model;
018
019import org.jetbrains.annotations.NotNull;
020import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
021import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
022import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
023import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
024import org.jetbrains.jet.lang.resolve.DelegatingBindingTrace;
025import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
026import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind;
027import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus;
028import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
029import org.jetbrains.jet.lang.types.JetType;
030
031import java.util.List;
032import java.util.Map;
033
034public class VariableAsFunctionResolvedCall implements ResolvedCallWithTrace<FunctionDescriptor> {
035    private final ResolvedCallWithTrace<FunctionDescriptor> functionCall;
036    private final ResolvedCallWithTrace<VariableDescriptor> variableCall;
037
038    public VariableAsFunctionResolvedCall(@NotNull ResolvedCallWithTrace<FunctionDescriptor> functionCall,
039            @NotNull ResolvedCallWithTrace<VariableDescriptor> variableCall) {
040        this.functionCall = functionCall;
041        this.variableCall = variableCall;
042    }
043
044    public ResolvedCallWithTrace<FunctionDescriptor> getFunctionCall() {
045        return functionCall;
046    }
047
048    public ResolvedCallWithTrace<VariableDescriptor> getVariableCall() {
049        return variableCall;
050    }
051
052    @NotNull
053    @Override
054    public FunctionDescriptor getCandidateDescriptor() {
055        return functionCall.getResultingDescriptor();
056    }
057
058    @NotNull
059    @Override
060    public FunctionDescriptor getResultingDescriptor() {
061        return functionCall.getResultingDescriptor();
062    }
063
064    @NotNull
065    @Override
066    public ReceiverValue getReceiverArgument() {
067        return variableCall.getReceiverArgument();
068    }
069
070    @NotNull
071    @Override
072    public ReceiverValue getThisObject() {
073        return variableCall.getThisObject();
074    }
075
076    @NotNull
077    @Override
078    public ExplicitReceiverKind getExplicitReceiverKind() {
079        return variableCall.getExplicitReceiverKind();
080    }
081
082    @NotNull
083    @Override
084    public Map<ValueParameterDescriptor, ResolvedValueArgument> getValueArguments() {
085        return functionCall.getValueArguments();
086    }
087
088    @NotNull
089    @Override
090    public List<ResolvedValueArgument> getValueArgumentsByIndex() {
091        return functionCall.getValueArgumentsByIndex();
092    }
093
094    @NotNull
095    @Override
096    public Map<TypeParameterDescriptor, JetType> getTypeArguments() {
097        return functionCall.getTypeArguments();
098    }
099
100    @NotNull
101    @Override
102    public DataFlowInfo getDataFlowInfo() {
103        return functionCall.getDataFlowInfo();
104    }
105
106    @NotNull
107    @Override
108    public ResolutionStatus getStatus() {
109        if (variableCall.getStatus() == ResolutionStatus.SUCCESS) {
110            return functionCall.getStatus();
111        }
112        return variableCall.getStatus();
113    }
114
115    @Override
116    public boolean isDirty() {
117        return functionCall.isDirty();
118    }
119
120    @Override
121    public DelegatingBindingTrace getTrace() {
122        //functionCall.trace is temporary trace above variableCall.trace and is committed already
123        return variableCall.getTrace();
124    }
125
126    @Override
127    public boolean isSafeCall() {
128        return variableCall.isSafeCall();
129    }
130
131    @Override
132    public boolean hasIncompleteTypeParameters() {
133        return variableCall.hasIncompleteTypeParameters();
134    }
135
136    @NotNull
137    @Override
138    public ResolvedCallImpl<FunctionDescriptor> getCallToCompleteTypeArgumentInference() {
139        return functionCall.getCallToCompleteTypeArgumentInference();
140    }
141}