LTDA: Refactoring - extract processClassOrObject method from TDA
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve;
|
package org.jetbrains.jet.lang.resolve;
|
||||||
|
|
||||||
import com.google.common.base.Predicates;
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
@@ -24,16 +23,14 @@ import kotlin.Function1;
|
|||||||
import kotlin.KotlinPackage;
|
import kotlin.KotlinPackage;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.context.GlobalContext;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptorWithResolutionScopes;
|
||||||
import org.jetbrains.jet.di.InjectorForTopDownAnalyzerBasic;
|
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.PackageFragmentProvider;
|
||||||
import org.jetbrains.jet.lang.descriptors.impl.*;
|
import org.jetbrains.jet.lang.descriptors.impl.*;
|
||||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingContext;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -173,69 +170,6 @@ public class TopDownAnalyzer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void processClassOrObject(
|
|
||||||
@NotNull GlobalContext globalContext,
|
|
||||||
@Nullable final WritableScope scope,
|
|
||||||
@NotNull ExpressionTypingContext context,
|
|
||||||
@NotNull final DeclarationDescriptor containingDeclaration,
|
|
||||||
@NotNull JetClassOrObject object,
|
|
||||||
@NotNull AdditionalCheckerProvider additionalCheckerProvider
|
|
||||||
) {
|
|
||||||
TopDownAnalysisParameters topDownAnalysisParameters =
|
|
||||||
TopDownAnalysisParameters.createForLocalDeclarations(
|
|
||||||
globalContext.getStorageManager(),
|
|
||||||
globalContext.getExceptionTracker(),
|
|
||||||
Predicates.equalTo(object.getContainingFile())
|
|
||||||
);
|
|
||||||
|
|
||||||
InjectorForTopDownAnalyzerBasic injector = new InjectorForTopDownAnalyzerBasic(
|
|
||||||
object.getProject(),
|
|
||||||
topDownAnalysisParameters,
|
|
||||||
context.trace,
|
|
||||||
DescriptorUtils.getContainingModule(containingDeclaration),
|
|
||||||
additionalCheckerProvider
|
|
||||||
);
|
|
||||||
|
|
||||||
TopDownAnalysisContext c = new TopDownAnalysisContext(topDownAnalysisParameters);
|
|
||||||
c.setOuterDataFlowInfo(context.dataFlowInfo);
|
|
||||||
|
|
||||||
injector.getTopDownAnalyzer().doProcess(
|
|
||||||
c,
|
|
||||||
context.scope,
|
|
||||||
new PackageLikeBuilder() {
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public DeclarationDescriptor getOwnerForChildren() {
|
|
||||||
return containingDeclaration;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addClassifierDescriptor(@NotNull MutableClassDescriptor classDescriptor) {
|
|
||||||
if (scope != null) {
|
|
||||||
scope.addClassifierDescriptor(classDescriptor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
|
|
||||||
return ClassObjectStatus.NOT_ALLOWED;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Collections.<PsiElement>singletonList(object)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public TopDownAnalysisContext analyzeFiles(
|
public TopDownAnalysisContext analyzeFiles(
|
||||||
@NotNull TopDownAnalysisParameters topDownAnalysisParameters,
|
@NotNull TopDownAnalysisParameters topDownAnalysisParameters,
|
||||||
|
|||||||
+6
-5
@@ -85,11 +85,12 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
};
|
};
|
||||||
ObservableBindingTrace traceAdapter = new ObservableBindingTrace(temporaryTrace);
|
ObservableBindingTrace traceAdapter = new ObservableBindingTrace(temporaryTrace);
|
||||||
traceAdapter.addHandler(CLASS, handler);
|
traceAdapter.addHandler(CLASS, handler);
|
||||||
TopDownAnalyzer.processClassOrObject(components.globalContext,
|
LocalClassifierAnalyzer.processClassOrObject(components.globalContext,
|
||||||
null, // don't need to add classifier of object literal to any scope
|
null, // don't need to add classifier of object literal to any scope
|
||||||
context.replaceBindingTrace(traceAdapter).replaceContextDependency(INDEPENDENT),
|
context.replaceBindingTrace(traceAdapter).replaceContextDependency(INDEPENDENT),
|
||||||
context.scope.getContainingDeclaration(),
|
context.scope.getContainingDeclaration(),
|
||||||
expression.getObjectDeclaration(), components.additionalCheckerProvider);
|
expression.getObjectDeclaration(),
|
||||||
|
components.additionalCheckerProvider);
|
||||||
|
|
||||||
DelegatingBindingTrace cloneDelta = new DelegatingBindingTrace(
|
DelegatingBindingTrace cloneDelta = new DelegatingBindingTrace(
|
||||||
new BindingTraceContext().getBindingContext(), "cached delta trace for object literal expression resolve", expression);
|
new BindingTraceContext().getBindingContext(), "cached delta trace for object literal expression resolve", expression);
|
||||||
|
|||||||
+2
-2
@@ -84,7 +84,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetTypeInfo visitObjectDeclaration(@NotNull JetObjectDeclaration declaration, ExpressionTypingContext context) {
|
public JetTypeInfo visitObjectDeclaration(@NotNull JetObjectDeclaration declaration, ExpressionTypingContext context) {
|
||||||
TopDownAnalyzer.processClassOrObject(
|
LocalClassifierAnalyzer.processClassOrObject(
|
||||||
components.globalContext,
|
components.globalContext,
|
||||||
scope, context.replaceScope(scope).replaceContextDependency(INDEPENDENT), scope.getContainingDeclaration(), declaration,
|
scope, context.replaceScope(scope).replaceContextDependency(INDEPENDENT), scope.getContainingDeclaration(), declaration,
|
||||||
components.additionalCheckerProvider);
|
components.additionalCheckerProvider);
|
||||||
@@ -181,7 +181,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetTypeInfo visitClass(@NotNull JetClass klass, ExpressionTypingContext context) {
|
public JetTypeInfo visitClass(@NotNull JetClass klass, ExpressionTypingContext context) {
|
||||||
TopDownAnalyzer.processClassOrObject(
|
LocalClassifierAnalyzer.processClassOrObject(
|
||||||
components.globalContext,
|
components.globalContext,
|
||||||
scope, context.replaceScope(scope).replaceContextDependency(INDEPENDENT), scope.getContainingDeclaration(), klass,
|
scope, context.replaceScope(scope).replaceContextDependency(INDEPENDENT), scope.getContainingDeclaration(), klass,
|
||||||
components.additionalCheckerProvider);
|
components.additionalCheckerProvider);
|
||||||
|
|||||||
+102
@@ -0,0 +1,102 @@
|
|||||||
|
/*
|
||||||
|
* 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.lang.types.expressions;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicates;
|
||||||
|
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.descriptors.DeclarationDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.impl.PackageLikeBuilder;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||||
|
import org.jetbrains.jet.lang.resolve.AdditionalCheckerProvider;
|
||||||
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
|
import org.jetbrains.jet.lang.resolve.TopDownAnalysisContext;
|
||||||
|
import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters;
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
/* package */ class LocalClassifierAnalyzer {
|
||||||
|
public static void processClassOrObject(
|
||||||
|
@NotNull GlobalContext globalContext,
|
||||||
|
@Nullable final WritableScope scope,
|
||||||
|
@NotNull ExpressionTypingContext context,
|
||||||
|
@NotNull final DeclarationDescriptor containingDeclaration,
|
||||||
|
@NotNull JetClassOrObject object,
|
||||||
|
@NotNull AdditionalCheckerProvider additionalCheckerProvider
|
||||||
|
) {
|
||||||
|
TopDownAnalysisParameters topDownAnalysisParameters =
|
||||||
|
TopDownAnalysisParameters.createForLocalDeclarations(
|
||||||
|
globalContext.getStorageManager(),
|
||||||
|
globalContext.getExceptionTracker(),
|
||||||
|
Predicates.equalTo(object.getContainingFile())
|
||||||
|
);
|
||||||
|
|
||||||
|
InjectorForTopDownAnalyzerBasic injector = new InjectorForTopDownAnalyzerBasic(
|
||||||
|
object.getProject(),
|
||||||
|
topDownAnalysisParameters,
|
||||||
|
context.trace,
|
||||||
|
DescriptorUtils.getContainingModule(containingDeclaration),
|
||||||
|
additionalCheckerProvider
|
||||||
|
);
|
||||||
|
|
||||||
|
TopDownAnalysisContext c = new TopDownAnalysisContext(topDownAnalysisParameters);
|
||||||
|
c.setOuterDataFlowInfo(context.dataFlowInfo);
|
||||||
|
|
||||||
|
injector.getTopDownAnalyzer().doProcess(
|
||||||
|
c,
|
||||||
|
context.scope,
|
||||||
|
new PackageLikeBuilder() {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public DeclarationDescriptor getOwnerForChildren() {
|
||||||
|
return containingDeclaration;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addClassifierDescriptor(@NotNull MutableClassDescriptor classDescriptor) {
|
||||||
|
if (scope != null) {
|
||||||
|
scope.addClassifierDescriptor(classDescriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Collections.<PsiElement>singletonList(object)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user