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    
017    package org.jetbrains.jet.lang.resolve.calls.model;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.annotations.Nullable;
021    import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
022    import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
023    import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
024    import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
025    import org.jetbrains.jet.lang.psi.Call;
026    import org.jetbrains.jet.lang.resolve.DelegatingBindingTrace;
027    import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind;
028    import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus;
029    import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
030    import org.jetbrains.jet.lang.types.JetType;
031    
032    import java.util.List;
033    import java.util.Map;
034    
035    public class VariableAsFunctionResolvedCall implements ResolvedCallWithTrace<FunctionDescriptor> {
036        private final ResolvedCallWithTrace<FunctionDescriptor> functionCall;
037        private final ResolvedCallWithTrace<VariableDescriptor> variableCall;
038    
039        public VariableAsFunctionResolvedCall(@NotNull ResolvedCallWithTrace<FunctionDescriptor> functionCall,
040                @NotNull ResolvedCallWithTrace<VariableDescriptor> variableCall) {
041            this.functionCall = functionCall;
042            this.variableCall = variableCall;
043        }
044    
045        @NotNull
046        public ResolvedCallWithTrace<FunctionDescriptor> getFunctionCall() {
047            return functionCall;
048        }
049    
050        @NotNull
051        public ResolvedCallWithTrace<VariableDescriptor> getVariableCall() {
052            return variableCall;
053        }
054    
055        @NotNull
056        @Override
057        public Call getCall() {
058            return variableCall.getCall();
059        }
060    
061        @NotNull
062        @Override
063        public FunctionDescriptor getCandidateDescriptor() {
064            return functionCall.getResultingDescriptor();
065        }
066    
067        @NotNull
068        @Override
069        public FunctionDescriptor getResultingDescriptor() {
070            return functionCall.getResultingDescriptor();
071        }
072    
073        @NotNull
074        @Override
075        public ReceiverValue getReceiverArgument() {
076            return variableCall.getReceiverArgument();
077        }
078    
079        @NotNull
080        @Override
081        public ReceiverValue getThisObject() {
082            return variableCall.getThisObject();
083        }
084    
085        @NotNull
086        @Override
087        public ExplicitReceiverKind getExplicitReceiverKind() {
088            return variableCall.getExplicitReceiverKind();
089        }
090    
091        @NotNull
092        @Override
093        public Map<ValueParameterDescriptor, ResolvedValueArgument> getValueArguments() {
094            return functionCall.getValueArguments();
095        }
096    
097        @Nullable
098        @Override
099        public List<ResolvedValueArgument> getValueArgumentsByIndex() {
100            return functionCall.getValueArgumentsByIndex();
101        }
102    
103        @NotNull
104        @Override
105        public Map<TypeParameterDescriptor, JetType> getTypeArguments() {
106            return functionCall.getTypeArguments();
107        }
108    
109        @NotNull
110        @Override
111        public ResolutionStatus getStatus() {
112            return variableCall.getStatus().combine(functionCall.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() || functionCall.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    
142        @NotNull
143        @Override
144        public DataFlowInfoForArguments getDataFlowInfoForArguments() {
145            return functionCall.getDataFlowInfoForArguments();
146        }
147    
148        @Override
149        public void markCallAsCompleted() {
150            functionCall.markCallAsCompleted();
151            variableCall.markCallAsCompleted();
152        }
153    
154        @Override
155        public boolean isCompleted() {
156            return functionCall.isCompleted() && variableCall.isCompleted();
157        }
158    }