From b104d70196b577b399c52eca150bc1ded32977dc Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Fri, 8 Jun 2012 22:53:17 +0400 Subject: [PATCH] More aggressive block cache invalidation for declarations with type inference --- .../lang/psi/JetModifiableBlockHelper.java | 28 +++++++++++++++++-- .../outOfBlock/InAntonymsObjectDeclaration.kt | 6 ++++ .../OutOfBlockModificationTest.java | 4 +++ 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 idea/testData/codeInsight/outOfBlock/InAntonymsObjectDeclaration.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetModifiableBlockHelper.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetModifiableBlockHelper.java index 70ed7f8c362..a5e3ddf140c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetModifiableBlockHelper.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetModifiableBlockHelper.java @@ -35,18 +35,18 @@ public final class JetModifiableBlockHelper { if (declaration instanceof JetNamedFunction) { JetNamedFunction function = (JetNamedFunction) declaration; if (function.hasDeclaredReturnType() || function.hasBlockBody()) { - return false; + return takePartInDeclarationTypeInference(function); } return shouldChangeModificationCount(function); } else if (declaration instanceof JetPropertyAccessor) { - return false; + return takePartInDeclarationTypeInference(declaration); } else if (declaration instanceof JetProperty) { JetProperty property = (JetProperty) declaration; if (property.getPropertyTypeRef() != null) { - return false; + return takePartInDeclarationTypeInference(property); } return shouldChangeModificationCount(property); @@ -59,4 +59,26 @@ public final class JetModifiableBlockHelper { return true; } + + private static boolean takePartInDeclarationTypeInference(PsiElement place) { + JetDeclaration declaration = PsiTreeUtil.getParentOfType(place, JetDeclaration.class, true); + if (declaration != null) { + if (declaration instanceof JetNamedFunction) { + JetNamedFunction function = (JetNamedFunction) declaration; + if (!function.hasDeclaredReturnType()) { + return true; + } + } + else if (declaration instanceof JetProperty) { + JetProperty property = (JetProperty) declaration; + if (property.getPropertyTypeRef() == null) { + return true; + } + } + + return takePartInDeclarationTypeInference(declaration); + } + + return false; + } } diff --git a/idea/testData/codeInsight/outOfBlock/InAntonymsObjectDeclaration.kt b/idea/testData/codeInsight/outOfBlock/InAntonymsObjectDeclaration.kt new file mode 100644 index 00000000000..2fa2ca10eb4 --- /dev/null +++ b/idea/testData/codeInsight/outOfBlock/InAntonymsObjectDeclaration.kt @@ -0,0 +1,6 @@ +// TRUE +val o = object { + fun test() { + + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/OutOfBlockModificationTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/OutOfBlockModificationTest.java index c81dd27ed55..91fdb68703a 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/OutOfBlockModificationTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/OutOfBlockModificationTest.java @@ -54,6 +54,10 @@ public class OutOfBlockModificationTest extends LightCodeInsightFixtureTestCase doTest(); } + public void testInAntonymsObjectDeclaration() { + doTest(); + } + public void testInPropertyWithFunctionLiteral() { doTest(); }