StorageManager&ExceptionTracker delivered where needed

- GlobalContext introduced to group the two
- Caches track exceptions
This commit is contained in:
Andrey Breslav
2014-02-03 18:30:16 +04:00
parent 364182e3f0
commit e60bd514fa
36 changed files with 284 additions and 161 deletions
@@ -38,7 +38,13 @@ public class AnalyzerFacadeForEverything {
@NotNull ModuleDescriptor module) {
TopDownAnalysisParameters topDownAnalysisParameters = new TopDownAnalysisParameters(
bodiesResolveContext.getStorageManager(), filesToAnalyzeCompletely, false, false, scriptParameters);
bodiesResolveContext.getStorageManager(),
bodiesResolveContext.getExceptionTracker(),
filesToAnalyzeCompletely,
false,
false,
scriptParameters
);
bodiesResolveContext.setTopDownAnalysisParameters(topDownAnalysisParameters);
@@ -0,0 +1,36 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.context
import org.jetbrains.jet.storage.StorageManager
import org.jetbrains.jet.storage.ExceptionTracker
import org.jetbrains.jet.storage.LockBasedStorageManager
trait GlobalContext {
val storageManager: StorageManager
val exceptionTracker: ExceptionTracker
}
open class GlobalContextImpl(
override val storageManager: LockBasedStorageManager,
override val exceptionTracker: ExceptionTracker
) : GlobalContext
fun GlobalContext(): GlobalContextImpl {
val tracker = ExceptionTracker()
return GlobalContextImpl(LockBasedStorageManager.createWithExceptionHandling(tracker), tracker)
}
@@ -92,7 +92,7 @@ public class InjectorForBodyResolve {
this.annotationResolver = new AnnotationResolver();
this.callResolver = new CallResolver();
this.argumentTypeResolver = new ArgumentTypeResolver();
this.expressionTypingServices = new ExpressionTypingServices(storageManager, platformToKotlinClassMap);
this.expressionTypingServices = new ExpressionTypingServices(getBodiesResolveContext(), platformToKotlinClassMap);
this.callExpressionResolver = new CallExpressionResolver();
this.descriptorResolver = new DescriptorResolver();
this.delegatedPropertyResolver = new DelegatedPropertyResolver();
@@ -17,12 +17,13 @@
package org.jetbrains.jet.di;
import com.intellij.openapi.project.Project;
import org.jetbrains.jet.storage.LockBasedStorageManagerWithExceptionTracking;
import org.jetbrains.jet.context.GlobalContextImpl;
import org.jetbrains.jet.lang.descriptors.ModuleDescriptorImpl;
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactory;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
import org.jetbrains.jet.lang.resolve.calls.CallResolverExtensionProvider;
import org.jetbrains.jet.storage.StorageManager;
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
import org.jetbrains.jet.lang.resolve.AnnotationResolver;
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
@@ -44,12 +45,13 @@ import javax.annotation.PreDestroy;
public class InjectorForLazyResolve {
private final Project project;
private final LockBasedStorageManagerWithExceptionTracking lockBasedStorageManagerWithExceptionTracking;
private final GlobalContextImpl globalContext;
private final ModuleDescriptorImpl moduleDescriptor;
private final DeclarationProviderFactory declarationProviderFactory;
private final BindingTrace bindingTrace;
private final ResolveSession resolveSession;
private final CallResolverExtensionProvider callResolverExtensionProvider;
private final StorageManager storageManager;
private final PlatformToKotlinClassMap platformToKotlinClassMap;
private final AnnotationResolver annotationResolver;
private final CallResolver callResolver;
@@ -66,23 +68,24 @@ public class InjectorForLazyResolve {
public InjectorForLazyResolve(
@NotNull Project project,
@NotNull LockBasedStorageManagerWithExceptionTracking lockBasedStorageManagerWithExceptionTracking,
@NotNull GlobalContextImpl globalContext,
@NotNull ModuleDescriptorImpl moduleDescriptor,
@NotNull DeclarationProviderFactory declarationProviderFactory,
@NotNull BindingTrace bindingTrace
) {
this.project = project;
this.lockBasedStorageManagerWithExceptionTracking = lockBasedStorageManagerWithExceptionTracking;
this.globalContext = globalContext;
this.moduleDescriptor = moduleDescriptor;
this.declarationProviderFactory = declarationProviderFactory;
this.bindingTrace = bindingTrace;
this.resolveSession = new ResolveSession(project, lockBasedStorageManagerWithExceptionTracking, moduleDescriptor, declarationProviderFactory, bindingTrace);
this.resolveSession = new ResolveSession(project, globalContext, moduleDescriptor, declarationProviderFactory, bindingTrace);
this.callResolverExtensionProvider = new CallResolverExtensionProvider();
this.storageManager = resolveSession.getStorageManager();
this.platformToKotlinClassMap = moduleDescriptor.getPlatformToKotlinClassMap();
this.annotationResolver = new AnnotationResolver();
this.callResolver = new CallResolver();
this.argumentTypeResolver = new ArgumentTypeResolver();
this.expressionTypingServices = new ExpressionTypingServices(lockBasedStorageManagerWithExceptionTracking, platformToKotlinClassMap);
this.expressionTypingServices = new ExpressionTypingServices(globalContext, platformToKotlinClassMap);
this.callExpressionResolver = new CallExpressionResolver();
this.descriptorResolver = new DescriptorResolver();
this.delegatedPropertyResolver = new DelegatedPropertyResolver();
@@ -123,7 +126,7 @@ public class InjectorForLazyResolve {
descriptorResolver.setAnnotationResolver(annotationResolver);
descriptorResolver.setDelegatedPropertyResolver(delegatedPropertyResolver);
descriptorResolver.setExpressionTypingServices(expressionTypingServices);
descriptorResolver.setStorageManager(lockBasedStorageManagerWithExceptionTracking);
descriptorResolver.setStorageManager(storageManager);
descriptorResolver.setTypeResolver(typeResolver);
delegatedPropertyResolver.setExpressionTypingServices(expressionTypingServices);
@@ -18,7 +18,8 @@ package org.jetbrains.jet.di;
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
import org.jetbrains.jet.lang.resolve.calls.CallResolverExtensionProvider;
import org.jetbrains.jet.storage.LockBasedStorageManager;
import org.jetbrains.jet.context.GlobalContext;
import org.jetbrains.jet.storage.StorageManager;
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
import com.intellij.openapi.project.Project;
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
@@ -40,7 +41,8 @@ public class InjectorForMacros {
private final ExpressionTypingServices expressionTypingServices;
private final CallResolverExtensionProvider callResolverExtensionProvider;
private final LockBasedStorageManager lockBasedStorageManager;
private final GlobalContext globalContext;
private final StorageManager storageManager;
private final PlatformToKotlinClassMap platformToKotlinClassMap;
private final Project project;
private final ModuleDescriptor moduleDescriptor;
@@ -58,10 +60,11 @@ public class InjectorForMacros {
@NotNull Project project,
@NotNull ModuleDescriptor moduleDescriptor
) {
this.lockBasedStorageManager = new LockBasedStorageManager();
this.globalContext = org.jetbrains.jet.context.ContextPackage.GlobalContext();
this.platformToKotlinClassMap = moduleDescriptor.getPlatformToKotlinClassMap();
this.expressionTypingServices = new ExpressionTypingServices(lockBasedStorageManager, platformToKotlinClassMap);
this.expressionTypingServices = new ExpressionTypingServices(globalContext, platformToKotlinClassMap);
this.callResolverExtensionProvider = new CallResolverExtensionProvider();
this.storageManager = globalContext.getStorageManager();
this.project = project;
this.moduleDescriptor = moduleDescriptor;
this.annotationResolver = new AnnotationResolver();
@@ -104,7 +107,7 @@ public class InjectorForMacros {
descriptorResolver.setAnnotationResolver(annotationResolver);
descriptorResolver.setDelegatedPropertyResolver(delegatedPropertyResolver);
descriptorResolver.setExpressionTypingServices(expressionTypingServices);
descriptorResolver.setStorageManager(lockBasedStorageManager);
descriptorResolver.setStorageManager(storageManager);
descriptorResolver.setTypeResolver(typeResolver);
delegatedPropertyResolver.setExpressionTypingServices(expressionTypingServices);
@@ -116,7 +116,7 @@ public class InjectorForTopDownAnalyzerBasic {
this.annotationResolver = new AnnotationResolver();
this.callResolver = new CallResolver();
this.argumentTypeResolver = new ArgumentTypeResolver();
this.expressionTypingServices = new ExpressionTypingServices(storageManager, platformToKotlinClassMap);
this.expressionTypingServices = new ExpressionTypingServices(getTopDownAnalysisContext(), platformToKotlinClassMap);
this.callExpressionResolver = new CallExpressionResolver();
this.typeResolver = new TypeResolver();
this.qualifiedExpressionResolver = new QualifiedExpressionResolver();
@@ -19,6 +19,7 @@ package org.jetbrains.jet.lang.resolve;
import com.google.common.base.Function;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.context.GlobalContext;
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
@@ -27,13 +28,19 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.storage.ExceptionTracker;
import org.jetbrains.jet.storage.StorageManager;
import java.util.Collection;
import java.util.Map;
public interface BodiesResolveContext {
public interface BodiesResolveContext extends GlobalContext {
@NotNull
@Override
StorageManager getStorageManager();
@NotNull
@Override
ExceptionTracker getExceptionTracker();
Collection<JetFile> getFiles();
Map<JetClassOrObject, MutableClassDescriptor> getClasses();
Map<JetProperty, PropertyDescriptor> getProperties();
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.storage.ExceptionTracker;
import org.jetbrains.jet.storage.StorageManager;
import java.util.Collection;
@@ -68,6 +69,11 @@ public class CachedBodiesResolveContext implements BodiesResolveContext {
return topDownAnalysisParameters.getStorageManager();
}
@Override
public ExceptionTracker getExceptionTracker() {
return topDownAnalysisParameters.getExceptionTracker();
}
@Override
public Collection<JetFile> getFiles() {
return files;
@@ -30,6 +30,7 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.storage.ExceptionTracker;
import org.jetbrains.jet.storage.StorageManager;
import javax.inject.Inject;
@@ -124,6 +125,11 @@ public class TopDownAnalysisContext implements BodiesResolveContext {
return topDownAnalysisParameters.getStorageManager();
}
@Override
public ExceptionTracker getExceptionTracker() {
return topDownAnalysisParameters.getExceptionTracker();
}
@Override
public Collection<JetFile> getFiles() {
return packageFragments.keySet();
@@ -19,6 +19,7 @@ package org.jetbrains.jet.lang.resolve;
import com.google.common.base.Predicate;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.storage.ExceptionTracker;
import org.jetbrains.jet.storage.StorageManager;
import java.util.List;
@@ -30,6 +31,8 @@ public class TopDownAnalysisParameters {
@NotNull
private final StorageManager storageManager;
@NotNull
private final ExceptionTracker exceptionTracker;
@NotNull
private final Predicate<PsiFile> analyzeCompletely;
private final boolean analyzingBootstrapLibrary;
private final boolean declaredLocally;
@@ -38,23 +41,32 @@ public class TopDownAnalysisParameters {
public TopDownAnalysisParameters(
@NotNull StorageManager storageManager,
@NotNull ExceptionTracker exceptionTracker,
@NotNull Predicate<PsiFile> analyzeCompletely,
boolean analyzingBootstrapLibrary,
boolean declaredLocally,
@NotNull List<AnalyzerScriptParameter> scriptParameters
) {
this.storageManager = storageManager;
this.exceptionTracker = exceptionTracker;
this.analyzeCompletely = analyzeCompletely;
this.analyzingBootstrapLibrary = analyzingBootstrapLibrary;
this.declaredLocally = declaredLocally;
this.scriptParameters = scriptParameters;
}
//@Override
@NotNull
public StorageManager getStorageManager() {
return storageManager;
}
//@Override
@NotNull
public ExceptionTracker getExceptionTracker() {
return exceptionTracker;
}
@NotNull
public Predicate<PsiFile> getAnalyzeCompletely() {
return analyzeCompletely;
@@ -21,6 +21,7 @@ import com.google.common.collect.Sets;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.context.GlobalContext;
import org.jetbrains.jet.di.InjectorForTopDownAnalyzerBasic;
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
import org.jetbrains.jet.lang.descriptors.*;
@@ -34,7 +35,6 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingContext;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.storage.StorageManager;
import javax.inject.Inject;
import java.util.Collection;
@@ -159,7 +159,7 @@ public class TopDownAnalyzer {
}
public static void processClassOrObject(
@NotNull StorageManager storageManager,
@NotNull GlobalContext globalContext,
@Nullable final WritableScope scope,
@NotNull ExpressionTypingContext context,
@NotNull final DeclarationDescriptor containingDeclaration,
@@ -170,8 +170,14 @@ public class TopDownAnalyzer {
PlatformToKotlinClassMap.EMPTY);
TopDownAnalysisParameters topDownAnalysisParameters =
new TopDownAnalysisParameters(storageManager, Predicates.equalTo(object.getContainingFile()),
false, true, Collections.<AnalyzerScriptParameter>emptyList());
new TopDownAnalysisParameters(
globalContext.getStorageManager(),
globalContext.getExceptionTracker(),
Predicates.equalTo(object.getContainingFile()),
false,
true,
Collections.<AnalyzerScriptParameter>emptyList()
);
InjectorForTopDownAnalyzerBasic injector = new InjectorForTopDownAnalyzerBasic(
object.getProject(), topDownAnalysisParameters, new ObservableBindingTrace(context.trace),
@@ -27,6 +27,7 @@ import com.intellij.util.containers.ContainerUtil;
import jet.Function0;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.context.GlobalContextImpl;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.*;
@@ -41,7 +42,10 @@ import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.name.SpecialNames;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import org.jetbrains.jet.storage.*;
import org.jetbrains.jet.storage.ExceptionTracker;
import org.jetbrains.jet.storage.LazyResolveStorageManager;
import org.jetbrains.jet.storage.LockBasedLazyResolveStorageManager;
import org.jetbrains.jet.storage.MemoizedFunctionToNullable;
import javax.inject.Inject;
import java.util.Collection;
@@ -115,14 +119,14 @@ public class ResolveSession implements KotlinCodeAnalyzer {
@Deprecated
public ResolveSession(
@NotNull Project project,
@NotNull LockBasedStorageManagerWithExceptionTracking storageManager,
@NotNull GlobalContextImpl globalContext,
@NotNull ModuleDescriptorImpl rootDescriptor,
@NotNull DeclarationProviderFactory declarationProviderFactory,
@NotNull BindingTrace delegationTrace
) {
LockBasedLazyResolveStorageManager lockBasedLazyResolveStorageManager = new LockBasedLazyResolveStorageManager(storageManager);
LockBasedLazyResolveStorageManager lockBasedLazyResolveStorageManager = new LockBasedLazyResolveStorageManager(globalContext.getStorageManager());
this.storageManager = lockBasedLazyResolveStorageManager;
this.exceptionTracker = storageManager.getTracker();
this.exceptionTracker = globalContext.getExceptionTracker();
this.trace = lockBasedLazyResolveStorageManager.createSafeTrace(delegationTrace);
this.module = rootDescriptor;
@@ -193,11 +197,13 @@ public class ResolveSession implements KotlinCodeAnalyzer {
}
@NotNull
//@Override
public LazyResolveStorageManager getStorageManager() {
return storageManager;
}
@NotNull
//@Override
public ExceptionTracker getExceptionTracker() {
return exceptionTracker;
}
@@ -23,6 +23,7 @@ import com.intellij.util.containers.ContainerUtil;
import jet.Function0;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.context.GlobalContext;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
import org.jetbrains.jet.lang.descriptors.impl.*;
@@ -37,7 +38,6 @@ import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.JetTypeInfo;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.storage.StorageManager;
import org.jetbrains.jet.util.slicedmap.WritableSlice;
import java.util.Collection;
@@ -51,11 +51,14 @@ import static org.jetbrains.jet.lang.types.TypeUtils.*;
import static org.jetbrains.jet.lang.types.expressions.CoercionStrategy.COERCION_TO_UNIT;
public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
private final StorageManager storageManager;
private final GlobalContext globalContext;
protected ClosureExpressionsTypingVisitor(@NotNull ExpressionTypingInternals facade, @NotNull StorageManager storageManager) {
protected ClosureExpressionsTypingVisitor(
@NotNull GlobalContext globalContext,
@NotNull ExpressionTypingInternals facade
) {
super(facade);
this.storageManager = storageManager;
this.globalContext = globalContext;
}
@Override
@@ -73,7 +76,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
@Override
public void handleRecord(WritableSlice<PsiElement, ClassDescriptor> slice, PsiElement declaration, final ClassDescriptor descriptor) {
if (slice == CLASS && declaration == expression.getObjectDeclaration()) {
JetType defaultType = DeferredType.createRecursionIntolerant(storageManager, context.trace,
JetType defaultType = DeferredType.createRecursionIntolerant(globalContext.getStorageManager(), context.trace,
new Function0<JetType>() {
@Override
public JetType invoke() {
@@ -90,7 +93,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
};
ObservableBindingTrace traceAdapter = new ObservableBindingTrace(temporaryTrace);
traceAdapter.addHandler(CLASS, handler);
TopDownAnalyzer.processClassOrObject(storageManager,
TopDownAnalyzer.processClassOrObject(globalContext,
null, // don't need to add classifier of object literal to any scope
context.replaceBindingTrace(traceAdapter).replaceContextDependency(INDEPENDENT),
context.scope.getContainingDeclaration(),
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.context.GlobalContext;
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
@@ -44,7 +45,6 @@ import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.JetTypeInfo;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.storage.StorageManager;
import javax.inject.Inject;
import java.util.Iterator;
@@ -75,7 +75,7 @@ public class ExpressionTypingServices {
@NotNull
private CallResolverExtensionProvider extensionProvider;
@NotNull
private StorageManager storageManager;
private GlobalContext globalContext;
@NotNull
public Project getProject() {
@@ -148,12 +148,12 @@ public class ExpressionTypingServices {
}
public ExpressionTypingServices(
@NotNull StorageManager storageManager,
@NotNull GlobalContext globalContext,
@NotNull PlatformToKotlinClassMap platformToKotlinClassMap
) {
this.storageManager = storageManager;
this.globalContext = globalContext;
this.platformToKotlinClassMap = platformToKotlinClassMap;
this.expressionTypingFacade = ExpressionTypingVisitorDispatcher.create(storageManager, platformToKotlinClassMap);
this.expressionTypingFacade = ExpressionTypingVisitorDispatcher.create(globalContext, platformToKotlinClassMap);
}
@NotNull
@@ -282,7 +282,7 @@ public class ExpressionTypingServices {
return JetTypeInfo.create(KotlinBuiltIns.getInstance().getUnitType(), context.dataFlowInfo);
}
ExpressionTypingInternals blockLevelVisitor = ExpressionTypingVisitorDispatcher.createForBlock(storageManager, platformToKotlinClassMap, scope);
ExpressionTypingInternals blockLevelVisitor = ExpressionTypingVisitorDispatcher.createForBlock(globalContext, platformToKotlinClassMap, scope);
ExpressionTypingContext newContext = createContext(context, trace, scope, context.dataFlowInfo, NO_EXPECTED_TYPE);
JetTypeInfo result = JetTypeInfo.create(null, context.dataFlowInfo);
@@ -306,7 +306,7 @@ public class ExpressionTypingServices {
if (newDataFlowInfo != context.dataFlowInfo) {
newContext = newContext.replaceDataFlowInfo(newDataFlowInfo);
}
blockLevelVisitor = ExpressionTypingVisitorDispatcher.createForBlock(storageManager, platformToKotlinClassMap, scope);
blockLevelVisitor = ExpressionTypingVisitorDispatcher.createForBlock(globalContext, platformToKotlinClassMap, scope);
}
return result;
}
@@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.types.expressions;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.context.GlobalContext;
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
@@ -27,7 +28,6 @@ import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.types.DeferredType;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetTypeInfo;
import org.jetbrains.jet.storage.StorageManager;
import org.jetbrains.jet.util.ReenteringLazyValueComputationException;
import static org.jetbrains.jet.lang.diagnostics.Errors.TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM;
@@ -35,36 +35,36 @@ import static org.jetbrains.jet.lang.diagnostics.Errors.TYPECHECKER_HAS_RUN_INTO
public class ExpressionTypingVisitorDispatcher extends JetVisitor<JetTypeInfo, ExpressionTypingContext> implements ExpressionTypingInternals {
@NotNull
public static ExpressionTypingFacade create(@NotNull StorageManager storageManager, @NotNull PlatformToKotlinClassMap platformToKotlinClassMap) {
return new ExpressionTypingVisitorDispatcher(storageManager, platformToKotlinClassMap, null);
public static ExpressionTypingFacade create(@NotNull GlobalContext globalContext, @NotNull PlatformToKotlinClassMap platformToKotlinClassMap) {
return new ExpressionTypingVisitorDispatcher(globalContext, platformToKotlinClassMap, null);
}
@NotNull
public static ExpressionTypingInternals createForBlock(
@NotNull StorageManager storageManager,
@NotNull GlobalContext globalContext,
@NotNull PlatformToKotlinClassMap platformToKotlinClassMap,
@NotNull WritableScope writableScope
) {
return new ExpressionTypingVisitorDispatcher(storageManager, platformToKotlinClassMap, writableScope);
return new ExpressionTypingVisitorDispatcher(globalContext, platformToKotlinClassMap, writableScope);
}
private final StorageManager storageManager;
private final GlobalContext globalContext;
private final BasicExpressionTypingVisitor basic;
private final ExpressionTypingVisitorForStatements statements;
private final ClosureExpressionsTypingVisitor closures;
private final ControlStructureTypingVisitor controlStructures = new ControlStructureTypingVisitor(this);
private final PatternMatchingTypingVisitor patterns = new PatternMatchingTypingVisitor(this);
private ExpressionTypingVisitorDispatcher(StorageManager storageManager, PlatformToKotlinClassMap platformToKotlinClassMap, WritableScope writableScope) {
this.storageManager = storageManager;
private ExpressionTypingVisitorDispatcher(GlobalContext globalContext, PlatformToKotlinClassMap platformToKotlinClassMap, WritableScope writableScope) {
this.globalContext = globalContext;
this.basic = new BasicExpressionTypingVisitor(this, platformToKotlinClassMap);
if (writableScope != null) {
this.statements = new ExpressionTypingVisitorForStatements(storageManager, this, writableScope, basic, controlStructures, patterns);
this.statements = new ExpressionTypingVisitorForStatements(globalContext, this, writableScope, basic, controlStructures, patterns);
}
else {
this.statements = null;
}
this.closures = new ClosureExpressionsTypingVisitor(this, storageManager);
this.closures = new ClosureExpressionsTypingVisitor(globalContext, this);
}
@NotNull
@@ -100,7 +100,7 @@ public class ExpressionTypingVisitorDispatcher extends JetVisitor<JetTypeInfo, E
}
private ExpressionTypingVisitorForStatements createStatementVisitor(ExpressionTypingContext context) {
return new ExpressionTypingVisitorForStatements(storageManager, this,
return new ExpressionTypingVisitorForStatements(globalContext, this,
ExpressionTypingUtils.newWritableScopeImpl(context, "statement scope"),
basic, controlStructures, patterns);
}
@@ -20,7 +20,11 @@ import com.google.common.collect.Sets;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.context.GlobalContext;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.evaluate.EvaluatePackage;
import org.jetbrains.jet.lang.psi.*;
@@ -39,7 +43,6 @@ import org.jetbrains.jet.lang.types.JetTypeInfo;
import org.jetbrains.jet.lang.types.TypeUtils;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.storage.StorageManager;
import java.util.Collection;
@@ -52,21 +55,21 @@ import static org.jetbrains.jet.lang.types.TypeUtils.noExpectedType;
@SuppressWarnings("SuspiciousMethodCalls")
public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisitor {
private final StorageManager storageManager;
private final GlobalContext globalContext;
private final WritableScope scope;
private final BasicExpressionTypingVisitor basic;
private final ControlStructureTypingVisitor controlStructures;
private final PatternMatchingTypingVisitor patterns;
public ExpressionTypingVisitorForStatements(
@NotNull StorageManager storageManager,
@NotNull GlobalContext globalContext,
@NotNull ExpressionTypingInternals facade,
@NotNull WritableScope scope,
BasicExpressionTypingVisitor basic,
@NotNull ControlStructureTypingVisitor controlStructures,
@NotNull PatternMatchingTypingVisitor patterns) {
super(facade);
this.storageManager = storageManager;
this.globalContext = globalContext;
this.scope = scope;
this.basic = basic;
this.controlStructures = controlStructures;
@@ -90,7 +93,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
@Override
public JetTypeInfo visitObjectDeclaration(@NotNull JetObjectDeclaration declaration, ExpressionTypingContext context) {
TopDownAnalyzer.processClassOrObject(
storageManager,
globalContext,
scope, context.replaceScope(scope).replaceContextDependency(INDEPENDENT), scope.getContainingDeclaration(), declaration);
return DataFlowUtils.checkStatementType(declaration, context, context.dataFlowInfo);
}
@@ -185,7 +188,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
@Override
public JetTypeInfo visitClass(@NotNull JetClass klass, ExpressionTypingContext context) {
TopDownAnalyzer.processClassOrObject(
storageManager,
globalContext,
scope, context.replaceScope(scope).replaceContextDependency(INDEPENDENT), scope.getContainingDeclaration(), klass);
return DataFlowUtils.checkStatementType(klass, context, context.dataFlowInfo);
}
@@ -1,38 +0,0 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.storage;
import org.jetbrains.annotations.NotNull;
public class LockBasedStorageManagerWithExceptionTracking extends LockBasedStorageManager {
@NotNull
public static LockBasedStorageManagerWithExceptionTracking create() {
return new LockBasedStorageManagerWithExceptionTracking(new ExceptionTracker());
}
private final ExceptionTracker tracker;
public LockBasedStorageManagerWithExceptionTracking(@NotNull ExceptionTracker tracker) {
super(tracker);
this.tracker = tracker;
}
@NotNull
public ExceptionTracker getTracker() {
return tracker;
}
}