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.isDebuggerContext, context.collectAllCandidates,
062                    context.callPosition);
063        }
064    
065        @NotNull
066        public static ExpressionTypingContext newContext(@NotNull ResolutionContext context, boolean isDebuggerContext) {
067            return new ExpressionTypingContext(
068                    context.trace, context.scope, context.dataFlowInfo, context.expectedType,
069                    context.contextDependency, context.resolutionResultsCache,
070                    context.callChecker,
071                    context.statementFilter,
072                    context.isAnnotationContext, isDebuggerContext, context.collectAllCandidates,
073                    context.callPosition);
074        }
075    
076        @NotNull
077        public static ExpressionTypingContext newContext(
078                @NotNull BindingTrace trace,
079                @NotNull LexicalScope scope,
080                @NotNull DataFlowInfo dataFlowInfo,
081                @NotNull KotlinType expectedType,
082                @NotNull ContextDependency contextDependency,
083                @NotNull ResolutionResultsCache resolutionResultsCache,
084                @NotNull CallChecker callChecker,
085                @NotNull StatementFilter statementFilter,
086                boolean isAnnotationContext
087        ) {
088            return new ExpressionTypingContext(
089                    trace, scope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, callChecker,
090                    statementFilter, isAnnotationContext, false, false, CallPosition.Unknown.INSTANCE);
091        }
092    
093        private ExpressionTypingContext(
094                @NotNull BindingTrace trace,
095                @NotNull LexicalScope scope,
096                @NotNull DataFlowInfo dataFlowInfo,
097                @NotNull KotlinType expectedType,
098                @NotNull ContextDependency contextDependency,
099                @NotNull ResolutionResultsCache resolutionResultsCache,
100                @NotNull CallChecker callChecker,
101                @NotNull StatementFilter statementFilter,
102                boolean isAnnotationContext,
103                boolean isDebuggerContext,
104                boolean collectAllCandidates,
105                @NotNull CallPosition callPosition
106        ) {
107            super(trace, scope, expectedType, dataFlowInfo, contextDependency, resolutionResultsCache,
108                  callChecker,
109                  statementFilter, isAnnotationContext, isDebuggerContext, collectAllCandidates, callPosition);
110        }
111    
112        @Override
113        protected ExpressionTypingContext create(
114                @NotNull BindingTrace trace,
115                @NotNull LexicalScope scope,
116                @NotNull DataFlowInfo dataFlowInfo,
117                @NotNull KotlinType expectedType,
118                @NotNull ContextDependency contextDependency,
119                @NotNull ResolutionResultsCache resolutionResultsCache,
120                @NotNull StatementFilter statementFilter,
121                boolean collectAllCandidates,
122                @NotNull CallPosition callPosition
123        ) {
124            return new ExpressionTypingContext(trace, scope, dataFlowInfo,
125                                               expectedType, contextDependency, resolutionResultsCache,
126                                               callChecker,
127                                               statementFilter, isAnnotationContext, isDebuggerContext, collectAllCandidates, callPosition);
128        }
129    }