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