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