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