001    /*
002     * Copyright 2010-2015 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.kotlin.types.expressions;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.kotlin.resolve.BindingTrace;
021    import org.jetbrains.kotlin.resolve.StatementFilter;
022    import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
023    import org.jetbrains.kotlin.resolve.calls.context.*;
024    import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
025    import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
026    import org.jetbrains.kotlin.types.KotlinType;
027    
028    public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingContext> {
029    
030        @NotNull
031        public static ExpressionTypingContext newContext(
032                @NotNull BindingTrace trace,
033                @NotNull LexicalScope scope,
034                @NotNull DataFlowInfo dataFlowInfo,
035                @NotNull KotlinType expectedType
036        ) {
037            return newContext(trace, scope, dataFlowInfo, expectedType, CallChecker.DoNothing.INSTANCE);
038        }
039    
040        @NotNull
041        public static ExpressionTypingContext newContext(
042                @NotNull BindingTrace trace,
043                @NotNull LexicalScope scope,
044                @NotNull DataFlowInfo dataFlowInfo,
045                @NotNull KotlinType expectedType,
046                @NotNull CallChecker callChecker
047        ) {
048            return newContext(trace, scope, dataFlowInfo, expectedType,
049                              ContextDependency.INDEPENDENT, new ResolutionResultsCacheImpl(),
050                              callChecker,
051                              StatementFilter.NONE, false);
052        }
053    
054        @NotNull
055        public static ExpressionTypingContext newContext(@NotNull ResolutionContext context) {
056            return new ExpressionTypingContext(
057                    context.trace, context.scope, context.dataFlowInfo, context.expectedType,
058                    context.contextDependency, context.resolutionResultsCache,
059                    context.callChecker,
060                    context.statementFilter,
061                    context.isAnnotationContext, context.collectAllCandidates,
062                    context.callPosition);
063        }
064    
065        @NotNull
066        public static ExpressionTypingContext newContext(
067                @NotNull BindingTrace trace,
068                @NotNull LexicalScope scope,
069                @NotNull DataFlowInfo dataFlowInfo,
070                @NotNull KotlinType expectedType,
071                @NotNull ContextDependency contextDependency,
072                @NotNull ResolutionResultsCache resolutionResultsCache,
073                @NotNull CallChecker callChecker,
074                @NotNull StatementFilter statementFilter,
075                boolean isAnnotationContext
076        ) {
077            return new ExpressionTypingContext(
078                    trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, callChecker,
079                    statementFilter, isAnnotationContext, false, CallPosition.Unknown.INSTANCE);
080        }
081    
082        private ExpressionTypingContext(
083                @NotNull BindingTrace trace,
084                @NotNull LexicalScope scope,
085                @NotNull DataFlowInfo dataFlowInfo,
086                @NotNull KotlinType expectedType,
087                @NotNull ContextDependency contextDependency,
088                @NotNull ResolutionResultsCache resolutionResultsCache,
089                @NotNull CallChecker callChecker,
090                @NotNull StatementFilter statementFilter,
091                boolean isAnnotationContext,
092                boolean collectAllCandidates,
093                @NotNull CallPosition callPosition
094        ) {
095            super(trace, scope, expectedType, dataFlowInfo, contextDependency, resolutionResultsCache,
096                  callChecker,
097                  statementFilter, isAnnotationContext, collectAllCandidates, callPosition);
098        }
099    
100        @Override
101        protected ExpressionTypingContext create(
102                @NotNull BindingTrace trace,
103                @NotNull LexicalScope scope,
104                @NotNull DataFlowInfo dataFlowInfo,
105                @NotNull KotlinType expectedType,
106                @NotNull ContextDependency contextDependency,
107                @NotNull ResolutionResultsCache resolutionResultsCache,
108                @NotNull StatementFilter statementFilter,
109                boolean collectAllCandidates,
110                @NotNull CallPosition callPosition
111        ) {
112            return new ExpressionTypingContext(trace, scope, dataFlowInfo,
113                                               expectedType, contextDependency, resolutionResultsCache,
114                                               callChecker,
115                                               statementFilter, isAnnotationContext, collectAllCandidates, callPosition);
116        }
117    }