Refactoring: use utility method for getting binding context with resolution for element
This commit is contained in:
+5
-6
@@ -23,10 +23,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetBlockExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.plugin.codeInsight.CodeInsightUtils;
|
||||
@@ -36,6 +33,9 @@ public class KotlinSurrounderUtils {
|
||||
public static String SURROUND_WITH = JetBundle.message("surround.with");
|
||||
public static String SURROUND_WITH_ERROR = JetBundle.message("surround.with.cannot.perform.action");
|
||||
|
||||
private KotlinSurrounderUtils() {
|
||||
}
|
||||
|
||||
public static void addStatementsInBlock(
|
||||
@NotNull JetBlockExpression block,
|
||||
@NotNull PsiElement[] statements
|
||||
@@ -46,12 +46,11 @@ public class KotlinSurrounderUtils {
|
||||
|
||||
@Nullable
|
||||
public static JetType getExpressionType(JetExpression expression) {
|
||||
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) expression.getContainingFile());
|
||||
BindingContext expressionBindingContext = ResolveSessionUtils.resolveToElement(resolveSession, expression);
|
||||
BindingContext expressionBindingContext = WholeProjectAnalyzerFacade.getContextForElement(expression);
|
||||
return expressionBindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
||||
}
|
||||
|
||||
public static void showErrorHint(@NotNull Project project, @NotNull Editor editor, @NotNull String message) {
|
||||
CodeInsightUtils.showErrorHint(project, editor, message, KotlinSurrounderUtils.SURROUND_WITH, null);
|
||||
CodeInsightUtils.showErrorHint(project, editor, message, SURROUND_WITH, null);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-4
@@ -28,8 +28,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.plugin.codeInsight.CodeInsightUtils;
|
||||
@@ -119,8 +117,7 @@ public class MoveDeclarationsOutHelper {
|
||||
|
||||
@NotNull
|
||||
private static JetType getPropertyType(@NotNull JetProperty property) {
|
||||
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) property.getContainingFile());
|
||||
BindingContext expressionBindingContext = ResolveSessionUtils.resolveToElement(resolveSession, property);
|
||||
BindingContext expressionBindingContext = WholeProjectAnalyzerFacade.getContextForElement(property);
|
||||
|
||||
VariableDescriptor propertyDescriptor = expressionBindingContext.get(BindingContext.VARIABLE, property);
|
||||
assert propertyDescriptor != null : "Couldn't resolve property to property descriptor " + property.getText();
|
||||
|
||||
@@ -32,8 +32,6 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
@@ -178,8 +176,7 @@ public class JetImportOptimizer implements ImportOptimizer {
|
||||
|
||||
@Override
|
||||
public void visitForExpression(JetForExpression expression) {
|
||||
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) expression.getContainingFile());
|
||||
BindingContext context = ResolveSessionUtils.resolveToElement(resolveSession, expression);
|
||||
BindingContext context = WholeProjectAnalyzerFacade.getContextForElement(expression);
|
||||
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.LOOP_RANGE_ITERATOR_RESOLVED_CALL, expression.getLoopRange());
|
||||
addResolvedCallFqName(resolvedCall);
|
||||
|
||||
@@ -188,8 +185,7 @@ public class JetImportOptimizer implements ImportOptimizer {
|
||||
|
||||
@Override
|
||||
public void visitMultiDeclaration(JetMultiDeclaration declaration) {
|
||||
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) declaration.getContainingFile());
|
||||
BindingContext context = ResolveSessionUtils.resolveToElement(resolveSession, declaration);
|
||||
BindingContext context = WholeProjectAnalyzerFacade.getContextForElement(declaration);
|
||||
List<JetMultiDeclarationEntry> entries = declaration.getEntries();
|
||||
for (JetMultiDeclarationEntry entry : entries) {
|
||||
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
|
||||
|
||||
@@ -279,7 +279,7 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
|
||||
JetFile file = (JetFile)elt.getContainingFile();
|
||||
assert file != null;
|
||||
|
||||
BindingContext bindingContext = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile(file).getBindingContext();
|
||||
BindingContext bindingContext = WholeProjectAnalyzerFacade.getContextForElement((JetElement) elt);
|
||||
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, elt);
|
||||
if (!(descriptor instanceof CallableMemberDescriptor)) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user