Use lazy analysis in intention actions

This commit is contained in:
Alexey Sedunov
2014-01-30 16:43:49 +04:00
parent a43404d7eb
commit bfbcaba0b0
5 changed files with 13 additions and 21 deletions
@@ -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);
}
}
@@ -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);
}
@@ -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") {
@@ -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)
@@ -29,9 +29,6 @@ public class SplitPropertyDeclarationIntention : JetSelfTargetingIntention<JetPr
override fun isApplicableTo(element: JetProperty): Boolean = DeclarationUtils.checkSplitProperty(element)
override fun applyTo(element: JetProperty, editor: Editor) {
val file = element.getContainingFile()
if (file is JetFile) {
DeclarationUtils.splitPropertyDeclaration(element, file)
}
DeclarationUtils.splitPropertyDeclaration(element)
}
}