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.context;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.annotations.Nullable;
021    import org.jetbrains.jet.lang.psi.Call;
022    import org.jetbrains.jet.lang.resolve.BindingTrace;
023    import org.jetbrains.jet.lang.resolve.calls.CallResolverExtension;
024    import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
025    import org.jetbrains.jet.lang.resolve.calls.model.DataFlowInfoForArgumentsImpl;
026    import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments;
027    import org.jetbrains.jet.lang.resolve.scopes.JetScope;
028    import org.jetbrains.jet.lang.types.JetType;
029    import org.jetbrains.jet.lang.types.expressions.LabelResolver;
030    
031    public abstract class CallResolutionContext<Context extends CallResolutionContext<Context>> extends ResolutionContext<Context> {
032        public final Call call;
033        public final CheckValueArgumentsMode checkArguments;
034        @NotNull
035        public final MutableDataFlowInfoForArguments dataFlowInfoForArguments;
036    
037        protected CallResolutionContext(
038                @NotNull BindingTrace trace,
039                @NotNull JetScope scope,
040                @NotNull Call call,
041                @NotNull JetType expectedType,
042                @NotNull DataFlowInfo dataFlowInfo,
043                @NotNull ContextDependency contextDependency,
044                @NotNull CheckValueArgumentsMode checkArguments,
045                @NotNull ResolutionResultsCache resolutionResultsCache,
046                @NotNull LabelResolver labelResolver,
047                @SuppressWarnings("NullableProblems")
048                @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments,
049                @NotNull CallResolverExtension callResolverExtension,
050                boolean isAnnotationContext,
051                boolean collectAllCandidates
052        ) {
053            super(trace, scope, expectedType, dataFlowInfo, contextDependency, resolutionResultsCache, labelResolver, callResolverExtension,
054                  isAnnotationContext, collectAllCandidates);
055            this.call = call;
056            this.checkArguments = checkArguments;
057            if (dataFlowInfoForArguments != null) {
058                this.dataFlowInfoForArguments = dataFlowInfoForArguments;
059            }
060            else if (checkArguments == CheckValueArgumentsMode.ENABLED) {
061                this.dataFlowInfoForArguments = new DataFlowInfoForArgumentsImpl(call);
062            }
063            else {
064                this.dataFlowInfoForArguments = MutableDataFlowInfoForArguments.WITHOUT_ARGUMENTS_CHECK;
065            }
066        }
067    
068        @NotNull
069        public BasicCallResolutionContext toBasic() {
070            return BasicCallResolutionContext.create(this, call, checkArguments);
071        }
072    }