From bfbcaba0b0211c3c627dcfb6c20605b30673e47b Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Thu, 30 Jan 2014 16:43:49 +0400 Subject: [PATCH] Use lazy analysis in intention actions --- .../ReconstructTypeInCastOrIsAction.java | 3 +-- .../BranchedUnfoldingUtils.java | 8 ++++---- .../branchedTransformations/UnfoldableKind.java | 4 ++-- .../intentions/declarations/DeclarationUtils.java | 14 +++++--------- .../SplitPropertyDeclarationIntention.kt | 5 +---- 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/ReconstructTypeInCastOrIsAction.java b/idea/src/org/jetbrains/jet/plugin/intentions/ReconstructTypeInCastOrIsAction.java index eb93db5f9cb..c2c09440c11 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/ReconstructTypeInCastOrIsAction.java +++ b/idea/src/org/jetbrains/jet/plugin/intentions/ReconstructTypeInCastOrIsAction.java @@ -81,7 +81,6 @@ public class ReconstructTypeInCastOrIsAction extends PsiElementBaseIntentionActi } private static JetType getReconstructedType(JetTypeReference typeRef) { - BindingContext bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) typeRef.getContainingFile()).getBindingContext(); - return bindingContext.get(BindingContext.TYPE, typeRef); + return AnalyzerFacadeWithCache.getContextForElement(typeRef).get(BindingContext.TYPE, typeRef); } } diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/BranchedUnfoldingUtils.java b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/BranchedUnfoldingUtils.java index b456b4876c4..4cc4e8b2692 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/BranchedUnfoldingUtils.java +++ b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/BranchedUnfoldingUtils.java @@ -127,13 +127,13 @@ public class BranchedUnfoldingUtils { editor.getCaretModel().moveToOffset(resultElement.getTextOffset()); } - public static void unfoldPropertyToIf(@NotNull JetProperty property, @NotNull JetFile file, @NotNull Editor editor) { - JetBinaryExpression assignment = DeclarationUtils.splitPropertyDeclaration(property, file); + public static void unfoldPropertyToIf(@NotNull JetProperty property, @NotNull Editor editor) { + JetBinaryExpression assignment = DeclarationUtils.splitPropertyDeclaration(property); unfoldAssignmentToIf(assignment, editor); } - public static void unfoldPropertyToWhen(@NotNull JetProperty property, @NotNull JetFile file, @NotNull Editor editor) { - JetBinaryExpression assignment = DeclarationUtils.splitPropertyDeclaration(property, file); + public static void unfoldPropertyToWhen(@NotNull JetProperty property, @NotNull Editor editor) { + JetBinaryExpression assignment = DeclarationUtils.splitPropertyDeclaration(property); unfoldAssignmentToWhen(assignment, editor); } diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/UnfoldableKind.java b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/UnfoldableKind.java index 9c99d7eb807..2c754f12e90 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/UnfoldableKind.java +++ b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/UnfoldableKind.java @@ -35,7 +35,7 @@ public enum UnfoldableKind implements Transformer { PROPERTY_TO_IF("unfold.property.to.if") { @Override public void transform(@NotNull PsiElement element, @NotNull Editor editor, JetFile file) { - BranchedUnfoldingUtils.unfoldPropertyToIf((JetProperty) element, file, editor); + BranchedUnfoldingUtils.unfoldPropertyToIf((JetProperty) element, editor); } }, RETURN_TO_IF("unfold.return.to.if") { @@ -53,7 +53,7 @@ public enum UnfoldableKind implements Transformer { PROPERTY_TO_WHEN("unfold.property.to.when") { @Override public void transform(@NotNull PsiElement element, @NotNull Editor editor, JetFile file) { - BranchedUnfoldingUtils.unfoldPropertyToWhen((JetProperty) element, file, editor); + BranchedUnfoldingUtils.unfoldPropertyToWhen((JetProperty) element, editor); } }, RETURN_TO_WHEN("unfold.return.to.when") { diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/declarations/DeclarationUtils.java b/idea/src/org/jetbrains/jet/plugin/intentions/declarations/DeclarationUtils.java index e0e53c40b61..107a93f7052 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/declarations/DeclarationUtils.java +++ b/idea/src/org/jetbrains/jet/plugin/intentions/declarations/DeclarationUtils.java @@ -33,8 +33,6 @@ import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache; import org.jetbrains.jet.plugin.util.JetPsiMatcher; import org.jetbrains.jet.renderer.DescriptorRenderer; -import java.util.Collections; - public class DeclarationUtils { private DeclarationUtils() { } @@ -84,20 +82,18 @@ public class DeclarationUtils { } @Nullable - private static JetType getPropertyTypeIfNeeded(@NotNull JetProperty property, @NotNull JetFile file) { + private static JetType getPropertyTypeIfNeeded(@NotNull JetProperty property) { if (property.getTypeRef() != null) return null; - JetType type = AnalyzerFacadeWithCache.analyzeFileWithCache(file).getBindingContext().get( - BindingContext.EXPRESSION_TYPE, - property.getInitializer() + JetType type = AnalyzerFacadeWithCache.getContextForElement(property).get( + BindingContext.EXPRESSION_TYPE, property.getInitializer() ); - return type == null || type.isError() ? null : type; } // returns assignment which replaces initializer @NotNull - public static JetBinaryExpression splitPropertyDeclaration(@NotNull JetProperty property, @NotNull JetFile file) { + public static JetBinaryExpression splitPropertyDeclaration(@NotNull JetProperty property) { Project project = property.getProject(); PsiElement parent = property.getParent(); @@ -116,7 +112,7 @@ public class DeclarationUtils { parent.addAfter(JetPsiFactory.createNewLine(project), property); //noinspection ConstantConditions - JetType inferredType = getPropertyTypeIfNeeded(property, file); + JetType inferredType = getPropertyTypeIfNeeded(property); String typeStr = inferredType != null ? DescriptorRenderer.TEXT.renderType(inferredType) diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/declarations/SplitPropertyDeclarationIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/declarations/SplitPropertyDeclarationIntention.kt index 86aba6b53a4..b681b7f2d2c 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/declarations/SplitPropertyDeclarationIntention.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/declarations/SplitPropertyDeclarationIntention.kt @@ -29,9 +29,6 @@ public class SplitPropertyDeclarationIntention : JetSelfTargetingIntention