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