From 48a43ddbb1a7e96329689c958b71e7d9e6134fa0 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 11 Apr 2017 10:26:36 +0200 Subject: [PATCH 01/66] StartupManager: avoid data races when registering post-startup activity from a bg thread, after project closing but before disposing --- .../ide/startup/impl/StartupManagerImpl.java | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java b/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java index a6b88340aa25..bf33a8f37d5e 100644 --- a/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/startup/impl/StartupManagerImpl.java @@ -203,7 +203,10 @@ public class StartupManagerImpl extends StartupManagerEx { dumbService.runWhenSmart(this); } else { - myPostStartupActivitiesPassed = true; + //noinspection SynchronizeOnThis + synchronized (this) { + myPostStartupActivitiesPassed = true; + } } } }); @@ -362,28 +365,23 @@ public class StartupManagerImpl extends StartupManagerEx { final Application application = ApplicationManager.getApplication(); if (application == null) return; - //noinspection SynchronizeOnThis - synchronized (this) { - // in tests which simulate project opening, post-startup activities could have been run already. - // Then we should act as if the project was initialized - boolean initialized = myProject.isInitialized() || myProject.isDefault() || application.isUnitTestMode() && myPostStartupActivitiesPassed; - if (!initialized) { - registerPostStartupActivity(action); - return; - } - } - Runnable runnable = () -> { - if (!myProject.isDisposed()) { - action.run(); + if (myProject.isDisposed()) return; + + //noinspection SynchronizeOnThis + synchronized (this) { + // in tests which simulate project opening, post-startup activities could have been run already. + // Then we should act as if the project was initialized + boolean initialized = myProject.isInitialized() || myProject.isDefault() || application.isUnitTestMode() && myPostStartupActivitiesPassed; + if (!initialized) { + registerPostStartupActivity(action); + return; + } } + + action.run(); }; - if (application.isDispatchThread()) { - runnable.run(); - } - else { - application.invokeLater(runnable, ModalityState.NON_MODAL); - } + GuiUtils.invokeLaterIfNeeded(runnable, ModalityState.NON_MODAL); } @TestOnly From 09c2af0f985da79b888d4268ee966eee546ec827 Mon Sep 17 00:00:00 2001 From: nik Date: Tue, 11 Apr 2017 11:50:06 +0300 Subject: [PATCH 02/66] build scripts: fixed updating from sources for IDEA Community --- build/scripts/idea_community.gant | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/build/scripts/idea_community.gant b/build/scripts/idea_community.gant index 8c0a6545572b..bd80d28014a3 100644 --- a/build/scripts/idea_community.gant +++ b/build/scripts/idea_community.gant @@ -42,4 +42,14 @@ target('update-from-sources': 'Update locally installed distribution from compil //when IDEA CE is updated from IDEA UE sources project should be loaded from IDEA UE directory String projectHome = isDefined("devIdeaHome") ? devIdeaHome : home new IdeaCommunityBuilder(home, binding, options, projectHome).buildUnpackedDistribution(deploy) -} \ No newline at end of file +} + +private boolean isDefined(String key) { + try { + this[key] + return true + } + catch (MissingPropertyException ignored) { + return false + } +} From c3d3de886d315fd0d8680d502eb9746e04060614 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Wed, 15 Mar 2017 13:41:35 +0300 Subject: [PATCH 03/66] diff: update test data --- .../tests/com/intellij/diff/DiffTestCase.kt | 14 ++++- .../comparison/ComparisonMergeUtilTestBase.kt | 8 +-- .../diff/comparison/ComparisonUtilAutoTest.kt | 6 +- .../diff/comparison/ComparisonUtilTestBase.kt | 14 ++--- .../comparison/IgnoreComparisonUtilTest.kt | 21 ++----- .../comparison/SplitComparisonUtilTest.kt | 17 ++++++ .../diff/comparison/WordComparisonUtilTest.kt | 59 +++++++++++++++++++ 7 files changed, 108 insertions(+), 31 deletions(-) diff --git a/platform/diff-impl/tests/com/intellij/diff/DiffTestCase.kt b/platform/diff-impl/tests/com/intellij/diff/DiffTestCase.kt index 6bcb79123e0c..bb501a53faa3 100644 --- a/platform/diff-impl/tests/com/intellij/diff/DiffTestCase.kt +++ b/platform/diff-impl/tests/com/intellij/diff/DiffTestCase.kt @@ -115,6 +115,18 @@ abstract class DiffTestCase : TestCase() { } } + fun assertSetsEquals(expected: BitSet, actual: BitSet, message: String = "") { + val sb = StringBuilder(message) + sb.append(": \"") + for (i in 0..actual.length()) { + sb.append(if (actual[i]) '-' else ' ') + } + sb.append('"') + val fullMessage = sb.toString() + + assertEquals(expected, actual, fullMessage) + } + // // Parsing // @@ -210,7 +222,7 @@ abstract class DiffTestCase : TestCase() { } } - class DebugData() { + class DebugData { private val data: MutableList> = ArrayList() fun put(key: String, value: Any) { diff --git a/platform/diff-impl/tests/com/intellij/diff/comparison/ComparisonMergeUtilTestBase.kt b/platform/diff-impl/tests/com/intellij/diff/comparison/ComparisonMergeUtilTestBase.kt index c116de58652e..249bf8674e48 100644 --- a/platform/diff-impl/tests/com/intellij/diff/comparison/ComparisonMergeUtilTestBase.kt +++ b/platform/diff-impl/tests/com/intellij/diff/comparison/ComparisonMergeUtilTestBase.kt @@ -73,12 +73,12 @@ abstract class ComparisonMergeUtilTestBase : DiffTestCase() { val sets = Trio(BitSet(), BitSet(), BitSet()) for (change in changes) { - sets.forEach({ set: BitSet, side: ThreeSide -> set.set(change.start(side), change.end(side)) }) + sets.forEach { set: BitSet, side: ThreeSide -> set.set(change.start(side), change.end(side)) } } - assertEquals(matchings.data1, sets.data1) - assertEquals(matchings.data2, sets.data2) - assertEquals(matchings.data3, sets.data3) + assertSetsEquals(matchings.data1, sets.data1, "Left") + assertSetsEquals(matchings.data2, sets.data2, "Base") + assertSetsEquals(matchings.data3, sets.data3, "Right") } private fun convertDiffFragments(fragments: List): List { diff --git a/platform/diff-impl/tests/com/intellij/diff/comparison/ComparisonUtilAutoTest.kt b/platform/diff-impl/tests/com/intellij/diff/comparison/ComparisonUtilAutoTest.kt index c415aa47ae47..b117f7261577 100644 --- a/platform/diff-impl/tests/com/intellij/diff/comparison/ComparisonUtilAutoTest.kt +++ b/platform/diff-impl/tests/com/intellij/diff/comparison/ComparisonUtilAutoTest.kt @@ -198,8 +198,8 @@ class ComparisonUtilAutoTest : DiffTestCase() { for (fragment in fragments) { if (fragment.innerFragments != null) { - val sequence1 = text1.subsequence(fragment.startOffset1, fragment.endOffset1) - val sequence2 = text2.subsequence(fragment.startOffset2, fragment.endOffset2) + val sequence1 = text1.subSequence(fragment.startOffset1, fragment.endOffset1) + val sequence2 = text2.subSequence(fragment.startOffset2, fragment.endOffset2) checkResultWord(sequence1, sequence2, fragment.innerFragments!!, policy) } @@ -538,7 +538,7 @@ class ComparisonUtilAutoTest : DiffTestCase() { return Couple.of(firstLine, lastLine) } - private fun Document.subsequence(start: Int, end: Int): CharSequence { + private fun Document.subSequence(start: Int, end: Int): CharSequence { return this.charsSequence.subSequence(start, end) } diff --git a/platform/diff-impl/tests/com/intellij/diff/comparison/ComparisonUtilTestBase.kt b/platform/diff-impl/tests/com/intellij/diff/comparison/ComparisonUtilTestBase.kt index 9d9bf6796202..f8750fc000dc 100644 --- a/platform/diff-impl/tests/com/intellij/diff/comparison/ComparisonUtilTestBase.kt +++ b/platform/diff-impl/tests/com/intellij/diff/comparison/ComparisonUtilTestBase.kt @@ -173,8 +173,8 @@ abstract class ComparisonUtilTestBase : DiffTestCase() { set2.set(fragment.startLine2, fragment.endLine2) } - assertEquals(matchings.first, set1, "Before") - assertEquals(matchings.second, set2, "After") + assertSetsEquals(matchings.first, set1, "Before") + assertSetsEquals(matchings.second, set2, "After") } private fun checkDiffMatching(fragments: List, matchings: Couple) { @@ -185,8 +185,8 @@ abstract class ComparisonUtilTestBase : DiffTestCase() { set2.set(fragment.startOffset2, fragment.endOffset2) } - assertEquals(matchings.first, set1, "Before") - assertEquals(matchings.second, set2, "After") + assertSetsEquals(matchings.first, set1, "Before") + assertSetsEquals(matchings.second, set2, "After") } private fun checkMergeMatching(fragments: List, matchings: Trio) { @@ -199,9 +199,9 @@ abstract class ComparisonUtilTestBase : DiffTestCase() { set3.set(fragment.getStartOffset(ThreeSide.RIGHT), fragment.getEndOffset(ThreeSide.RIGHT)) } - assertEquals(matchings.data1, set1, "Before") - assertEquals(matchings.data2, set2, "Base") - assertEquals(matchings.data3, set3, "After") + assertSetsEquals(matchings.data1, set1, "Left") + assertSetsEquals(matchings.data2, set2, "Base") + assertSetsEquals(matchings.data3, set3, "Right") } private fun convertDiffFragments(fragments: List): List> { diff --git a/platform/diff-impl/tests/com/intellij/diff/comparison/IgnoreComparisonUtilTest.kt b/platform/diff-impl/tests/com/intellij/diff/comparison/IgnoreComparisonUtilTest.kt index fce98b3c2574..825437f5cd43 100644 --- a/platform/diff-impl/tests/com/intellij/diff/comparison/IgnoreComparisonUtilTest.kt +++ b/platform/diff-impl/tests/com/intellij/diff/comparison/IgnoreComparisonUtilTest.kt @@ -401,28 +401,17 @@ class IgnoreComparisonUtilTest : DiffTestCase() { .run() } - private inner class Test(input1: String, input2: String, + private inner class Test(val input1: String, val input2: String, ignored1: String, ignored2: String, result1: String, result2: String) { - private val input1: String - private val input2: String - private val ignored1: String - private val ignored2: String - private val result1: String - private val result2: String + val ignored1: String = ignored1.filterNot { it == '.' } + val ignored2: String = ignored2.filterNot { it == '.' } + val result1: String = result1.filterNot { it == '.' } + val result2: String = result2.filterNot { it == '.' } private var inner = true private var changedLines: IntPair? = null - init { - this.input1 = input1 - this.input2 = input2 - this.ignored1 = ignored1.filterNot { it == '.' } - this.ignored2 = ignored2.filterNot { it == '.' } - this.result1 = result1.filterNot { it == '.' } - this.result2 = result2.filterNot { it == '.' } - } - fun noInnerChanges(): Test { inner = false return this diff --git a/platform/diff-impl/tests/com/intellij/diff/comparison/SplitComparisonUtilTest.kt b/platform/diff-impl/tests/com/intellij/diff/comparison/SplitComparisonUtilTest.kt index 0e52c2c09115..e25ec85c1243 100644 --- a/platform/diff-impl/tests/com/intellij/diff/comparison/SplitComparisonUtilTest.kt +++ b/platform/diff-impl/tests/com/intellij/diff/comparison/SplitComparisonUtilTest.kt @@ -74,6 +74,23 @@ class SplitComparisonUtilTest : ComparisonUtilTestBase() { default(del(0, 0, 1), mod(1, 0, 1, 1), del(2, 1, 1)) testAll() } + + splitter(trim = false) { + ("< i" - "" - "x'y'>") + (" " - " -- ").default() + testAll() + } + + lines_inner { + ("x'y'>" - "x'>") + (" -- " - " ").default() + testAll() + } } fun testWhitespaceOnlyChanges() { @@ -219,6 +252,12 @@ class WordComparisonUtilTest : ComparisonUtilTestBase() { ("- -" - "- -").ignore() testIgnore() } + + words { + ("A_B_" - "X_") + ("--- " - "- ").default() + testAll() + } } fun testFixedBugs() { @@ -336,6 +375,26 @@ class WordComparisonUtilTest : ComparisonUtilTestBase() { (" ---" - "--- ").default() testDefault() } + + lines_inner { + ("A B_C D" - "A_B C_D") + (" -- - " - " -- - ").default() + (" -- - " - " -- ").trim() + (" - " - " - ").ignore() + testAll() + } + + lines_inner { + ("B_C_D_" - "X_Y_Z_") + ("- - - " - "- - - ").default() + testAll() + } + + words { + ("!x_!_z" - "!_!_y z") + (" - " - " -- ").default() + testDefault() + } } fun `test trailing punctuation`() { From 8ea1d42ecf8a49cff25b8187a773d337be885aac Mon Sep 17 00:00:00 2001 From: Denis Fokin Date: Tue, 11 Apr 2017 12:31:27 +0300 Subject: [PATCH 04/66] IDEA-170605 the modal progress window steals focus from a editor --- .../intellij/openapi/ui/impl/GlassPaneDialogWrapperPeer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/impl/GlassPaneDialogWrapperPeer.java b/platform/platform-impl/src/com/intellij/openapi/ui/impl/GlassPaneDialogWrapperPeer.java index 94b7bcbf753e..7c6de1ea7ba6 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/impl/GlassPaneDialogWrapperPeer.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/impl/GlassPaneDialogWrapperPeer.java @@ -581,8 +581,8 @@ public class GlassPaneDialogWrapperPeer extends DialogWrapperPeer implements Foc @Override public void dispose() { - setVisible(false); remove(getContentPane()); + setVisible(false); DialogWrapper.unregisterKeyboardActions(myWrapperPane); myRootPane = null; } From c9554bd544ba299b9d9aebae531f7e25f673586c Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Tue, 11 Apr 2017 11:30:10 +0200 Subject: [PATCH 05/66] move initializer to setup: should work when setup method is there (IDEA-171236) --- .../MoveInitializerToSetUpMethodAction.java | 33 ++++++++++--------- .../afterJUnit4WithBeforeOnly.java | 10 ++++++ .../beforeJUnit4WithBeforeOnly.java | 9 +++++ 3 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/moveInitializerToSetUp/afterJUnit4WithBeforeOnly.java create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/moveInitializerToSetUp/beforeJUnit4WithBeforeOnly.java diff --git a/java/java-impl/src/com/intellij/testIntegration/intention/MoveInitializerToSetUpMethodAction.java b/java/java-impl/src/com/intellij/testIntegration/intention/MoveInitializerToSetUpMethodAction.java index fdaa574c2871..d3c6c07977a0 100644 --- a/java/java-impl/src/com/intellij/testIntegration/intention/MoveInitializerToSetUpMethodAction.java +++ b/java/java-impl/src/com/intellij/testIntegration/intention/MoveInitializerToSetUpMethodAction.java @@ -20,13 +20,11 @@ import com.intellij.codeInsight.TestFrameworks; import com.intellij.codeInsight.intention.impl.BaseMoveInitializerToMethodAction; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.testIntegration.JavaTestFramework; import com.intellij.testIntegration.TestFramework; -import com.intellij.testIntegration.TestIntegrationUtils; import org.jetbrains.annotations.NotNull; import java.util.Arrays; @@ -53,25 +51,23 @@ public class MoveInitializerToSetUpMethodAction extends BaseMoveInitializerToMet @Override public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) { - final boolean isAvailable = super.isAvailable(project, editor, element) && TestIntegrationUtils.isTest(element); + final boolean isAvailable = super.isAvailable(project, editor, element); if (isAvailable) { final PsiField field = PsiTreeUtil.getParentOfType(element, PsiField.class); LOG.assertTrue(field != null); final PsiClass aClass = field.getContainingClass(); LOG.assertTrue(aClass != null); + TestFramework testFramework = TestFrameworks.detectFramework(aClass); final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project); - for (TestFramework framework : Extensions.getExtensions(TestFramework.EXTENSION_NAME)) { - if (framework instanceof JavaTestFramework && framework.isTestClass(aClass)) { - try { - ((JavaTestFramework)framework).createSetUpPatternMethod(elementFactory); - return true; - } - catch (Exception e) { - return false; - } + if (testFramework instanceof JavaTestFramework) { + try { + ((JavaTestFramework)testFramework).createSetUpPatternMethod(elementFactory); + return testFramework.isTestClass(aClass) || testFramework.findSetUpMethod(aClass) instanceof PsiMethod; + } + catch (Exception e) { + return false; } } - return true; } return false; } @@ -85,7 +81,14 @@ public class MoveInitializerToSetUpMethodAction extends BaseMoveInitializerToMet @NotNull @Override protected Collection getOrCreateMethods(@NotNull Project project, @NotNull Editor editor, PsiFile file, @NotNull PsiClass aClass) { - final PsiMethod setUpMethod = TestFrameworks.getInstance().findOrCreateSetUpMethod(aClass); - return setUpMethod == null ? Collections.emptyList() : Arrays.asList(setUpMethod); + TestFramework testFramework = TestFrameworks.detectFramework(aClass); + PsiElement setUpMethod = null; + if (testFramework != null) { + setUpMethod = testFramework.findSetUpMethod(aClass); + if (setUpMethod == null) { + setUpMethod = testFramework.findOrCreateSetUpMethod(aClass); + } + } + return setUpMethod instanceof PsiMethod ? Collections.singletonList((PsiMethod)setUpMethod) : Collections.emptyList(); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/moveInitializerToSetUp/afterJUnit4WithBeforeOnly.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/moveInitializerToSetUp/afterJUnit4WithBeforeOnly.java new file mode 100644 index 000000000000..a693577921ce --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/moveInitializerToSetUp/afterJUnit4WithBeforeOnly.java @@ -0,0 +1,10 @@ +// "Move initializer to setUp method" "true" +public class X { + int i; + + @org.junit.Before + public void setUp() throws Exception { + + i = 7; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/moveInitializerToSetUp/beforeJUnit4WithBeforeOnly.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/moveInitializerToSetUp/beforeJUnit4WithBeforeOnly.java new file mode 100644 index 000000000000..5af0027632a3 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/moveInitializerToSetUp/beforeJUnit4WithBeforeOnly.java @@ -0,0 +1,9 @@ +// "Move initializer to setUp method" "true" +public class X { + int i = 7; + + @org.junit.Before + public void setUp() throws Exception { + + } +} From ddb4bb31e90cff64300cc89af59d481d415039b7 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Tue, 11 Apr 2017 11:50:23 +0200 Subject: [PATCH 06/66] method may be void: don't warn for implicit reads --- .../unusedReturnValue/UnusedReturnValue.java | 5 +++- .../UnusedReturnValueLocalInspection.java | 4 ++- .../quickFix/NoChangeForImplicitRead.java | 9 +++++++ .../UnusedReturnValueQuickFixTest.java | 27 +++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 java/java-tests/testData/inspection/unusedReturnValue/quickFix/NoChangeForImplicitRead.java diff --git a/java/java-impl/src/com/intellij/codeInspection/unusedReturnValue/UnusedReturnValue.java b/java/java-impl/src/com/intellij/codeInspection/unusedReturnValue/UnusedReturnValue.java index 01d40e0e3f5b..e012812e3cf8 100644 --- a/java/java-impl/src/com/intellij/codeInspection/unusedReturnValue/UnusedReturnValue.java +++ b/java/java-impl/src/com/intellij/codeInspection/unusedReturnValue/UnusedReturnValue.java @@ -21,7 +21,9 @@ import com.intellij.codeInspection.*; import com.intellij.codeInspection.reference.*; import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel; import com.intellij.openapi.util.WriteExternalException; -import com.intellij.psi.*; +import com.intellij.psi.PsiMethod; +import com.intellij.psi.PsiModifier; +import com.intellij.psi.PsiReference; import com.intellij.psi.util.PropertyUtil; import org.jdom.Element; import org.jetbrains.annotations.NotNull; @@ -55,6 +57,7 @@ public class UnusedReturnValue extends GlobalJavaBatchInspectionTool{ final boolean isNative = psiMethod.hasModifierProperty(PsiModifier.NATIVE); if (refMethod.isExternalOverride() && !isNative) return null; + if (RefUtil.isImplicitRead(psiMethod)) return null; return new ProblemDescriptor[]{createProblemDescriptor(psiMethod, manager, processor, isNative)}; } } diff --git a/java/java-impl/src/com/intellij/codeInspection/unusedReturnValue/UnusedReturnValueLocalInspection.java b/java/java-impl/src/com/intellij/codeInspection/unusedReturnValue/UnusedReturnValueLocalInspection.java index 850e45c9db92..decd81176a26 100644 --- a/java/java-impl/src/com/intellij/codeInspection/unusedReturnValue/UnusedReturnValueLocalInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/unusedReturnValue/UnusedReturnValueLocalInspection.java @@ -19,6 +19,7 @@ import com.intellij.codeInsight.daemon.impl.UnusedSymbolUtil; import com.intellij.codeInspection.BaseJavaLocalInspectionTool; import com.intellij.codeInspection.InspectionManager; import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.codeInspection.reference.RefUtil; import com.intellij.openapi.progress.EmptyProgressIndicator; import com.intellij.patterns.PsiJavaPatterns; import com.intellij.psi.*; @@ -57,7 +58,8 @@ public class UnusedReturnValueLocalInspection extends BaseJavaLocalInspectionToo PsiType.VOID.equals(method.getReturnType()) || myGlobal.IGNORE_BUILDER_PATTERN && PropertyUtil.isSimplePropertySetter(method) || method.hasModifierProperty(PsiModifier.NATIVE) || - MethodUtils.hasSuper(method)) return null; + MethodUtils.hasSuper(method) || + RefUtil.isImplicitRead(method)) return null; final boolean[] atLeastOneUsageExists = new boolean[]{false}; if (UnusedSymbolUtil.processUsages(manager.getProject(), method.getContainingFile(), method, new EmptyProgressIndicator(), null, u -> { diff --git a/java/java-tests/testData/inspection/unusedReturnValue/quickFix/NoChangeForImplicitRead.java b/java/java-tests/testData/inspection/unusedReturnValue/quickFix/NoChangeForImplicitRead.java new file mode 100644 index 000000000000..3b544339d2ac --- /dev/null +++ b/java/java-tests/testData/inspection/unusedReturnValue/quickFix/NoChangeForImplicitRead.java @@ -0,0 +1,9 @@ +class Test { + public String implicitRead() { + return ""; + } + + { + implicitRead(); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/UnusedReturnValueQuickFixTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/UnusedReturnValueQuickFixTest.java index 7048df0f57bb..dcff2ac300c4 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/UnusedReturnValueQuickFixTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/UnusedReturnValueQuickFixTest.java @@ -16,7 +16,12 @@ package com.intellij.codeInspection; import com.intellij.JavaTestUtil; +import com.intellij.codeInsight.daemon.ImplicitUsageProvider; import com.intellij.codeInspection.unusedReturnValue.UnusedReturnValue; +import com.intellij.openapi.extensions.Extensions; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiMethod; +import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; /** @@ -27,11 +32,33 @@ public class UnusedReturnValueQuickFixTest extends LightCodeInsightFixtureTestCa @Override protected void setUp() throws Exception { super.setUp(); + PlatformTestUtil.registerExtension(Extensions.getRootArea(), ImplicitUsageProvider.EP_NAME, new ImplicitUsageProvider() { + @Override + public boolean isImplicitUsage(PsiElement element) { + return false; + } + + @Override + public boolean isImplicitRead(PsiElement element) { + return element instanceof PsiMethod && ((PsiMethod)element).getName().equals("implicitRead"); + } + + @Override + public boolean isImplicitWrite(PsiElement element) { + return false; + } + }, getTestRootDisposable()); + myFixture.enableInspections(new UnusedReturnValue()); } public void testSideEffects() { doTest(); } public void testRedundantReturn() { doTest(); } + public void testNoChangeForImplicitRead() { + final String name = getTestName(false); + myFixture.configureByFile(name + ".java"); + assertEmpty(myFixture.filterAvailableIntentions(InspectionsBundle.message("inspection.unused.return.value.make.void.quickfix"))); + } private void doTest() { final String name = getTestName(false); From b6d0200cfb61448ab8d0ae2b679ce67bbd30e9ca Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Tue, 11 Apr 2017 13:00:48 +0300 Subject: [PATCH 07/66] IDEA-171252 Debugger doesn't evaluate watches on breakpoint --- .../intellij/xdebugger/impl/ui/tree/nodes/WatchNodeImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/WatchNodeImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/WatchNodeImpl.java index 0d6725dde9bb..7203b7230e3c 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/WatchNodeImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/tree/nodes/WatchNodeImpl.java @@ -95,6 +95,9 @@ public class WatchNodeImpl extends XValueNodeImpl implements WatchNode { return; } } + else { + return; // do not set anything if view is not visible, otherwise the code in computePresentationIfNeeded() will not work + } } node.setPresentation(AllIcons.Debugger.Watch, EMPTY_PRESENTATION, false); From 243800e6f6cefe813dc9226e8caa03613416907c Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Tue, 11 Apr 2017 17:46:20 +0700 Subject: [PATCH 08/66] IDEA-109323 "Numeric cast that loses precision" inspection should analyze flow --- .../siyeh/InspectionGadgetsBundle.properties | 1 + .../CastThatLosesPrecisionInspection.java | 57 +++++++++++++++++-- .../CastThatLosesPrecision.java | 46 +++++++++++++-- .../cast_that_loses_precision/expected.xml | 7 +++ 4 files changed, 99 insertions(+), 12 deletions(-) diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties index ea03a59930c2..7a34944e258f 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties @@ -1198,6 +1198,7 @@ remove.modifier.quickfix=Remove ''{0}'' modifier replace.inheritance.with.delegation.quickfix=Replace inheritance with delegation big.decimal.equals.replace.quickfix=Replace with 'compareTo()==0' cast.that.loses.precision.problem.descriptor=Cast to #ref from ''{0}'' may result in loss of precision #loc +cast.that.loses.precision.negative.problem.descriptor=Cast to #ref from ''{0}'' may result in loss of precision #loc for negative argument comparison.to.nan.problem.descriptor1=Comparison to #ref is always false #loc comparison.to.nan.problem.descriptor2=Comparison to #ref is always true #loc comparison.to.nan.replace.quickfix=Replace with 'isNaN()' diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/CastThatLosesPrecisionInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/CastThatLosesPrecisionInspection.java index e5b362f2247c..8087a528ff18 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/CastThatLosesPrecisionInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/CastThatLosesPrecisionInspection.java @@ -15,7 +15,11 @@ */ package com.siyeh.ig.numeric; +import com.intellij.codeInspection.dataFlow.*; +import com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction; +import com.intellij.codeInspection.dataFlow.rangeSet.LongRangeSet; import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel; +import com.intellij.openapi.util.Ref; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; import com.siyeh.InspectionGadgetsBundle; @@ -25,6 +29,7 @@ import com.siyeh.ig.psiutils.ClassUtils; import com.siyeh.ig.psiutils.ExpressionUtils; import com.siyeh.ig.psiutils.MethodUtils; import com.siyeh.ig.psiutils.TypeUtils; +import org.intellij.lang.annotations.Pattern; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -34,6 +39,7 @@ public class CastThatLosesPrecisionInspection extends BaseInspection { @SuppressWarnings({"PublicField"}) public boolean ignoreIntegerCharCasts = false; + @Pattern(VALID_ID_PATTERN) @Override @NotNull public String getID() { @@ -51,7 +57,10 @@ public class CastThatLosesPrecisionInspection extends BaseInspection { @NotNull public String buildErrorString(Object... infos) { final PsiType operandType = (PsiType)infos[0]; - return InspectionGadgetsBundle.message("cast.that.loses.precision.problem.descriptor", operandType.getPresentableText()); + boolean negativeOnly = (boolean)infos[1]; + return InspectionGadgetsBundle + .message(negativeOnly ? "cast.that.loses.precision.negative.problem.descriptor" : "cast.that.loses.precision.problem.descriptor", + operandType.getPresentableText()); } @Override @@ -106,7 +115,46 @@ public class CastThatLosesPrecisionInspection extends BaseInspection { if (castTypeElement == null) { return; } - registerError(castTypeElement, operandType); + LongRangeSet targetRange = LongRangeSet.fromType(castType); + LongRangeSet lostRange = LongRangeSet.all(); + if (targetRange != null && LongRangeSet.fromType(operandType) != null) { + LongRangeSet valueRange = getValueRange(operand); + lostRange = valueRange.subtract(targetRange); + if (lostRange.isEmpty()) return; + } + registerError(castTypeElement, operandType, lostRange.max() < 0); + } + + private LongRangeSet getValueRange(@NotNull PsiExpression operand) { + PsiElement parent = PsiTreeUtil.getParentOfType(operand, PsiMethod.class, PsiLambdaExpression.class, PsiClass.class); + if (parent instanceof PsiMethod) { + parent = ((PsiMethod)parent).getBody(); + } + else if (parent instanceof PsiLambdaExpression) { + parent = ((PsiLambdaExpression)parent).getBody(); + } + else { + parent = null; + } + if (parent == null) return LongRangeSet.all(); + Ref range = Ref.create(LongRangeSet.empty()); + StandardDataFlowRunner runner = new StandardDataFlowRunner(false, false); + RunnerResult runnerResult = runner.analyzeMethod(parent, new StandardInstructionVisitor() { + @Override + public DfaInstructionState[] visitMethodCall(MethodCallInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) { + if (instruction.getMethodType() == MethodCallInstruction.MethodType.CAST && instruction.getContext() == operand) { + LongRangeSet curRange = memState.getRange(memState.peek()); + if (curRange == null) { + range.set(LongRangeSet.all()); + } + else { + range.set(range.get().union(curRange)); + } + } + return super.visitMethodCall(instruction, runner, memState); + } + }); + return runnerResult == RunnerResult.OK ? range.get() : LongRangeSet.all(); } private boolean valueIsContainableInType(Number value, PsiType type) { @@ -137,10 +185,7 @@ public class CastThatLosesPrecisionInspection extends BaseInspection { doubleValue <= (double)Integer.MAX_VALUE; } else if (PsiType.LONG.equals(type)) { - return longValue >= Long.MIN_VALUE && - longValue <= Long.MAX_VALUE && - doubleValue >= (double)Long.MIN_VALUE && - doubleValue <= (double)Long.MAX_VALUE; + return doubleValue >= (double)Long.MIN_VALUE && doubleValue <= (double)Long.MAX_VALUE; } else if (PsiType.FLOAT.equals(type)) { return doubleValue == value.floatValue(); diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/cast_that_loses_precision/CastThatLosesPrecision.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/cast_that_loses_precision/CastThatLosesPrecision.java index e50643b38d8a..eb4e4e6d609f 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/cast_that_loses_precision/CastThatLosesPrecision.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/cast_that_loses_precision/CastThatLosesPrecision.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.siyeh.igtest.numeric.cast_that_loses_precision; public class CastThatLosesPrecision @@ -6,14 +21,14 @@ public class CastThatLosesPrecision { } - public void fooBar() + public void fooBar(long l, double d, float f) { byte b; int i; char ch; - long l = 0L; - double d = 0.0; - float f = 0.0f; + + + i = (int) f; System.out.println("i = " + i); @@ -38,11 +53,11 @@ public class CastThatLosesPrecision System.out.println("f = " + f); } - public void barFoo() { + public void barFoo(long l) { byte b; int i; char ch; - long l = 0L; + i = (int) 0.0f; System.out.println("i = " + i); @@ -78,4 +93,23 @@ public class CastThatLosesPrecision result = 31 * result + (int) (temp ^ temp >>> 32); return result; } + + void testNegativeOnly(long longNumberOfAgents) { + if (longNumberOfAgents > Integer.MAX_VALUE) { + throw new IllegalArgumentException("Too many agents: " + longNumberOfAgents); + } + int intNumberOfAgents = (int)longNumberOfAgents; + System.out.println(intNumberOfAgents); + } + + void testBoundsCheck(long longNumberOfAgents) { + if (longNumberOfAgents < 0) { + throw new IllegalArgumentException("Negative is not allowed"); + } + if (longNumberOfAgents > Integer.MAX_VALUE) { + throw new IllegalArgumentException("Too many agents: " + longNumberOfAgents); + } + int intNumberOfAgents = (int)longNumberOfAgents; + System.out.println(intNumberOfAgents); + } } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/cast_that_loses_precision/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/cast_that_loses_precision/expected.xml index 6e310f74e494..919b968da37f 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/cast_that_loses_precision/expected.xml +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/numeric/cast_that_loses_precision/expected.xml @@ -69,4 +69,11 @@ Numeric cast that loses precision Cast to <code>int</code> from 'double' may result in loss of precision #loc + + + CastThatLosesPrecision.java + 86 + Numeric cast that loses precision + Cast to <code>int</code> from 'long' may result in loss of precision for negative argument #loc + \ No newline at end of file From 0087518064b389ee9e017a0a41cc45fac0e3819a Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 11 Apr 2017 11:50:49 +0200 Subject: [PATCH 09/66] lock-free access to allSettings list remove duplicated method getSortedConfigurations (already existed in the API method `allSettings` should be used instead) --- .../com/intellij/execution/RunManagerEx.java | 8 +- .../RunConfigurationsComboBoxAction.java | 5 +- .../impl/ModuleRunConfigurationManager.java | 3 +- .../impl/ProjectRunConfigurationManager.java | 1 - .../RunConfigurationBeforeRunProvider.java | 6 +- .../intellij/execution/impl/RunManagerImpl.kt | 278 ++++++++++-------- .../src/com/intellij/mock/MockRunManager.kt | 4 - .../jetbrains/python/PyModuleListener.java | 8 +- 8 files changed, 171 insertions(+), 142 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/RunManagerEx.java b/platform/lang-impl/src/com/intellij/execution/RunManagerEx.java index cba123dcddf7..34a9f409641d 100644 --- a/platform/lang-impl/src/com/intellij/execution/RunManagerEx.java +++ b/platform/lang-impl/src/com/intellij/execution/RunManagerEx.java @@ -97,8 +97,14 @@ public abstract class RunManagerEx extends RunManager { public abstract Icon getConfigurationIcon(@NotNull RunnerAndConfigurationSettings settings, boolean withLiveIndicator); + /** + * @deprecated Use {@link #getAllSettings()} + */ @NotNull - public abstract Collection getSortedConfigurations(); + @Deprecated + public final Collection getSortedConfigurations() { + return getAllSettings(); + } public abstract void removeConfiguration(@Nullable RunnerAndConfigurationSettings settings); diff --git a/platform/lang-impl/src/com/intellij/execution/actions/RunConfigurationsComboBoxAction.java b/platform/lang-impl/src/com/intellij/execution/actions/RunConfigurationsComboBoxAction.java index cf287e5f7f54..0779bb86c6b4 100644 --- a/platform/lang-impl/src/com/intellij/execution/actions/RunConfigurationsComboBoxAction.java +++ b/platform/lang-impl/src/com/intellij/execution/actions/RunConfigurationsComboBoxAction.java @@ -34,6 +34,7 @@ import com.intellij.ui.IdeBorderFactory; import com.intellij.ui.SizedIcon; import com.intellij.ui.components.panels.NonOpaquePanel; import com.intellij.util.IconUtil; +import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.EmptyIcon; import com.intellij.util.ui.JBUI; import org.jetbrains.annotations.NotNull; @@ -41,7 +42,6 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -225,8 +225,7 @@ public class RunConfigurationsComboBoxAction extends ComboBoxAction implements D if (selectedConfiguration != null && selectedConfiguration.isTemporary()) { return selectedConfiguration; } - Iterator iterator = RunManager.getInstance(project).getTempConfigurationsList().iterator(); - return iterator.hasNext() ? iterator.next() : null; + return ContainerUtil.getFirstItem(RunManager.getInstance(project).getTempConfigurationsList()); } } diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ModuleRunConfigurationManager.java b/platform/lang-impl/src/com/intellij/execution/impl/ModuleRunConfigurationManager.java index 0b853cf4f5e5..f6b47beffc2c 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ModuleRunConfigurationManager.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ModuleRunConfigurationManager.java @@ -99,7 +99,7 @@ public final class ModuleRunConfigurationManager implements PersistentStateCompo @NotNull private Collection getModuleRunConfigurationSettings() { - return ContainerUtil.filter(myManager.getConfigurationSettings(), myModuleConfigCondition); + return ContainerUtil.filter(myManager.getAllSettings(), myModuleConfigCondition); } private boolean usesMyModule(RunConfiguration config) { @@ -152,6 +152,5 @@ public final class ModuleRunConfigurationManager implements PersistentStateCompo // IDEA-60004: configs may never be sorted before write, so call it manually after shared configs read myManager.setOrdered(false); - myManager.getSortedConfigurations(); } } diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ProjectRunConfigurationManager.java b/platform/lang-impl/src/com/intellij/execution/impl/ProjectRunConfigurationManager.java index 8237bdafedad..ef606a5dc6a2 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ProjectRunConfigurationManager.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ProjectRunConfigurationManager.java @@ -90,7 +90,6 @@ public class ProjectRunConfigurationManager implements PersistentStateComponent< // IDEA-60004: configs may never be sorted before write, so call it manually after shared configs read myManager.setOrdered(false); - myManager.getSortedConfigurations(); } static class RunConfigurationStateSplitter extends StateSplitterEx { diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationBeforeRunProvider.java b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationBeforeRunProvider.java index 440f12c2d6b6..d8112243eb87 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationBeforeRunProvider.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationBeforeRunProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -113,7 +113,7 @@ extends BeforeRunTaskProvider configurations = - RunManagerImpl.getInstanceImpl(runConfiguration.getProject()).getSortedConfigurations(); + RunManagerImpl.getInstanceImpl(runConfiguration.getProject()).getAllSettings(); if (configurations.isEmpty() || (configurations.size() == 1 && configurations.iterator().next().getConfiguration() == runConfiguration)) { return null; @@ -144,7 +144,7 @@ extends BeforeRunTaskProvider configurations = new ArrayList<>(RunManagerImpl.getInstanceImpl(project).getSortedConfigurations()); + List configurations = new ArrayList<>(RunManagerImpl.getInstanceImpl(project).getAllSettings()); String executorId = DefaultRunExecutor.getRunExecutorInstance().getId(); for (Iterator iterator = configurations.iterator(); iterator.hasNext();) { RunnerAndConfigurationSettings settings = iterator.next(); diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt index 3e1dc6729386..058e9525d75d 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt @@ -41,7 +41,6 @@ import com.intellij.openapi.updateSettings.impl.pluginsAdvertisement.UnknownFeat import com.intellij.openapi.util.InvalidDataException import com.intellij.openapi.util.JDOMExternalizableStringList import com.intellij.openapi.util.Key -import com.intellij.openapi.util.Pair import com.intellij.openapi.util.registry.Registry import com.intellij.util.EventDispatcher import com.intellij.util.IconUtil @@ -114,7 +113,14 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent @Suppress("DEPRECATION") private val myOrder = JDOMExternalizableStringList() private val recentlyUsedTemporaries = ArrayList() - private var myOrdered = true + + var isOrdered = true + set(value) { + lock.write { + field = value + immutableSortedSettingsList = null + } + } private val myDispatcher = EventDispatcher.create(RunManagerListener::class.java)!! @@ -212,7 +218,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent */ override fun getConfigurationsList(type: ConfigurationType): List { var result: MutableList? = null - for (settings in sortedConfigurations) { + for (settings in allSettings) { val configuration = settings.configuration if (type.id == configuration.type.id) { if (result == null) { @@ -225,16 +231,11 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent } override val allConfigurationsList: List - get() = sortedConfigurations.mapSmart { it.configuration } + get() = allSettings.mapSmart { it.configuration } - override val allSettings: List - get() = sortedConfigurations.toList() + fun getSettings(configuration: RunConfiguration) = allSettings.firstOrNull { it.configuration === configuration } as? RunnerAndConfigurationSettingsImpl - fun getSettings(configuration: RunConfiguration) = sortedConfigurations.firstOrNull { it.configuration === configuration } as? RunnerAndConfigurationSettingsImpl - - override fun getConfigurationSettingsList(type: ConfigurationType) = lock.read { sortedConfigurations.filterSmart { it.type?.id == type.id } } - - fun getConfigurationSettings() = idToSettings.values.toTypedArray() + override fun getConfigurationSettingsList(type: ConfigurationType) = allSettings.filterSmart { it.type?.id == type.id } override fun getStructure(type: ConfigurationType): Map> { val result = LinkedHashMap>() @@ -275,6 +276,8 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent var existingSettings: RunnerAndConfigurationSettings? = null var existingId: String? = null lock.write { + immutableSortedSettingsList = null + existingId = findExistingConfigurationId(settings) existingId?.let { existingSettings = idToSettings.remove(it) @@ -322,25 +325,25 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent fun checkRecentsLimit() { trimUsagesListToLimit() - val removed = SmartList() + var removed: MutableList? = null lock.write { - while (tempConfigurationsList.size > config.recentsLimit) { + while (idToSettings.values.count { it.isTemporary } > config.recentsLimit) { val it = idToSettings.values.iterator() while (it.hasNext()) { val settings = it.next() if (settings.isTemporary && !recentlyUsedTemporaries.contains(settings.configuration)) { - removed.add(settings) + if (removed == null) { + immutableSortedSettingsList = null + removed = SmartList() + } + removed!!.add(settings) it.remove() break } } } } - fireRunConfigurationsRemoved(removed) - } - - fun setOrdered(ordered: Boolean) { - myOrdered = ordered + removed?.let { fireRunConfigurationsRemoved(it) } } fun saveOrder() { @@ -355,12 +358,13 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent myOrder.clear() sorted.mapTo(myOrder) { it.uniqueID} + immutableSortedSettingsList = null } fun setOrder(comparator: Comparator?) { doSaveOrder(comparator) // force recache of configurations list - setOrdered(false) + isOrdered = false } override var selectedConfiguration: RunnerAndConfigurationSettings? @@ -377,75 +381,95 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent private fun setSelectedConfigurationId(id: String?) { selectedConfigurationId = id - if (selectedConfigurationId != null) { + if (id != null) { loadedSelectedConfigurationUniqueName = null } } - override fun getSortedConfigurations(): MutableCollection { - if (myOrdered) { - return idToSettings.values - } + private data class OrderItem(val id: String, val settings: RunnerAndConfigurationSettings) - val order = ArrayList>(idToSettings.size) - val folderNames = SmartList() - for (each in idToSettings.values) { - order.add(Pair.create(each.uniqueID, each)) - val folderName = each.folderName - if (folderName != null && !folderNames.contains(folderName)) { - folderNames.add(folderName) + @Volatile + private var immutableSortedSettingsList: List? = null + + override val allSettings: List + get() { + immutableSortedSettingsList?.let { + return it + } + + lock.write { + immutableSortedSettingsList?.let { + return it + } + + if (isOrdered) { + val result = Collections.unmodifiableList(idToSettings.values.toList()) + immutableSortedSettingsList = result + return result + } + + val order = ArrayList(idToSettings.size) + val folderNames = SmartList() + for (each in idToSettings.values) { + order.add(OrderItem(each.uniqueID, each)) + val folderName = each.folderName + if (folderName != null && !folderNames.contains(folderName)) { + folderNames.add(folderName) + } + } + folderNames.add(null) + idToSettings.clear() + + if (myOrder.isEmpty()) { + // IDEA-63663 Sort run configurations alphabetically if clean checkout + order.sortWith(Comparator { o1, o2 -> + val temporary1 = o1.settings.isTemporary + val temporary2 = o2.settings.isTemporary + when { + temporary1 == temporary2 -> o1.id.compareTo(o2.id) + temporary1 -> 1 + else -> -1 + } + }) + } + else { + order.sortWith(Comparator { o1, o2 -> + val i1 = folderNames.indexOf(o1.settings.folderName) + val i2 = folderNames.indexOf(o2.settings.folderName) + if (i1 != i2) { + return@Comparator i1 - i2 + } + + val temporary1 = o1.settings.isTemporary + val temporary2 = o2.settings.isTemporary + when { + temporary1 == temporary2 -> { + val index1 = myOrder.indexOf(o1.id) + val index2 = myOrder.indexOf(o2.id) + if (index1 == -1 && index2 == -1) { + o1.settings.name.compareTo(o2.settings.name) + } + else { + index1 - index2 + } + } + temporary1 -> 1 + else -> -1 + } + }) + } + + for (each in order) { + val setting = each.settings + idToSettings.put(setting.uniqueID, setting) + } + + val result = Collections.unmodifiableList(idToSettings.values.toList()) + isOrdered = true + immutableSortedSettingsList = result + return result } } - folderNames.add(null) - idToSettings.clear() - - if (myOrder.isEmpty()) { - // IDEA-63663 Sort run configurations alphabetically if clean checkout - order.sortWith(Comparator { o1, o2 -> - val temporary1 = o1.getSecond().isTemporary - val temporary2 = o2.getSecond().isTemporary - when { - temporary1 == temporary2 -> o1.first.compareTo(o2.first) - temporary1 -> 1 - else -> -1 - } - }) - } - else { - order.sortWith(Comparator { o1, o2 -> - val i1 = folderNames.indexOf(o1.getSecond().folderName) - val i2 = folderNames.indexOf(o2.getSecond().folderName) - if (i1 != i2) { - return@Comparator i1 - i2 - } - - val temporary1 = o1.getSecond().isTemporary - val temporary2 = o2.getSecond().isTemporary - when { - temporary1 == temporary2 -> { - val index1 = myOrder.indexOf(o1.first) - val index2 = myOrder.indexOf(o2.first) - if (index1 == -1 && index2 == -1) { - o1.second.name.compareTo(o2.second.name) - } - else { - index1 - index2 - } - } - temporary1 -> 1 - else -> -1 - } - }) - } - - for (each in order) { - val setting = each.second - idToSettings.put(setting.uniqueID, setting) - } - - myOrdered = true - return idToSettings.values - } @Suppress("DEPRECATION") override fun getState(): Element { @@ -502,7 +526,11 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent } fun writeContext(element: Element) { - writeConfigurations(element, lock.read { idToSettings.values.filterSmart { it.isTemporary } }) + for (setting in allSettings) { + if (setting.isTemporary) { + element.addContent((setting as RunnerAndConfigurationSettingsImpl).writeScheme()) + } + } selectedConfiguration?.let { element.setAttribute(SELECTED_ATTR, it.uniqueID) @@ -589,7 +617,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent } } } - myOrdered = false + isOrdered = false loadedSelectedConfigurationUniqueName = parentNode.getAttributeValue(SELECTED_ATTR) setSelectedConfigurationId(loadedSelectedConfigurationUniqueName) @@ -648,32 +676,40 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent } private fun clear(allConfigurations: Boolean) { - val configurations: MutableList - if (allConfigurations) { - this.idToSettings.clear() - selectedConfigurationId = null - configurations = ArrayList(this.idToSettings.values) - } - else { - configurations = SmartList() - val iterator = this.idToSettings.values.iterator() - while (iterator.hasNext()) { - val configuration = iterator.next() - if (configuration.isTemporary || !configuration.isShared) { - iterator.remove() + val configurations = lock.write { + immutableSortedSettingsList = null - configurations.add(configuration) - } - } + val configurations = if (allConfigurations) { + val configurations = idToSettings.values.toList() - if (selectedConfigurationId != null && this.idToSettings.containsKey(selectedConfigurationId!!)) { + idToSettings.clear() selectedConfigurationId = null + + configurations } + else { + val configurations = SmartList() + val iterator = idToSettings.values.iterator() + while (iterator.hasNext()) { + val configuration = iterator.next() + if (configuration.isTemporary || !configuration.isShared) { + iterator.remove() + + configurations.add(configuration) + } + } + + if (selectedConfigurationId != null && this.idToSettings.containsKey(selectedConfigurationId!!)) { + selectedConfigurationId = null + } + + configurations + } + + templateIdToConfiguration.clear() + configurations } - lock.write { - templateIdToConfiguration.clear() - } loadedSelectedConfigurationUniqueName = null iconCache.clear() recentlyUsedTemporaries.clear() @@ -763,25 +799,20 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent } fun getSharedConfigurations(): List { - lock.read { - var result: MutableList? = null - for (configuration in idToSettings.values) { - if (configuration.isShared) { - if (result == null) { - result = ArrayList() - } - result.add(configuration) + var result: MutableList? = null + for (configuration in allSettings) { + if (configuration.isShared) { + if (result == null) { + result = ArrayList() } + result.add(configuration) } - return result ?: emptyList() } + return result ?: emptyList() } - internal val configurationSettings: Collection - get() = idToSettings.values - override val tempConfigurationsList: List - get() = idToSettings.values.filter { it.isTemporary } + get() = allSettings.filterSmart { it.isTemporary } override fun makeStable(settings: RunnerAndConfigurationSettings) { settings.isTemporary = false @@ -792,7 +823,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent private fun doMakeStable(settings: RunnerAndConfigurationSettings) { recentlyUsedTemporaries.remove(settings.configuration) if (!myOrder.isEmpty()) { - setOrdered(false) + isOrdered = false } } @@ -807,7 +838,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent val tasks = SmartList() val checkedTemplates = SmartList() lock.read { - for (settings in idToSettings.values.toTypedArray()) { + for (settings in allSettings) { val configuration = settings.configuration for (task in getBeforeRunTasks(configuration)) { if (task.isEnabled && task.providerId === taskProviderId) { @@ -858,11 +889,11 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent if (name == null) { return null } - return idToSettings.values.firstOrNull { it.name == name } + return allSettings.firstOrNull { it.name == name } } fun findConfigurationByTypeAndName(typeId: String, name: String): RunnerAndConfigurationSettings? { - return sortedConfigurations.firstOrNull { + return allSettings.firstOrNull { val t = it.type t != null && typeId == t.id && name == it.name } @@ -998,7 +1029,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent // we must update all existing configuration tasks to ensure that effective tasks (own + template) are the same as before template configuration change // see testTemplates test lock.read { - for (otherSettings in idToSettings.values) { + for (otherSettings in allSettings) { val otherConfiguration = otherSettings.configuration if (otherConfiguration !is WrappingRunConfiguration<*> && otherConfiguration.factory === templateConfiguration.factory) { otherConfiguration.beforeRunTasks = getEffectiveBeforeRunTasks(otherConfiguration, ownIsOnlyEnabled = false, isDisableTemplateTasks = true, newTemplateTasks = tasks) @@ -1028,6 +1059,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent val settings = entry.value if (!settings.isTemplate && settings.isShared && !existing.contains(settings.uniqueID)) { if (removed == null) { + immutableSortedSettingsList = null removed = SmartList() } removed!!.add(settings) @@ -1080,6 +1112,8 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent val changedSettings = SmartList() lock.write { + immutableSortedSettingsList = null + val iterator = idToSettings.values.iterator() for (otherSettings in iterator) { if (otherSettings === settings) { diff --git a/platform/testFramework/src/com/intellij/mock/MockRunManager.kt b/platform/testFramework/src/com/intellij/mock/MockRunManager.kt index c4331f987314..12e43bfdadce 100644 --- a/platform/testFramework/src/com/intellij/mock/MockRunManager.kt +++ b/platform/testFramework/src/com/intellij/mock/MockRunManager.kt @@ -107,10 +107,6 @@ class MockRunManager : RunManagerEx() { return null } - override fun getSortedConfigurations(): Collection { - return emptyList() - } - override fun removeConfiguration(settings: RunnerAndConfigurationSettings?) {} override fun addRunManagerListener(listener: RunManagerListener) {} diff --git a/python/ide/src/com/jetbrains/python/PyModuleListener.java b/python/ide/src/com/jetbrains/python/PyModuleListener.java index 2646174ac178..16d76ae65adb 100644 --- a/python/ide/src/com/jetbrains/python/PyModuleListener.java +++ b/python/ide/src/com/jetbrains/python/PyModuleListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,9 +25,6 @@ import com.intellij.util.messages.MessageBus; import com.jetbrains.python.run.AbstractPythonRunConfiguration; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.Collection; - /** * @author yole */ @@ -37,8 +34,7 @@ public class PyModuleListener { @Override public void beforeModuleRemoved(@NotNull Project project, @NotNull Module module) { final RunManagerEx runManager = RunManagerEx.getInstanceEx(project); - final Collection configurations = new ArrayList<>(runManager.getSortedConfigurations()); - for (RunnerAndConfigurationSettings configuration : configurations) { + for (RunnerAndConfigurationSettings configuration : runManager.getAllSettings()) { if (configuration.getConfiguration() instanceof AbstractPythonRunConfiguration) { final Module configModule = ((AbstractPythonRunConfiguration)configuration.getConfiguration()).getModule(); if (configModule == module) { From e3dfd37504dfb56458fd3430ea9ceebfa89a6a8c Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 11 Apr 2017 12:42:08 +0200 Subject: [PATCH 10/66] cleanup (inline method, use assertJ extracting) --- .../execution/impl/RunConfigurable.java | 2 +- .../intellij/execution/impl/RunManagerImpl.kt | 39 +++++++++---------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java index f46d570fc6db..0728028149d5 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.java @@ -704,7 +704,7 @@ class RunConfigurable extends BaseConfigurable { each.first.apply(); } - manager.saveOrder(); + manager.setOrder(null); } finally { getRunManager().fireEndUpdate(); diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt index 058e9525d75d..4ac12fbbf438 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt @@ -117,8 +117,10 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent var isOrdered = true set(value) { lock.write { - field = value - immutableSortedSettingsList = null + if (field != value) { + field = value + immutableSortedSettingsList = null + } } } @@ -346,25 +348,17 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent removed?.let { fireRunConfigurationsRemoved(it) } } - fun saveOrder() { - setOrder(null) - } - - private fun doSaveOrder(comparator: Comparator?) { - val sorted = idToSettings.values.filter { it.type !is UnknownConfigurationType } - if (comparator != null) { - sorted.sortedWith(comparator) - } - - myOrder.clear() - sorted.mapTo(myOrder) { it.uniqueID} - immutableSortedSettingsList = null - } - fun setOrder(comparator: Comparator?) { - doSaveOrder(comparator) - // force recache of configurations list - isOrdered = false + lock.write { + val sorted = idToSettings.values.filter { it.type !is UnknownConfigurationType } + if (comparator != null) { + sorted.sortedWith(comparator) + } + myOrder.clear() + sorted.mapTo(myOrder) { it.uniqueID } + // force recache of configurations list + isOrdered = false + } } override var selectedConfiguration: RunnerAndConfigurationSettings? @@ -402,6 +396,11 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent return it } + if (idToSettings.isEmpty()) { + immutableSortedSettingsList = emptyList() + return immutableSortedSettingsList!! + } + if (isOrdered) { val result = Collections.unmodifiableList(idToSettings.values.toList()) immutableSortedSettingsList = result From 83931bdb61a69efba179e7718edbe773c1adcbc2 Mon Sep 17 00:00:00 2001 From: Dennis Ushakov Date: Mon, 10 Apr 2017 12:20:38 +0200 Subject: [PATCH 11/66] update braces instead of cancelling all requests (IDEA-104141) --- .../highlighting/BraceHighlighter.java | 32 +++++++------------ .../BraceHighlightingHandler.java | 1 + 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlighter.java b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlighter.java index 746054ae90bf..4c7ff762cdb7 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlighter.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlighter.java @@ -23,11 +23,10 @@ import com.intellij.openapi.editor.EditorFactory; import com.intellij.openapi.editor.SelectionModel; import com.intellij.openapi.editor.event.*; import com.intellij.openapi.editor.ex.DocumentEx; -import com.intellij.openapi.editor.ex.EditorEventMulticasterEx; -import com.intellij.openapi.editor.ex.FocusChangeListener; -import com.intellij.openapi.fileEditor.FileEditorManager; +import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorManagerEvent; import com.intellij.openapi.fileEditor.FileEditorManagerListener; +import com.intellij.openapi.fileEditor.TextEditor; import com.intellij.openapi.project.Project; import com.intellij.openapi.startup.StartupActivity; import com.intellij.openapi.util.TextRange; @@ -96,27 +95,20 @@ public class BraceHighlighter implements StartupActivity { }; eventMulticaster.addDocumentListener(documentListener, project); - final FocusChangeListener myFocusChangeListener = new FocusChangeListener() { - @Override - public void focusLost(Editor editor) { - clearBraces(editor); - } - - @Override - public void focusGained(Editor editor) { - updateBraces(editor, myAlarm); - } - }; - ((EditorEventMulticasterEx)eventMulticaster).addFocusChangeListner(myFocusChangeListener, project); - - final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); - - fileEditorManager.addFileEditorManagerListener(new FileEditorManagerListener() { + project.getMessageBus().connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() { @Override public void selectionChanged(@NotNull FileEditorManagerEvent e) { myAlarm.cancelAllRequests(); + FileEditor oldEditor = e.getOldEditor(); + if (oldEditor instanceof TextEditor) { + clearBraces(((TextEditor)oldEditor).getEditor()); + } + FileEditor newEditor = e.getNewEditor(); + if (newEditor instanceof TextEditor) { + updateBraces(((TextEditor)newEditor).getEditor(), myAlarm); + } } - }, project); + }); } static void updateBraces(@NotNull final Editor editor, @NotNull final Alarm alarm) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java index fda551d2546b..85850d103124 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/highlighting/BraceHighlightingHandler.java @@ -567,6 +567,7 @@ public class BraceHighlightingHandler { hint.hide(); myEditor.putUserData(HINT_IN_EDITOR_KEY, null); } + removeLineMarkers(); } private void lineMarkFragment(int startLine, int endLine, @NotNull Color color) { From 6568d00315afbd126d3969a4e8fc075832b35d50 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 11 Apr 2017 14:15:45 +0200 Subject: [PATCH 12/66] add debug logging for flaky NewProjectWizardTest --- .../src/com/intellij/ide/projectWizard/ProjectTypeStep.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java b/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java index 27cb4d410370..d6d35f6ee017 100644 --- a/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java +++ b/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java @@ -45,6 +45,7 @@ import com.intellij.platform.ProjectTemplate; import com.intellij.platform.ProjectTemplateEP; import com.intellij.platform.ProjectTemplatesFactory; import com.intellij.platform.templates.*; +import com.intellij.psi.impl.DebugUtil; import com.intellij.ui.CollectionListModel; import com.intellij.ui.IdeBorderFactory; import com.intellij.ui.ListSpeedSearch; @@ -233,6 +234,7 @@ public class ProjectTypeStep extends ModuleWizardStep implements SettingsStep, D } final String groupId = PropertiesComponent.getInstance().getValue(PROJECT_WIZARD_GROUP); + LOG.debug("saved groupId=" + groupId); if (groupId != null) { TemplatesGroup group = ContainerUtil.find(groups, group1 -> groupId.equals(group1.getId())); if (group != null) { @@ -375,6 +377,9 @@ public class ProjectTypeStep extends ModuleWizardStep implements SettingsStep, D if (group == null || group == myLastSelectedGroup) return; myLastSelectedGroup = group; PropertiesComponent.getInstance().setValue(PROJECT_WIZARD_GROUP, group.getId() ); + if (LOG.isDebugEnabled()) { + LOG.debug("projectTypeChanged: " + group.getId() + " " + DebugUtil.currentStackTrace()); + } ModuleBuilder groupModuleBuilder = group.getModuleBuilder(); mySettingsStep = null; From e00d80c50d364c939f140fd1bb4497313b1d24dd Mon Sep 17 00:00:00 2001 From: Anton Tarasov Date: Tue, 11 Apr 2017 15:21:51 +0300 Subject: [PATCH 13/66] IDEA-152169 [followup] --- .../com/intellij/ui/popup/PopupComponent.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ui/popup/PopupComponent.java b/platform/platform-impl/src/com/intellij/ui/popup/PopupComponent.java index 64222a6adbf1..9c24b75b01b2 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/PopupComponent.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/PopupComponent.java @@ -132,13 +132,6 @@ public interface PopupComponent { myDialog.setBackground(UIUtil.getPanelBackground()); myDialog.pack(); myDialog.setLocation(x, y); - myDialog.addWindowListener(new WindowAdapter() { - @Override - public void windowClosed(WindowEvent e) { - super.windowClosed(e); - //A11YFix.invokeFocusGained(myDialog); - } - }); } public Window getWindow() { @@ -155,13 +148,20 @@ public interface PopupComponent { public void show() { - UIUtil.suppressFocusStealing(getWindow()); + UIUtil.suppressFocusStealing(getWindow()); if (!myRequestFocus) { myDialog.setFocusableWindowState(false); } AwtPopupWrapper.fixFlickering(myDialog, false); + myDialog.addWindowListener(new WindowAdapter() { + @Override + public void windowClosed(WindowEvent e) { + //A11YFix.invokeFocusGained(myDialog); + myDialog.removeWindowListener(this); + } + }); myDialog.setVisible(true); AwtPopupWrapper.fixFlickering(myDialog, true); From cb3a5654e68b3516cc07a1bde0381dd34c526ed6 Mon Sep 17 00:00:00 2001 From: Kirill Kirichenko Date: Tue, 11 Apr 2017 15:43:48 +0300 Subject: [PATCH 14/66] IDEA-168273 EditorTextField focus reworked --- .../ide/ui/laf/darcula/DarculaUIUtil.java | 81 +++++++++++++++++++ .../src/com/intellij/ui/EditorTextField.java | 4 +- .../src/com/intellij/util/ui/MacUIUtil.java | 68 ---------------- 3 files changed, 83 insertions(+), 70 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaUIUtil.java b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaUIUtil.java index d36ba7734adb..0eee7358206e 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaUIUtil.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/darcula/DarculaUIUtil.java @@ -18,17 +18,26 @@ package com.intellij.ide.ui.laf.darcula; import com.intellij.ide.IdeEventQueue; import com.intellij.ide.ui.laf.IntelliJLaf; import com.intellij.ui.ColorUtil; +import com.intellij.ui.Gray; import com.intellij.ui.JBColor; +import com.intellij.util.ui.JBInsets; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.MacUIUtil; import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.NotNull; +import javax.swing.*; +import javax.swing.border.Border; import javax.swing.text.JTextComponent; import javax.swing.text.Position; import java.awt.*; import java.awt.event.KeyEvent; import java.awt.geom.Path2D; +import java.awt.geom.Rectangle2D; +import java.util.Arrays; +import java.util.List; +import static com.intellij.util.ui.MacUIUtil.MAC_FILL_BORDER; import static javax.swing.SwingConstants.EAST; import static javax.swing.SwingConstants.WEST; @@ -184,4 +193,76 @@ public class DarculaUIUtil { } return -1; } + + public static class EditorTextFieldBorder implements Border { + private final JComponent myEnabledComponent; + + public EditorTextFieldBorder(JComponent enabledComponent) { + myEnabledComponent = enabledComponent; + } + + @Override + public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { + Graphics2D g2 = (Graphics2D)g.create(); + try { + if (c.isOpaque() || (c instanceof JComponent && ((JComponent)c).getClientProperty(MAC_FILL_BORDER) == Boolean.TRUE)) { + g2.setColor(UIUtil.getPanelBackground()); + g2.fillRect(x, y, width, height); + } + + Rectangle2D rect = new Rectangle2D.Double(x + JBUI.scale(3), y + JBUI.scale(3), width - JBUI.scale(6), height - JBUI.scale(6)); + g2.setColor(c.getBackground()); + g2.fill(rect); + + if (!myEnabledComponent.isEnabled()) { + ((Graphics2D)g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f)); + } + + double bw = UIUtil.isRetina(g2) ? 0.5 : 1.0; + Path2D outline = new Path2D.Double(Path2D.WIND_EVEN_ODD); + outline.append(rect, false); + outline.append(new Rectangle2D.Double(rect.getX() + bw, + rect.getY() + bw, + rect.getWidth() - 2*bw, + rect.getHeight() - 2*bw), false); + g2.setColor(Gray.xBC); + g2.fill(outline); + + if (myEnabledComponent.isEnabled() && myEnabledComponent.isVisible() && hasFocus(myEnabledComponent)) { + g2.translate(x, y); + paintFocusBorder(g2, width, height, 0, true); + } + } finally { + g2.dispose(); + } + } + + @Override + public Insets getBorderInsets(Component c) { + return new JBInsets(6, 7, 6, 7); + } + + @Override + public boolean isBorderOpaque() { + return true; + } + } + + private static boolean hasFocus(@NotNull Component component) { + if (component.hasFocus()) return true; + if (!(component instanceof JComponent)) return false; + + List children; + synchronized (component.getTreeLock()) { + children = Arrays.asList(((Container)component).getComponents()); + } + + for (Component c : children) { + if (hasFocus(c)) { + return true; + } + } + + return false; + } } diff --git a/platform/platform-impl/src/com/intellij/ui/EditorTextField.java b/platform/platform-impl/src/com/intellij/ui/EditorTextField.java index fcce5aa99be6..b655d0124639 100644 --- a/platform/platform-impl/src/com/intellij/ui/EditorTextField.java +++ b/platform/platform-impl/src/com/intellij/ui/EditorTextField.java @@ -17,6 +17,7 @@ package com.intellij.ui; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; import com.intellij.ide.ui.UISettings; +import com.intellij.ide.ui.laf.darcula.DarculaUIUtil; import com.intellij.ide.ui.laf.darcula.ui.DarculaEditorTextFieldBorder; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.CommonDataKeys; @@ -52,7 +53,6 @@ import com.intellij.ui.components.panels.NonOpaquePanel; import com.intellij.util.IJSwingUtilities; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.JBInsets; -import com.intellij.util.ui.MacUIUtil; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -545,7 +545,7 @@ public class EditorTextField extends NonOpaquePanel implements DocumentListener, protected void setupBorder(@NotNull EditorEx editor) { if (UIUtil.isUnderAquaLookAndFeel() || UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF()) { - editor.setBorder(UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF() ? new DarculaEditorTextFieldBorder() : new MacUIUtil.EditorTextFieldBorder(this)); + editor.setBorder(UIUtil.isUnderDefaultMacTheme() ? new DarculaUIUtil.EditorTextFieldBorder(this) : new DarculaEditorTextFieldBorder()); editor.addFocusListener(new FocusChangeListener() { @Override public void focusGained(Editor editor) { diff --git a/platform/util/src/com/intellij/util/ui/MacUIUtil.java b/platform/util/src/com/intellij/util/ui/MacUIUtil.java index 3329d0531ba8..8f8ef7f23244 100644 --- a/platform/util/src/com/intellij/util/ui/MacUIUtil.java +++ b/platform/util/src/com/intellij/util/ui/MacUIUtil.java @@ -24,7 +24,6 @@ import com.intellij.util.ui.tree.WideSelectionTreeUI; import org.jetbrains.annotations.NotNull; import javax.swing.*; -import javax.swing.border.Border; import javax.swing.tree.DefaultTreeCellRenderer; import java.awt.*; import java.awt.geom.GeneralPath; @@ -114,69 +113,6 @@ public class MacUIUtil { g.fillRect(0, h1, width, height); } - public static class EditorTextFieldBorder implements Border { - private JComponent myEnabledComponent; - - public EditorTextFieldBorder(final JComponent enabledComponent) { - myEnabledComponent = enabledComponent; - } - - @Override - public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) { - final int x1 = x + 3; - final int y1 = y + 3; - final int width1 = width - 8; - final int height1 = height - 6; - - if (c.isOpaque() || (c instanceof JComponent && ((JComponent)c).getClientProperty(MAC_FILL_BORDER) == Boolean.TRUE)) { - g.setColor(UIUtil.getPanelBackground()); - g.fillRect(x, y, width, height); - } - - g.setColor(c.getBackground()); - g.fillRect(x1, y1, width1, height1); - - if (!myEnabledComponent.isEnabled()) { - ((Graphics2D)g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f)); - } - - //noinspection UseJBColor - g.setColor(new Color(100, 100, 100, 200)); - g.drawRect(x1, y1, width1 - 1, height1 - 1); - - g.setColor(Gray._225); - g.drawRect(x1 + 1, y1 + 1, width1 - 3, height1 - 3); - - if (myEnabledComponent.isEnabled() && myEnabledComponent.isVisible() && hasFocus(myEnabledComponent)) { - paintTextFieldFocusRing((Graphics2D) g, new Rectangle(x1, y1, width1, height1)); - } - } - - private static boolean hasFocus(@NotNull final Component toCheck) { - if (toCheck.hasFocus()) return true; - if (toCheck instanceof JComponent) { - final JComponent c = (JComponent)toCheck; - for (int i = 0; i < c.getComponentCount(); i++) { - final boolean b = hasFocus(c.getComponent(i)); - if (b) return true; - } - } - - return false; - } - - - @Override - public Insets getBorderInsets(Component c) { - return new JBInsets(6, 7, 6, 7); - } - - @Override - public boolean isBorderOpaque() { - return true; - } - } - public static Color getFocusRingColor() { final Object o = UIManager.get("Focus.color"); if (o instanceof Color) { @@ -187,10 +123,6 @@ public class MacUIUtil { return new Color(64, 113, 167); } - public static void paintTextFieldFocusRing(@NotNull final Graphics2D g2d, @NotNull final Rectangle bounds) { - paintFocusRing(g2d, getFocusRingColor(), bounds); - } - public static void paintComboboxFocusRing(@NotNull final Graphics2D g2d, @NotNull final Rectangle bounds) { final Color color = getFocusRingColor(); final Color[] colors = new Color[]{ From 7f59254e4d7c2fb2e189901b4459e13ab90e7777 Mon Sep 17 00:00:00 2001 From: nik Date: Tue, 11 Apr 2017 16:21:41 +0300 Subject: [PATCH 15/66] build scripts: don't perform unnecessary initialization of KotlinBuilder class This may lead to problems e.g. with logging: static fields of Logger type may be initialized before we configure debug settings for loggers via Log4jFileLoggerFactory, and therefore 'debug' logging level won't be set for them. --- build/scripts/utils.gant | 7 ++----- .../intellij/build/impl/CompilationTasksImpl.groovy | 5 +---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/build/scripts/utils.gant b/build/scripts/utils.gant index c3d7002bf503..031e6b7e54d0 100644 --- a/build/scripts/utils.gant +++ b/build/scripts/utils.gant @@ -150,11 +150,8 @@ private void setupKotlin() { } private boolean ensureKotlinCompilerAddedToClassPath() { - try { - Class.forName("org.jetbrains.kotlin.jps.build.KotlinBuilder") - return true - } - catch (ClassNotFoundException ignored) { + if (getClass().getResource("/org/jetbrains/kotlin/jps/build/KotlinBuilder.class") != null) { + return } def kotlinPluginLibPath = "$home/build/dependencies/build/Kotlin/lib" diff --git a/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/CompilationTasksImpl.groovy b/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/CompilationTasksImpl.groovy index 41064c16d540..5deb4016eedd 100644 --- a/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/CompilationTasksImpl.groovy +++ b/platform/build-scripts/groovy/org/jetbrains/intellij/build/impl/CompilationTasksImpl.groovy @@ -77,12 +77,9 @@ class CompilationTasksImpl extends CompilationTasks { } private void ensureKotlinCompilerAddedToClassPath() { - try { - Class.forName("org.jetbrains.kotlin.jps.build.KotlinBuilder") + if (getClass().getResource("/org/jetbrains/kotlin/jps/build/KotlinBuilder.class") != null) { return } - catch (ClassNotFoundException ignored) { - } def kotlinPluginLibPath = "$context.paths.communityHome/build/dependencies/build/Kotlin/lib" if (new File(kotlinPluginLibPath).exists()) { From 1989b89e65ada40190d7cacea01dedf2b03692ee Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Tue, 11 Apr 2017 16:15:00 +0300 Subject: [PATCH 16/66] DBE-4211 Table editor row number misplaced when horizontal scroll bar is present and scrolled to the bottom fix only for a table header --- .../src/com/intellij/ui/components/JBScrollPane.java | 4 ++-- .../src/com/intellij/ui/components/JBViewport.java | 4 ++-- .../src/com/intellij/ui/components/ScrollSettings.java | 5 ++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java b/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java index eb432a1b1642..c6e1f548f0b7 100644 --- a/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java +++ b/platform/platform-api/src/com/intellij/ui/components/JBScrollPane.java @@ -561,7 +561,7 @@ public class JBScrollPane extends JScrollPane { if (hsbOpaque) { Component corner = hsbOnTop ? (vsbOnLeft ? upperRight : upperLeft) : (vsbOnLeft ? lowerRight : lowerLeft); fillLowerCorner = corner == null && UIManager.getBoolean("ScrollPane.fillLowerCorner"); - if (!fillLowerCorner && ScrollSettings.isHeaderOverCorner()) { + if (!fillLowerCorner && ScrollSettings.isHeaderOverCorner(rowHead)) { if (hsbOnTop) rowHeadBounds.y -= hsbBounds.height; rowHeadBounds.height += hsbBounds.height; } @@ -577,7 +577,7 @@ public class JBScrollPane extends JScrollPane { if (vsbOpaque) { Component corner = vsbOnLeft ? (hsbOnTop ? lowerLeft : upperLeft) : (hsbOnTop ? lowerRight : upperRight); fillUpperCorner = corner == null && UIManager.getBoolean("ScrollPane.fillUpperCorner"); - if (!fillUpperCorner && ScrollSettings.isHeaderOverCorner()) { + if (!fillUpperCorner && ScrollSettings.isHeaderOverCorner(colHead)) { if (vsbOnLeft) colHeadBounds.x -= vsbBounds.width; colHeadBounds.width += vsbBounds.width; } diff --git a/platform/platform-api/src/com/intellij/ui/components/JBViewport.java b/platform/platform-api/src/com/intellij/ui/components/JBViewport.java index 8655f078dde1..c6139a3f0485 100644 --- a/platform/platform-api/src/com/intellij/ui/components/JBViewport.java +++ b/platform/platform-api/src/com/intellij/ui/components/JBViewport.java @@ -471,7 +471,7 @@ public class JBViewport extends JViewport implements ZoomableViewport { if (vsb != null && vsb.isVisible()) { boolean opaque = vsb.isOpaque(); if (viewport == pane.getColumnHeader() - ? (!opaque || ScrollSettings.isHeaderOverCorner()) + ? (!opaque || ScrollSettings.isHeaderOverCorner(viewport)) : (!opaque && viewport == pane.getViewport())) { Alignment va = UIUtil.getClientProperty(vsb, Alignment.class); if (va == Alignment.LEFT) { @@ -487,7 +487,7 @@ public class JBViewport extends JViewport implements ZoomableViewport { if (hsb != null && hsb.isVisible()) { boolean opaque = hsb.isOpaque(); if (viewport == pane.getRowHeader() - ? (!opaque || ScrollSettings.isHeaderOverCorner()) + ? (!opaque || ScrollSettings.isHeaderOverCorner(viewport)) : (!opaque && viewport == pane.getViewport())) { Alignment ha = UIUtil.getClientProperty(hsb, Alignment.class); if (ha == Alignment.TOP) { diff --git a/platform/platform-api/src/com/intellij/ui/components/ScrollSettings.java b/platform/platform-api/src/com/intellij/ui/components/ScrollSettings.java index 8be0e99a8f3d..3e5c5f47cc42 100644 --- a/platform/platform-api/src/com/intellij/ui/components/ScrollSettings.java +++ b/platform/platform-api/src/com/intellij/ui/components/ScrollSettings.java @@ -24,6 +24,8 @@ import com.intellij.openapi.util.registry.RegistryValue; import javax.swing.JDialog; import javax.swing.JScrollBar; +import javax.swing.JViewport; +import javax.swing.table.JTableHeader; import javax.swing.RootPaneContainer; import java.awt.Component; import java.awt.Container; @@ -72,7 +74,8 @@ final class ScrollSettings { return BACKGROUND_FROM_VIEW.asBoolean(); } - static boolean isHeaderOverCorner() { + static boolean isHeaderOverCorner(JViewport viewport) { + if (viewport.getView() instanceof JTableHeader) return false; return HEADER_OVER_CORNER.asBoolean(); } From 49b18fcd0ceba728a3cd26b675869b3acac6a769 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Mon, 10 Apr 2017 21:37:08 +0300 Subject: [PATCH 17/66] [groovy] implicit `it` in closure doesn't have initializer --- .../synthetic/ClosureSyntheticParameter.java | 14 +------------- .../convertToJava/AnonymousFromMapGenerator.java | 16 ++++++++++------ .../codeBlock/anonymousFromMap.groovy | 2 +- .../codeBlock/anonymousFromMap.java | 6 ++++++ 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/ClosureSyntheticParameter.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/ClosureSyntheticParameter.java index dc6b1a7a497a..13db03071c83 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/ClosureSyntheticParameter.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/synthetic/ClosureSyntheticParameter.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory; import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock; -import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter; import org.jetbrains.plugins.groovy.lang.psi.dataFlow.types.TypeInferenceHelper; import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil; @@ -90,15 +89,4 @@ public class ClosureSyntheticParameter extends GrLightParameter implements Navig public GrClosableBlock getClosure() { return myClosure; } - - @Override - public GrExpression getInitializerGroovy() { - return GroovyPsiElementFactory.getInstance(getProject()).createExpressionFromText("null"); - } - - @Nullable - @Override - public PsiElement getEllipsisDots() { - return null; - } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/AnonymousFromMapGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/AnonymousFromMapGenerator.java index 0f4b86ec3214..c4273d447bb4 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/AnonymousFromMapGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/convertToJava/AnonymousFromMapGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -72,15 +72,19 @@ public class AnonymousFromMapGenerator { for (int i = 0; i < allParameters.length; i++) { args[i] = factory.createExpressionFromText(allParameters[i].getName()); } - + boolean singleParam = allParameters.length == 1; for (int param = allParameters.length; param >= 0; param--) { - - - if (param < allParameters.length && !actual.get(param).isOptional()) continue; + if (param < allParameters.length && !(actual.get(param).isOptional() || singleParam)) continue; if (param < allParameters.length) { final GrParameter opt = actual.remove(param); - args[param] = opt.getInitializerGroovy(); + GrExpression initializer = opt.getInitializerGroovy(); + if (initializer == null) { + args[param] = factory.createExpressionFromText("null"); + } + else { + args[param] = initializer; + } } final GrParameter[] parameters = actual.toArray(new GrParameter[actual.size()]); diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/codeBlock/anonymousFromMap.groovy b/plugins/groovy/testdata/refactoring/convertGroovyToJava/codeBlock/anonymousFromMap.groovy index c766f15132bc..629936ff8423 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/codeBlock/anonymousFromMap.groovy +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/codeBlock/anonymousFromMap.groovy @@ -1,2 +1,2 @@ print([run: {print "foo}"}] as Runnable) - +print([run: {a -> print "foo}"}] as Runnable) diff --git a/plugins/groovy/testdata/refactoring/convertGroovyToJava/codeBlock/anonymousFromMap.java b/plugins/groovy/testdata/refactoring/convertGroovyToJava/codeBlock/anonymousFromMap.java index 1cb3b2258ab6..dace7fef92f4 100644 --- a/plugins/groovy/testdata/refactoring/convertGroovyToJava/codeBlock/anonymousFromMap.java +++ b/plugins/groovy/testdata/refactoring/convertGroovyToJava/codeBlock/anonymousFromMap.java @@ -4,3 +4,9 @@ public void run() { this.run(null); } }); +print(new java.lang.Runnable() { +public void run(java.lang.Object a) {print("foo}");} +public void run() { +this.run(null); +} +}); From e24b08b6f3e77ce1625ae345940eae4cbd4b7a0e Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Mon, 10 Apr 2017 21:52:06 +0300 Subject: [PATCH 18/66] [groovy] do not call getNode() on a file during completion Before the change element.getParent() returned current file, for example when cursor was at the very beginning. Then getPrevSibling() returned a neighbour file, which then was passed to skipWhitespacesAndComments() where getNode() was called forcing AST loading. --- .../lang/completion/GroovyCompletionData.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java index 1ddffb87f647..f0b9077753ee 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/completion/GroovyCompletionData.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -243,8 +243,16 @@ public class GroovyCompletionData { if (elem instanceof GrReferenceExpression && PsiUtil.skipWhitespacesAndComments(elem.getPrevSibling(), false) instanceof GrTypeDefinition) { elem = PsiUtil.skipWhitespacesAndComments(elem.getPrevSibling(), false); } - else if (elem.getParent() != null) { - elem = PsiUtil.skipWhitespacesAndComments(elem.getParent().getPrevSibling(), false); + else { + PsiElement parent = elem.getParent(); + if (parent != null) { + if (parent instanceof PsiFile) { + elem = null; + } + else { + elem = PsiUtil.skipWhitespacesAndComments(parent.getPrevSibling(), false); + } + } } } From ee5095bc644e4469a463195999642e0919f8cab4 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Tue, 11 Apr 2017 16:23:23 +0300 Subject: [PATCH 19/66] [groovy] process only DGM in super method search --- .../groovy/findUsages/GDKSuperMethodSearcher.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/findUsages/GDKSuperMethodSearcher.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/findUsages/GDKSuperMethodSearcher.java index 48740a3fb6e1..b8edb5d73ab3 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/findUsages/GDKSuperMethodSearcher.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/findUsages/GDKSuperMethodSearcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,11 +26,12 @@ import com.intellij.util.Processor; import com.intellij.util.QueryExecutor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.groovy.dgm.DGMMemberContributor; import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod; import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil; -import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil; +import org.jetbrains.plugins.groovy.lang.resolve.NonCodeMembersContributor; import org.jetbrains.plugins.groovy.lang.resolve.processors.MethodResolverProcessor; import java.util.ArrayList; @@ -42,6 +43,9 @@ import java.util.List; * @author Maxim.Medvedev */ public class GDKSuperMethodSearcher implements QueryExecutor { + + private static final DGMMemberContributor myContributor = NonCodeMembersContributor.EP_NAME.findExtension(DGMMemberContributor.class); + @Override public boolean execute(@NotNull SuperMethodsSearch.SearchParameters queryParameters, @NotNull Processor consumer) { final PsiMethod method = queryParameters.getMethod(); @@ -61,7 +65,7 @@ public class GDKSuperMethodSearcher implements QueryExecutor Date: Mon, 10 Apr 2017 20:24:11 +0300 Subject: [PATCH 20/66] Java: Cleanup upon review of inspection "Reflective invocation arguments mismatch", better handling of arrays (IDEA-167270, IDEA-CR-19841) --- .../JavaReflectionInvocationInspection.java | 3 +- .../impl/JavaReflectionReferenceUtil.java | 11 ++- .../ConstructorParamTypes.java | 81 +++++++++++++++--- .../MethodParamTypes.java | 84 ++++++++++++++++--- .../src/messages/InspectionsBundle.properties | 2 +- 5 files changed, 151 insertions(+), 30 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInspection/reflectiveAccess/JavaReflectionInvocationInspection.java b/java/java-impl/src/com/intellij/codeInspection/reflectiveAccess/JavaReflectionInvocationInspection.java index abd323f67c33..6d210a11311e 100644 --- a/java/java-impl/src/com/intellij/codeInspection/reflectiveAccess/JavaReflectionInvocationInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/reflectiveAccess/JavaReflectionInvocationInspection.java @@ -115,7 +115,8 @@ public class JavaReflectionInvocationInspection extends BaseJavaBatchLocalInspec final PsiExpression[] expressions = argumentList.getExpressions(); final PsiElement element = expressions.length == argumentOffset + 1 ? expressions[argumentOffset] : argumentList; holder.registerProblem(element, InspectionsBundle.message( - "inspection.reflection.invocation.item.number.not.assignable", i, requiredType.getQualifiedName())); + "inspection.reflection.invocation.array.not.assignable", actualArguments.expressions.length)); + break; } } } diff --git a/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/JavaReflectionReferenceUtil.java b/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/JavaReflectionReferenceUtil.java index 1328cb519c9c..670c5eae7d60 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/JavaReflectionReferenceUtil.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/JavaReflectionReferenceUtil.java @@ -374,12 +374,15 @@ public class JavaReflectionReferenceUtil { if (type.equals(PsiType.NULL)) { return myPsiClass != null || myArrayDimensions != 0; } - if (type.getArrayDimensions() != myArrayDimensions) { - return false; + PsiType otherType = type; + for (int i = 0; i < myArrayDimensions; i++) { + if (!(otherType instanceof PsiArrayType)) { + return false; + } + otherType = ((PsiArrayType)otherType).getComponentType(); } - final PsiType otherType = type.getDeepComponentType(); if (myPrimitiveType != null) { - return myPrimitiveType.isAssignableFrom(otherType) || otherType.equalsToText(myPrimitiveType.getBoxedTypeName()); + return myPrimitiveType.isAssignableFrom(otherType); } final PsiElementFactory factory = JavaPsiFacade.getInstance(myPsiClass.getProject()).getElementFactory(); return factory.createType(myPsiClass).isAssignableFrom(otherType); diff --git a/java/java-tests/testData/inspection/javaReflectionInvocation/ConstructorParamTypes.java b/java/java-tests/testData/inspection/javaReflectionInvocation/ConstructorParamTypes.java index 57a33f282be6..c2a1c41fc07e 100644 --- a/java/java-tests/testData/inspection/javaReflectionInvocation/ConstructorParamTypes.java +++ b/java/java-tests/testData/inspection/javaReflectionInvocation/ConstructorParamTypes.java @@ -1,3 +1,4 @@ +import java.io.Serializable; import java.lang.reflect.Constructor; import java.util.*; @@ -32,9 +33,9 @@ class ConstructorParamTypes { c2.newInstance(new Object[] {"abc", Integer.valueOf(42)}); c3.newInstance(new Object[] {new int[]{42, 23}, Arrays.asList("x", "y")}); - c1.newInstance(a2); - c2.newInstance(a3); - c3.newInstance(a1); + c1.newInstance(a2); + c2.newInstance(a3); + c3.newInstance(a1); c1.newInstance(new Object[]{"42", "abc"}); c2.newInstance(new Object[]{42, 23}); @@ -46,9 +47,18 @@ class ConstructorParamTypes { cls.getConstructor(String[].class).newInstance((Object)new String[] {"abc"}); cls.getConstructor(String[].class).newInstance(new String[] {"abc"}); + + Constructor c4 = cls.getConstructor(Cloneable.class); + Constructor c5 = cls.getConstructor(Serializable.class); + + c4.newInstance(new C()); + c5.newInstance(new S()); + + c4.newInstance(new S()); + c5.newInstance(new C()); } - void arraySignatutre() throws Exception { + void arraySignature() throws Exception { Class cls = Test.class; Constructor c1 = cls.getConstructor(new Class[]{int.class, String.class}); @@ -73,9 +83,9 @@ class ConstructorParamTypes { c2.newInstance(new Object[] {"abc", Integer.valueOf(42)}); c3.newInstance(new Object[] {new int[]{42, 23}, Arrays.asList("x", "y")}); - c1.newInstance(a2); - c2.newInstance(a3); - c3.newInstance(a1); + c1.newInstance(a2); + c2.newInstance(a3); + c3.newInstance(a1); c1.newInstance(new Object[]{"42", "abc"}); c2.newInstance(new Object[]{42, 23}); @@ -87,6 +97,15 @@ class ConstructorParamTypes { cls.getConstructor(new Class[]{String[].class}).newInstance((Object)new String[] {"abc"}); cls.getConstructor(new Class[]{String[].class}).newInstance(new String[] {"abc"}); + + Constructor c4 = cls.getConstructor(new Class[]{Cloneable.class}); + Constructor c5 = cls.getConstructor(new Class[]{Serializable.class}); + + c4.newInstance(new C()); + c5.newInstance(new S()); + + c4.newInstance(new S()); + c5.newInstance(new C()); } void manyArguments() throws Exception { @@ -107,11 +126,38 @@ class ConstructorParamTypes { Object[] a5 = {0, (short)0, 0, 0.0f, "abc"}; m0.newInstance(a0); - m1.newInstance(a1); - m2.newInstance(a2); - m3.newInstance(a3); - m4.newInstance(a4); - m5.newInstance(a5); + m1.newInstance(a1); + m2.newInstance(a2); + m3.newInstance(a3); + m4.newInstance(a4); + m5.newInstance(a5); + } + + void arrayArguments() throws Exception { + Class cls = Test.class; + + Constructor c1 = cls.getConstructor(Object.class); + Constructor c2 = cls.getConstructor(Cloneable.class); + Constructor c3 = cls.getConstructor(Serializable.class); + + c1.newInstance((Object) new String[0]); + c2.newInstance((Object) new String[0]); + c3.newInstance((Object) new String[0]); + + c1.newInstance((Object) new String[][]{ new String[0] }); + c2.newInstance((Object) new String[][]{ new String[0] }); + c3.newInstance((Object) new String[][]{ new String[0] }); + + Constructor c4 = cls.getConstructor(Object[].class); + Constructor c5 = cls.getConstructor(String[].class); + + c4.newInstance((Object) new String[0]); + c4.newInstance((Object) new String[][]{ new String[0] }); + + c5.newInstance((Object) new String[0]); + c5.newInstance((Object) new String[][]{ new String[0] }); + c5.newInstance("abc"); + c5.newInstance(new Test(1, null)); } class Test { @@ -119,6 +165,11 @@ class ConstructorParamTypes { public Test(String s, Integer n) {} public Test(int[] n, List s) {} public Test(String[] s) {} + public Test(Object[] s) {} + + public Test(Object o) {} + public Test(Cloneable c) {} + public Test(Serializable s) {} } class M { @@ -128,4 +179,10 @@ class ConstructorParamTypes { public String m4(int a1, short a2, long a3, float a4) {return "";} public String m5(int a1, short a2, long a3, float a4, double a5) {return "";} } + + static class S implements Serializable { + } + + static class C implements Cloneable { + } } \ No newline at end of file diff --git a/java/java-tests/testData/inspection/javaReflectionInvocation/MethodParamTypes.java b/java/java-tests/testData/inspection/javaReflectionInvocation/MethodParamTypes.java index 261998ff30f4..836102c0de47 100644 --- a/java/java-tests/testData/inspection/javaReflectionInvocation/MethodParamTypes.java +++ b/java/java-tests/testData/inspection/javaReflectionInvocation/MethodParamTypes.java @@ -1,3 +1,4 @@ +import java.io.Serializable; import java.lang.reflect.Method; import java.util.*; @@ -33,9 +34,9 @@ class MethodParamTypes { m2.invoke(obj, new Object[] {"abc", Integer.valueOf(42)}); m3.invoke(obj, new Object[] {new int[]{42, 23}, Arrays.asList("x", "y")}); - m1.invoke(obj, a2); - m2.invoke(obj, a3); - m3.invoke(obj, a1); + m1.invoke(obj, a2); + m2.invoke(obj, a3); + m3.invoke(obj, a1); m1.invoke(obj, new Object[]{"42", "abc"}); m2.invoke(obj, new Object[]{42, 23}); @@ -47,9 +48,18 @@ class MethodParamTypes { cls.getMethod("str", String[].class).invoke(null, (Object)new String[] {"abc"}); cls.getMethod("str", String[].class).invoke(null, new String[] {"abc"}); + + Method m4 = cls.getMethod("obj", Cloneable.class); + Method m5 = cls.getMethod("obj", Serializable.class); + + m4.invoke(obj, new C()); + m5.invoke(obj, new S()); + + m4.invoke(obj, new S()); + m5.invoke(obj, new C()); } - void arraySignatutre() throws Exception { + void arraySignature() throws Exception { Class cls = Test.class; Object obj = new Test(); @@ -75,9 +85,9 @@ class MethodParamTypes { m2.invoke(obj, new Object[] {"abc", Integer.valueOf(42)}); m3.invoke(obj, new Object[] {new int[]{42, 23}, Arrays.asList("x", "y")}); - m1.invoke(obj, a2); - m2.invoke(obj, a3); - m3.invoke(obj, a1); + m1.invoke(obj, a2); + m2.invoke(obj, a3); + m3.invoke(obj, a1); m1.invoke(obj, new Object[]{"42", "abc"}); m2.invoke(obj, new Object[]{42, 23}); @@ -89,6 +99,15 @@ class MethodParamTypes { cls.getMethod("str", new Class[]{String[].class}).invoke(null, (Object)new String[] {"abc"}); cls.getMethod("str", new Class[]{String[].class}).invoke(null, new String[] {"abc"}); + + Method m4 = cls.getMethod("obj", new Class[]{Cloneable.class}); + Method m5 = cls.getMethod("obj", new Class[]{Serializable.class}); + + m4.invoke(obj, new C()); + m5.invoke(obj, new S()); + + m4.invoke(obj, new S()); + m5.invoke(obj, new C()); } void manyArguments() throws Exception { @@ -110,11 +129,39 @@ class MethodParamTypes { Object[] a5 = {0, (short)0, 0, 0.0f, "abc"}; m0.invoke(obj, a0); - m1.invoke(obj, a1); - m2.invoke(obj, a2); - m3.invoke(obj, a3); - m4.invoke(obj, a4); - m5.invoke(obj, a5); + m1.invoke(obj, a1); + m2.invoke(obj, a2); + m3.invoke(obj, a3); + m4.invoke(obj, a4); + m5.invoke(obj, a5); + } + + void arrayArguments() throws Exception { + Class cls = Test.class; + Object obj = new Test(); + + Method m1 = cls.getMethod("obj", Object.class); + Method m2 = cls.getMethod("obj", Cloneable.class); + Method m3 = cls.getMethod("obj", Serializable.class); + + m1.invoke(obj, (Object) new String[0]); + m2.invoke(obj, (Object) new String[0]); + m3.invoke(obj, (Object) new String[0]); + + m1.invoke(obj, (Object) new String[][]{ new String[0] }); + m2.invoke(obj, (Object) new String[][]{ new String[0] }); + m3.invoke(obj, (Object) new String[][]{ new String[0] }); + + Method m4 = cls.getMethod("array", Object[].class); + Method m5 = cls.getMethod("array", String[].class); + + m4.invoke(null, (Object) new String[0]); + m4.invoke(null, (Object) new String[][]{ new String[0] }); + + m5.invoke(null, (Object) new String[0]); + m5.invoke(null, (Object) new String[][]{ new String[0] }); + m5.invoke(null, "abc"); + m5.invoke(null, obj); } static class Test { @@ -123,6 +170,13 @@ class MethodParamTypes { public void bar(int[] n, List s) {} public static void str(String[] s) {} + + public void obj(Object o) {} + public void obj(Cloneable c) {} + public void obj(Serializable s) {} + + public static void array(Object[] a) {} + public static void array(String[] a) {} } class M { @@ -132,4 +186,10 @@ class MethodParamTypes { public String m4(int a1, short a2, long a3, float a4) {return "";} public String m5(int a1, short a2, long a3, float a4, double a5) {return "";} } + + static class S implements Serializable { + } + + static class C implements Cloneable { + } } \ No newline at end of file diff --git a/platform/platform-resources-en/src/messages/InspectionsBundle.properties b/platform/platform-resources-en/src/messages/InspectionsBundle.properties index 8ce66459e6a1..b6a9271a8f64 100644 --- a/platform/platform-resources-en/src/messages/InspectionsBundle.properties +++ b/platform/platform-resources-en/src/messages/InspectionsBundle.properties @@ -819,4 +819,4 @@ inspection.reflection.invocation.argument.count={0,choice,0#No arguments are|1#O inspection.reflection.invocation.item.count={0,choice,0#Empty array is|1#Single-item array is|1<{0} array items are} expected inspection.reflection.invocation.argument.not.assignable=Argument is not assignable to ''{0}'' inspection.reflection.invocation.item.not.assignable=Array item is not assignable to ''{0}'' -inspection.reflection.invocation.item.number.not.assignable=Array item {0} is not assignable to ''{1}'' \ No newline at end of file +inspection.reflection.invocation.array.not.assignable=Array {0,choice,1#item has|1 Date: Tue, 11 Apr 2017 16:42:27 +0300 Subject: [PATCH 21/66] build scripts: don't interrupt project loading if Kotlin Compiler is already in classpath All glory to statically typed languages! --- build/scripts/utils.gant | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/scripts/utils.gant b/build/scripts/utils.gant index 031e6b7e54d0..6bccdfbbf0d0 100644 --- a/build/scripts/utils.gant +++ b/build/scripts/utils.gant @@ -151,7 +151,7 @@ private void setupKotlin() { private boolean ensureKotlinCompilerAddedToClassPath() { if (getClass().getResource("/org/jetbrains/kotlin/jps/build/KotlinBuilder.class") != null) { - return + return true } def kotlinPluginLibPath = "$home/build/dependencies/build/Kotlin/lib" From 0af6e32a6c19e52797459909da1dc4ea7166e2c4 Mon Sep 17 00:00:00 2001 From: Alexander Kass Date: Tue, 11 Apr 2017 11:20:49 +0300 Subject: [PATCH 22/66] UNG: fix null names --- .../util/src/com/intellij/util/text/UniqueNameGenerator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/util/src/com/intellij/util/text/UniqueNameGenerator.java b/platform/util/src/com/intellij/util/text/UniqueNameGenerator.java index 2d3dfb4ee61f..ee629fc21773 100644 --- a/platform/util/src/com/intellij/util/text/UniqueNameGenerator.java +++ b/platform/util/src/com/intellij/util/text/UniqueNameGenerator.java @@ -16,6 +16,7 @@ package com.intellij.util.text; import com.intellij.openapi.util.Condition; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.Function; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; @@ -32,7 +33,7 @@ public class UniqueNameGenerator implements Condition { public UniqueNameGenerator(@NotNull Collection elements, @Nullable Function namer) { for (final T t : elements) { - addExistingName(namer != null ? namer.fun(t) : t.toString()); + addExistingName(namer != null ? StringUtil.notNullize(namer.fun(t)) : t.toString()); } } From 2cbd8e1149bdecddf8ea988c8f62dc6c69cbe0ea Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Tue, 11 Apr 2017 16:53:16 +0300 Subject: [PATCH 23/66] DSGN-3290 diff: update icons for frame windows --- .../src/com/intellij/diff/util/DiffUtil.java | 1 - platform/icons/src/diff_frame128.png | Bin 633 -> 901 bytes platform/icons/src/diff_frame16.png | Bin 155 -> 0 bytes platform/icons/src/diff_frame32.png | Bin 217 -> 359 bytes platform/icons/src/diff_frame64.png | Bin 363 -> 562 bytes 5 files changed, 1 deletion(-) delete mode 100644 platform/icons/src/diff_frame16.png diff --git a/platform/diff-impl/src/com/intellij/diff/util/DiffUtil.java b/platform/diff-impl/src/com/intellij/diff/util/DiffUtil.java index 481c376804d1..922145918392 100644 --- a/platform/diff-impl/src/com/intellij/diff/util/DiffUtil.java +++ b/platform/diff-impl/src/com/intellij/diff/util/DiffUtil.java @@ -120,7 +120,6 @@ public class DiffUtil { @NotNull private static List loadDiffFrameImages() { return ContainerUtil.list( - ImageLoader.loadFromResource("/diff_frame16.png"), ImageLoader.loadFromResource("/diff_frame32.png"), ImageLoader.loadFromResource("/diff_frame64.png"), ImageLoader.loadFromResource("/diff_frame128.png") diff --git a/platform/icons/src/diff_frame128.png b/platform/icons/src/diff_frame128.png index 7fe30c2947391f6b13c569063e50d583c5e2910e..dea2af2cd39fd0c96da5d814f466e291cccbc2b3 100644 GIT binary patch literal 901 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1|$#LC7uRSk|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*9U+nAJU9978H@y_xHscR4_$Eq^uNW|jn(@{4>98h%=73dC~UnVs622&g|1?APtLl_Tex%=dOgaH|6MbGiYI&D{_UUomhXyy^KddBr}d$w3D=$~&dc{bzp7xs?i)t|Tj`{y&ck)f=fu~0;@ z;fcCV5|f0OLm;CMgVup4GvkUQLAA9N-|eoxcAd6Af+^pS>+s7E%M7!X44u{vLN|I@ z)_zreAQG@a_JP%gK!F#6k}KU-AJuf2#PGSXx2fQkA$zum1M7_U42zvwqnb3jLNAxD zWbhRIa6M_oYlX`Bp(+cQxVEwAap~-tcA&UeRD{vTzu|vOz9{F4hNi!A5B426^sqp! z(Vcb5Uy%(R3KJc=FMX+1bNIKs!QwKffxhFC@BG(4-()H>gX3{!fU{-tZ@JyC_b67$eUUDYf z?2w%|H`epQ%K%2N7xPCb^oUiV<{*>6z63^&`r2(>Rgd$(eZQLhSE;6v>5IQ#$l5sdnod!NABTX- zra2r+=iFlcM_*ig<-OC3+xcfO*!+YW1Z2ES`m?|7@1L)?U+v!|(|>$b(8`GF`d=a& z4zd_@T+i@PozPXmxGyfQYg&V9zz!A;g&3f3^%{Q!ADBFMuC;yjp1o`D&6~Hb#OlZO zuh$;l?tedrX$A{N0}&{p6=E6#3m9TcvLLa^e*_a4n!4CCX6=7t3li{j^>bP0l+XkK D+?Hh! literal 633 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1|$#LC7uRSk|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*9U+n4~>j978H@y}5hP^Kb$~+ruRt$E$)^+&47eV7;O#qAobs z$@Pog(cG3G^AC&I`kj={`uqI0eIM!dwOZ=-q-CM1o|9BOCk3tgeeXcg*MB=t);An( zUd%iH!{Y00!u^eJ7#JKFI2afe7+4P2msb|1PEBF>Ud}JDYF4KeE&n9g=8O~eE z!r{)~V8O(2NRUCGkD;M}g`q{cz|MiaY1yQFk*WXZ9sTy&!ivd4h=GBTK>!Q!k%Iw? z2@DD{jlqZ5TnvuA+Gif{Yj<<|x<8gx&d=vKfTE}YXcChHC_Ys@_x}<~V7PrW+GN$i Ru(=FC;OXk;vd$@?2>|tS=V|}| diff --git a/platform/icons/src/diff_frame16.png b/platform/icons/src/diff_frame16.png deleted file mode 100644 index b86600dd917b4e77b77d1ad22f918932612261b7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 155 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`NuDl_Ar-fh6BdY7e0=q_K4(T_ zBQN{0M289&o>aC5m5IEHrx{Y5J4_gMD@{-gF->^1WaX1;#wC(hy;WG0e2fFx7Pu>K zN;_lXD@F$G@qC`(fkXJAn4pYbg2i{mk%Z492SelF{r5}E-2 C#4`i{ diff --git a/platform/icons/src/diff_frame32.png b/platform/icons/src/diff_frame32.png index 65bb77966fd35ff56928b139cec5c4d441ec5daa..8f09468171a0fc7ca9172088142a0bc820aec711 100644 GIT binary patch delta 333 zcmV-T0kZzt0p|jcBYy!dNklZDIw5gg7czA2+fpbC%ohuA z9LHJdZksJBlm(`<891Hx1BS!5K-ajul0sSFcQOIzqIQnE)_)Cb+y3vWH7S$@#^WDw z&MGG!*UKv!3|_tNbopBbWr1U(j7^BU(eJ+?>KvggP&&*bie|k5nR5bVfrGt$Y@$*= zg4OLI>KvggF#7riCzsvzFp4FZRyWWQ;*;Z@ARd98EQ~@CrfCH_LX5wEdfB9f0l#Dms8PgJ6yrFbBXKF>)P1gD4pAL`dCiIC0X{fh&kWmg9CD zjf-NKV!Z diff --git a/platform/icons/src/diff_frame64.png b/platform/icons/src/diff_frame64.png index faab388ebb6a848845a42195dd29f086c87e8412..754e9907427a4b558f4b909fca94638e344acd84 100644 GIT binary patch delta 537 zcmV+!0_Oee0VAwo)t2yxXbphyDJ;PWJ&1XD?VcvN`yz3(MhP7=~dOhG7_nLGWED0Hq6a^P~z7 zkk99V()rLVslo%~a$i7cXnKZJ;Q>CgS-^N1kE8BpCZ|Xh9)IBD;}bAW1t;L*>>PDR zsqg@q_jkZJF&-#;c5-TY7cAaTDm*|sodJvi|Jbi5N5|%Oqkd9_2Y5@R0Hc4z_s7^_ z40Ttp!UMd#z5zzxu(!&C=zi7RNbz$@g$GC`UjUK}l5-PzuO zr{`o@iuWoN9)Dn<*8>!8ZEV8B;}cN5rzt#ur`ruwZba6B^1YJ61Gu|fKxHJn2JX%- zQiTU_wRZr8;gwamy}Jjh_cVnE=xB99y{;~=l*gB(c&}370kkh}XIpcNq05U)sJmKi zm;lbE<|_5$&F=JGU0tK@N;Yf&qw$ykrSaHM4I990yno#=ZM@V0tj1dns~j(F0K4&K z!}Q~&41gJLG|XtclmTk_tuPy}L;$Pt|53^SRO6)#KsjE@0Extn+5!69J){w&{0*Rt zAnjiPy9i4BA7B+hi2zm+lnG!KL8$;n5tIv{kDz3L$_UB^&>|=u;6HKzhG7_nVHk#C b7z97N#u7^Lcl~<&00000NkvXXu0mjfBLe>x delta 336 zcmV-W0k8hD1nUBjB!4nVL_t(|+U?sx4uUWch2gF|4I59R3ooUKm(#d6a)=rhB!mdG z*iNQ1|0G=+d|v{z(-HzjQPfJkKYgq@LO4_&0001h1i1;84D8-OJQg#dN`&>X=Xz#PFPz<(6MEx?EX0Ji`SL0*GQ zgqRAm7|I&g+uiSScnF{OJ3|eTF?((0R{5~sygx5cH7%d6cOk^Ejj<<=Nq ii~s;IXa%0000 Date: Tue, 11 Apr 2017 15:24:10 +0200 Subject: [PATCH 24/66] com.intellij.util.containers: add @FunctionalInterface --- .../anno/com/intellij/util/containers/annotations.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/platform/util/anno/com/intellij/util/containers/annotations.xml b/platform/util/anno/com/intellij/util/containers/annotations.xml index fade09d3017b..b49b0a379e92 100644 --- a/platform/util/anno/com/intellij/util/containers/annotations.xml +++ b/platform/util/anno/com/intellij/util/containers/annotations.xml @@ -15,4 +15,13 @@ + + + + + + + + + \ No newline at end of file From 2bae2fc9b49be41310372685879c84866d423f1d Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 11 Apr 2017 15:30:54 +0200 Subject: [PATCH 25/66] add @NotNull --- .../src/com/intellij/psi/stubs/EmptyStubElementType.java | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/core-api/src/com/intellij/psi/stubs/EmptyStubElementType.java b/platform/core-api/src/com/intellij/psi/stubs/EmptyStubElementType.java index 634b491854b3..6fcba842d7b3 100644 --- a/platform/core-api/src/com/intellij/psi/stubs/EmptyStubElementType.java +++ b/platform/core-api/src/com/intellij/psi/stubs/EmptyStubElementType.java @@ -31,6 +31,7 @@ public abstract class EmptyStubElementType extends IStubEl super(debugName, language); } + @NotNull @Override public final EmptyStub createStub(@NotNull T psi, StubElement parentStub) { return createStub(parentStub); From 1edd93719a0f3aa8f5b568ea0fc9a7e95efaba20 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 11 Apr 2017 15:44:21 +0200 Subject: [PATCH 26/66] more diagnostics for EA-99911 - assert: IStubElementType. and make the flag volatile, in case it's caused by instruction reordering --- .../com/intellij/psi/stubs/IStubElementType.java | 14 +++++++++++--- .../psi/stubs/StubElementTypeHolderEP.java | 7 ++++++- .../intellij/psi/stubs/SerializationManager.java | 6 +----- 3 files changed, 18 insertions(+), 9 deletions(-) rename platform/{indexing-api => core-api}/src/com/intellij/psi/stubs/StubElementTypeHolderEP.java (92%) diff --git a/platform/core-api/src/com/intellij/psi/stubs/IStubElementType.java b/platform/core-api/src/com/intellij/psi/stubs/IStubElementType.java index bb3f87afa3b7..cfe36c13d63d 100644 --- a/platform/core-api/src/com/intellij/psi/stubs/IStubElementType.java +++ b/platform/core-api/src/com/intellij/psi/stubs/IStubElementType.java @@ -22,24 +22,32 @@ package com.intellij.psi.stubs; import com.intellij.lang.ASTNode; import com.intellij.lang.Language; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.extensions.Extensions; import com.intellij.psi.PsiElement; import com.intellij.psi.tree.IElementType; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; + public abstract class IStubElementType extends IElementType implements StubSerializer { - private static boolean ourInitializedStubs; + private static volatile boolean ourInitializedStubs; private static final Logger LOG = Logger.getInstance("#com.intellij.psi.stubs.IStubElementType"); public IStubElementType(@NotNull @NonNls final String debugName, @Nullable final Language language) { super(debugName, language); if (ourInitializedStubs) { - LOG.error("All stub element types should be created before index initialization is complete. Please add the class containing stub element type constants to \"stubElementTypeHolder\" extension."); + LOG.error("All stub element types should be created before index initialization is complete.\n" + + "Please add the class containing stub element type constants to \"stubElementTypeHolder\" extension.\n" + + "Registered extensions: " + Arrays.toString(StubElementTypeHolderEP.EP_NAME.getExtensions())); } } - static void markStubInitializationComplete() { + static void loadRegisteredStubElementTypes() { + for (StubElementTypeHolderEP holderEP : Extensions.getExtensions(StubElementTypeHolderEP.EP_NAME)) { + holderEP.initialize(); + } ourInitializedStubs = true; } diff --git a/platform/indexing-api/src/com/intellij/psi/stubs/StubElementTypeHolderEP.java b/platform/core-api/src/com/intellij/psi/stubs/StubElementTypeHolderEP.java similarity index 92% rename from platform/indexing-api/src/com/intellij/psi/stubs/StubElementTypeHolderEP.java rename to platform/core-api/src/com/intellij/psi/stubs/StubElementTypeHolderEP.java index 9d4f64ff1429..60fee521c764 100644 --- a/platform/indexing-api/src/com/intellij/psi/stubs/StubElementTypeHolderEP.java +++ b/platform/core-api/src/com/intellij/psi/stubs/StubElementTypeHolderEP.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,4 +40,9 @@ public class StubElementTypeHolderEP extends AbstractExtensionPointBean { LOG.error(e); } } + + @Override + public String toString() { + return holderClass; + } } diff --git a/platform/indexing-api/src/com/intellij/psi/stubs/SerializationManager.java b/platform/indexing-api/src/com/intellij/psi/stubs/SerializationManager.java index 24e766db456e..b72f8bb57a5c 100644 --- a/platform/indexing-api/src/com/intellij/psi/stubs/SerializationManager.java +++ b/platform/indexing-api/src/com/intellij/psi/stubs/SerializationManager.java @@ -20,7 +20,6 @@ package com.intellij.psi.stubs; import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.extensions.Extensions; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.StubFileElementType; import org.jetbrains.annotations.NotNull; @@ -45,10 +44,7 @@ public abstract class SerializationManager { if (mySerializersLoaded) return; synchronized (this) { if (mySerializersLoaded) return; - for (StubElementTypeHolderEP holderEP : Extensions.getExtensions(StubElementTypeHolderEP.EP_NAME)) { - holderEP.initialize(); - } - IStubElementType.markStubInitializationComplete(); + IStubElementType.loadRegisteredStubElementTypes(); final IElementType[] stubElementTypes = IElementType.enumerate(new IElementType.Predicate() { @Override public boolean matches(@NotNull final IElementType type) { From a4a4f57a6fe5a9aad05486fcd13df5c4cfa642c2 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 11 Apr 2017 16:08:26 +0200 Subject: [PATCH 27/66] tests: reload file from disk immediately after copying to project fixes some tests that open files in editor several times --- .../fixtures/impl/CodeInsightTestFixtureImpl.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index b9137b5a4f44..b89b60cad63d 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -309,16 +309,20 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig targetFile.putUserData(VfsTestUtil.TEST_DATA_FILE_PATH, sourceFile.getAbsolutePath()); } - final File _source = sourceFile; - final VirtualFile _target = targetFile; + copyContent(sourceFile, targetFile); + + return targetFile; + } + + private static void copyContent(File sourceFile, VirtualFile targetFile) { new WriteAction() { @Override protected void run(@NotNull Result result) throws IOException { - _target.setBinaryContent(FileUtil.loadFileBytes(_source)); + targetFile.setBinaryContent(FileUtil.loadFileBytes(sourceFile)); + // update the document now, otherwise MemoryDiskConflictResolver will do it later at unexpected moment of time + FileDocumentManager.getInstance().reloadFiles(targetFile); } }.execute(); - - return targetFile; } @NotNull From 75c5dfdf03e8cb657bbf113b32ee6f2497720881 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Tue, 11 Apr 2017 14:40:25 +0200 Subject: [PATCH 28/66] read action (EA-100181 - assert: PsiFileImpl.getStubTree) --- .../src/com/intellij/codeInsight/daemon/impl/MarkerType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/MarkerType.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/MarkerType.java index 7da422c36c5a..4cc52be1aa29 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/MarkerType.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/MarkerType.java @@ -462,7 +462,7 @@ public class MarkerType { return super.process(psiMethod); } }); - if (myMethod.hasModifierProperty(PsiModifier.ABSTRACT)) { + if (ReadAction.compute(() -> myMethod.hasModifierProperty(PsiModifier.ABSTRACT))) { PsiClass psiClass = ReadAction.compute(myMethod::getContainingClass); FunctionalExpressionSearch.search(psiClass).forEach(new CommonProcessors.CollectProcessor() { @Override From 795f9698d394ef42cae1df70d6493dc292e59a2f Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Tue, 11 Apr 2017 14:54:59 +0200 Subject: [PATCH 29/66] convert static to instance: more clear unable to refactor message --- .../src/messages/RefactoringBundle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/platform-resources-en/src/messages/RefactoringBundle.properties b/platform/platform-resources-en/src/messages/RefactoringBundle.properties index 446d08d09196..75b84b669f56 100644 --- a/platform/platform-resources-en/src/messages/RefactoringBundle.properties +++ b/platform/platform-resources-en/src/messages/RefactoringBundle.properties @@ -152,8 +152,8 @@ variable.of.type=Variable of &type: convert.to.instance.method.title=Convert To Instance Method convertToInstanceMethod.method.is.not.static=Cannot perform the refactoring\nMethod {0} is not static convertToInstanceMethod.no.parameters.with.reference.type=There are no parameters that have reference type -convertToInstanceMethod.all.reference.type.parametres.have.unknown.types=All reference type parameters have unknown types -convertToInstanceMethod.all.reference.type.parameters.are.not.in.project=All reference type parameters have types that are not in project +convertToInstanceMethod.all.reference.type.parametres.have.unknown.types=No target class for the instance method is found: all referenced types are unknown +convertToInstanceMethod.all.reference.type.parameters.are.not.in.project=No target class for the instance method is found: all referenced types are not in project cannot.perform.refactoring=Cannot perform refactoring. move.instance.method.title=Move Instance Method move.method.is.not.supported.for.constructors=Move method is not supported for constructors From 5430f8b5ac9049c93cd9d80c0f76b459dfd20b20 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Tue, 11 Apr 2017 16:14:06 +0200 Subject: [PATCH 30/66] ensure prepareMovedFile invoked after move directory --- .../MoveFilesOrDirectoriesProcessor.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/refactoring/move/moveFilesOrDirectories/MoveFilesOrDirectoriesProcessor.java b/platform/lang-impl/src/com/intellij/refactoring/move/moveFilesOrDirectories/MoveFilesOrDirectoriesProcessor.java index 511316f8ea35..196fb8d19098 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/move/moveFilesOrDirectories/MoveFilesOrDirectoriesProcessor.java +++ b/platform/lang-impl/src/com/intellij/refactoring/move/moveFilesOrDirectories/MoveFilesOrDirectoriesProcessor.java @@ -160,10 +160,11 @@ public class MoveFilesOrDirectoriesProcessor extends BaseRefactoringProcessor { final RefactoringElementListener elementListener = getTransaction().getElementListener(element); if (element instanceof PsiDirectory) { + if (mySearchForReferences) encodeDirectoryFiles(element); + MoveFilesOrDirectoriesUtil.doMoveDirectory((PsiDirectory)element, myNewParent); for (PsiElement psiElement : element.getChildren()) { processDirectoryFiles(movedFiles, oldToNewMap, psiElement); } - MoveFilesOrDirectoriesUtil.doMoveDirectory((PsiDirectory)element, myNewParent); } else if (element instanceof PsiFile) { final PsiFile movedFile = (PsiFile)element; @@ -239,10 +240,20 @@ public class MoveFilesOrDirectoriesProcessor extends BaseRefactoringProcessor { return data; } - private void processDirectoryFiles(List movedFiles, Map oldToNewMap, PsiElement psiElement) { + private static void encodeDirectoryFiles(PsiElement psiElement) { + if (psiElement instanceof PsiFile) { + FileReferenceContextUtil.encodeFileReferences(psiElement); + } + else if (psiElement instanceof PsiDirectory) { + for (PsiElement element : psiElement.getChildren()) { + encodeDirectoryFiles(element); + } + } + } + + private static void processDirectoryFiles(List movedFiles, Map oldToNewMap, PsiElement psiElement) { if (psiElement instanceof PsiFile) { final PsiFile movedFile = (PsiFile)psiElement; - if (mySearchForReferences) FileReferenceContextUtil.encodeFileReferences(psiElement); MoveFileHandler.forElement(movedFile).prepareMovedFile(movedFile, movedFile.getParent(), oldToNewMap); movedFiles.add(movedFile); } From c917f02b47368a25e7976815807f3558ec216855 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Tue, 11 Apr 2017 16:20:35 +0200 Subject: [PATCH 31/66] testdata for javac resolution order: to be merged in java 9 update --- .../TopLevelParentNoParameters.java | 26 +++++++++++++++++++ .../GraphInferenceHighlightingTest.java | 4 +++ 2 files changed, 30 insertions(+) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/TopLevelParentNoParameters.java diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/TopLevelParentNoParameters.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/TopLevelParentNoParameters.java new file mode 100644 index 000000000000..0431d525cb85 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/TopLevelParentNoParameters.java @@ -0,0 +1,26 @@ + +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.logging.Logger; + +class MyTest +{ + private final static Logger LOGGER = Logger.getLogger(MyTest.class.getName()); + + public static void test(List> testList) { + testList.forEach( MyTest.bind(MyTest.cast(LOGGER::info), iterable -> "")); + } + + private static TestConsumer bind(Consumer delegate, Function function) { + return null; + } + + private static Consumer cast(Consumer consumer) + { + return consumer; + } + + private interface TestConsumer extends Consumer { } + +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java index bf3d4c349a7e..50ae8601fd14 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java @@ -178,6 +178,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase doTest(); } + public void testTopLevelParentNoParameters() throws Exception { + doTest(); + } + private void doTest() { doTest(false); } From f96fd092af94988066616c5411d36969888411be Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 11 Apr 2017 16:21:32 +0200 Subject: [PATCH 32/66] Use UAST to determine when an unresolved reference is inside an annotation --- .../daemon/impl/quickfix/OrderEntryFix.java | 13 ++++++++----- .../jetbrains/uast/java/JavaUastLanguagePlugin.kt | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/OrderEntryFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/OrderEntryFix.java index 13571b4dc8de..e41d9be7d87e 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/OrderEntryFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/OrderEntryFix.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import com.intellij.codeInsight.daemon.quickFix.ExternalLibraryResolver.External import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.codeInspection.LocalQuickFix; import com.intellij.codeInspection.ProblemDescriptor; +import com.intellij.lang.java.JavaLanguage; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.DumbService; @@ -36,13 +37,15 @@ import com.intellij.psi.*; import com.intellij.psi.impl.source.PsiJavaModuleReference; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.PsiShortNamesCache; -import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiUtil; import com.intellij.util.ThreeState; import com.intellij.util.containers.ContainerUtil; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.uast.UAnnotation; +import org.jetbrains.uast.UImportStatement; +import org.jetbrains.uast.UastContextKt; import java.io.File; import java.util.*; @@ -219,13 +222,13 @@ public abstract class OrderEntryFix implements IntentionAction, LocalQuickFix { } private static ThreeState isReferenceToAnnotation(final PsiElement psiElement) { - if (!PsiUtil.isLanguageLevel5OrHigher(psiElement)) { + if (psiElement.getLanguage() == JavaLanguage.INSTANCE && !PsiUtil.isLanguageLevel5OrHigher(psiElement)) { return ThreeState.NO; } - if (PsiTreeUtil.getParentOfType(psiElement, PsiAnnotation.class) != null) { + if (UastContextKt.getUastParentOfType(psiElement, UAnnotation.class) != null) { return ThreeState.YES; } - if (PsiTreeUtil.getParentOfType(psiElement, PsiImportStatement.class) != null) { + if (UastContextKt.getUastParentOfType(psiElement, UImportStatement.class) != null) { return ThreeState.UNSURE; } return ThreeState.NO; diff --git a/uast/uast-java/src/org/jetbrains/uast/java/JavaUastLanguagePlugin.kt b/uast/uast-java/src/org/jetbrains/uast/java/JavaUastLanguagePlugin.kt index 46c9652380ca..afe5b8660f03 100644 --- a/uast/uast-java/src/org/jetbrains/uast/java/JavaUastLanguagePlugin.kt +++ b/uast/uast-java/src/org/jetbrains/uast/java/JavaUastLanguagePlugin.kt @@ -158,6 +158,7 @@ internal object JavaConverter { is PsiExpressionStatement -> unwrapElements(element.parent) is PsiParameterList -> unwrapElements(element.parent) is PsiAnnotationParameterList -> unwrapElements(element.parent) + is PsiModifierList -> unwrapElements(element.parent) else -> element } From 092be128987e98836348316ff60815a477faf100 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Tue, 11 Apr 2017 17:44:28 +0300 Subject: [PATCH 33/66] IDEA-168111 Open project in current window opens new window instead --- .../python/newProject/steps/PythonGenerateProjectCallback.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/python-community-configure/src/com/jetbrains/python/newProject/steps/PythonGenerateProjectCallback.java b/python/python-community-configure/src/com/jetbrains/python/newProject/steps/PythonGenerateProjectCallback.java index afa444caa9e7..7301d5f98c5b 100644 --- a/python/python-community-configure/src/com/jetbrains/python/newProject/steps/PythonGenerateProjectCallback.java +++ b/python/python-community-configure/src/com/jetbrains/python/newProject/steps/PythonGenerateProjectCallback.java @@ -116,7 +116,7 @@ public class PythonGenerateProjectCallback implements NullableConsumer computeProjectSettings(generator, (ProjectSpecificSettingsStep)settings)); } From 2a8cdc4f0c97f170f03bb728e518187bcbf19f3a Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 11 Apr 2017 16:36:21 +0200 Subject: [PATCH 34/66] restore PSI event firing on file copying --- .../psi/impl/file/impl/PsiEventsTest.java | 15 +++++++++++++++ .../psi/impl/file/impl/PsiVFSListener.java | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/PsiEventsTest.java b/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/PsiEventsTest.java index 9681d9e2bc82..e7d41970d988 100644 --- a/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/PsiEventsTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/impl/file/impl/PsiEventsTest.java @@ -16,6 +16,7 @@ package com.intellij.psi.impl.file.impl; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Document; import com.intellij.openapi.fileEditor.FileDocumentManager; @@ -814,4 +815,18 @@ public class PsiEventsTest extends PsiTestCase { PsiDocumentManager.getInstance(myProject).commitAllDocuments(); assertEquals(" ", getPsiManager().findFile(vFile).getText()); } + + public void testCopyFile() throws Exception { + VirtualFile original = createFile(myModule, mySrcDir1, "a.xml", "").getVirtualFile(); + + EventsTestListener listener = new EventsTestListener(); + myPsiManager.addPsiTreeChangeListener(listener,getTestRootDisposable()); + + PsiDirectory psiDir2 = PsiManager.getInstance(myProject).findDirectory(mySrcDir2); + assertNotNull(psiDir2); + WriteAction.run(() -> original.copy(this, mySrcDir2, "b.xml")); + + assertEquals("beforeChildAddition\n" + + "childAdded\n", listener.getEventsString()); + } } diff --git a/platform/lang-impl/src/com/intellij/psi/impl/file/impl/PsiVFSListener.java b/platform/lang-impl/src/com/intellij/psi/impl/file/impl/PsiVFSListener.java index c7d502240e17..018c61129602 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/file/impl/PsiVFSListener.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/file/impl/PsiVFSListener.java @@ -133,6 +133,11 @@ public class PsiVFSListener implements VirtualFileListener { return parent == null ? null : myFileManager.getCachedDirectory(parent); } + @Override + public void fileCopied(@NotNull VirtualFileCopyEvent event) { + fileCreated(event); + } + @Override public void fileCreated(@NotNull VirtualFileEvent event) { final VirtualFile vFile = event.getFile(); From ec48dbd165dde78cd90ef36724a2a4085ceedf0a Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Tue, 11 Apr 2017 17:06:09 +0200 Subject: [PATCH 35/66] collect all suppressors from the language (IDEA-169300) --- .../InspectionProfileEntry.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java b/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java index d2d041879c76..576402bc645c 100644 --- a/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java +++ b/platform/analysis-api/src/com/intellij/codeInspection/InspectionProfileEntry.java @@ -49,10 +49,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.Set; +import java.util.*; /** * @author anna @@ -177,26 +174,32 @@ public abstract class InspectionProfileEntry implements BatchSuppressableTool { @NotNull public static Set getSuppressors(@NotNull PsiElement element) { FileViewProvider viewProvider = element.getContainingFile().getViewProvider(); - final InspectionSuppressor elementLanguageSuppressor = LanguageInspectionSuppressors.INSTANCE.forLanguage(element.getLanguage()); + final List elementLanguageSuppressor = LanguageInspectionSuppressors.INSTANCE.allForLanguage(element.getLanguage()); if (viewProvider instanceof TemplateLanguageFileViewProvider) { Set suppressors = new LinkedHashSet<>(); - ContainerUtil.addIfNotNull(suppressors, LanguageInspectionSuppressors.INSTANCE.forLanguage(viewProvider.getBaseLanguage())); + ContainerUtil.addAllNotNull(suppressors, LanguageInspectionSuppressors.INSTANCE.allForLanguage(viewProvider.getBaseLanguage())); for (Language language : viewProvider.getLanguages()) { - ContainerUtil.addIfNotNull(suppressors, LanguageInspectionSuppressors.INSTANCE.forLanguage(language)); + ContainerUtil.addAllNotNull(suppressors, LanguageInspectionSuppressors.INSTANCE.allForLanguage(language)); } - ContainerUtil.addIfNotNull(suppressors, elementLanguageSuppressor); + ContainerUtil.addAllNotNull(suppressors, elementLanguageSuppressor); return suppressors; } if (!element.getLanguage().isKindOf(viewProvider.getBaseLanguage())) { // handling embedding elements {@link EmbeddingElementType Set suppressors = new LinkedHashSet<>(); - ContainerUtil.addIfNotNull(suppressors, LanguageInspectionSuppressors.INSTANCE.forLanguage(viewProvider.getBaseLanguage())); - ContainerUtil.addIfNotNull(suppressors, elementLanguageSuppressor); + ContainerUtil.addAllNotNull(suppressors, LanguageInspectionSuppressors.INSTANCE.allForLanguage(viewProvider.getBaseLanguage())); + ContainerUtil.addAllNotNull(suppressors, elementLanguageSuppressor); return suppressors; } - return elementLanguageSuppressor != null - ? Collections.singleton(elementLanguageSuppressor) - : Collections.emptySet(); + int size = elementLanguageSuppressor.size(); + switch (size) { + case 0: + return Collections.emptySet(); + case 1: + return Collections.singleton(elementLanguageSuppressor.get(0)); + default: + return new java.util.HashSet<>(elementLanguageSuppressor); + } } public void cleanup(@NotNull Project project) { From 6763fb7787e7c701818f6633e1d6994bfdd63573 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Tue, 11 Apr 2017 18:07:01 +0300 Subject: [PATCH 36/66] [groovy] do not check result validity in isReferenceTo() (IDEA-170936) --- .../expressions/GrReferenceExpressionImpl.java | 1 - .../groovy/lang/highlighting/GrUnusedDefTest.groovy | 10 +++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java index 1751b38a178f..4b32321da153 100644 --- a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrReferenceExpressionImpl.java @@ -527,7 +527,6 @@ public class GrReferenceExpressionImpl extends GrReferenceElementImplf2(String foo, int mode) { def abc ''') } + + void 'test method referenced via incapplicable call is used'() { + testHighlighting '''\ +static boolean fsdasdfsgsdsfadfgs(a, b) { a == b } +def bar() { fsdasdfsgsdsfadfgs("s") } +bar() +''' + } } From 8f9833297ae8a77668ea66514f72baedde9efddf Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Tue, 11 Apr 2017 16:01:47 +0300 Subject: [PATCH 37/66] cleanup: use WriteAction --- .../ui/breakpoints/BreakpointManager.java | 10 +++--- .../breakpoints/JavaFieldBreakpointType.java | 6 ++-- .../JavaWildcardMethodBreakpointType.java | 7 ++-- .../xdebugger/impl/XDebuggerUtilImpl.java | 4 +-- .../impl/breakpoints/XLineBreakpointImpl.java | 7 ++-- .../breakpoints/XLineBreakpointManager.java | 11 +++---- .../UpdateBreakpointsAfterRenameTest.java | 13 +++----- .../intellij/xdebugger/XDebuggerTestCase.java | 33 +++++++------------ .../intellij/xdebugger/XDebuggerTestUtil.java | 7 ++-- 9 files changed, 39 insertions(+), 59 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java index 11d828cffe49..e260a8b6d000 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/BreakpointManager.java @@ -32,6 +32,7 @@ import com.intellij.debugger.impl.DebuggerSession; import com.intellij.debugger.ui.JavaDebuggerSupport; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ReadAction; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; @@ -42,7 +43,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.util.Comparing; -import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; @@ -247,7 +247,7 @@ public class BreakpointManager { public ExceptionBreakpoint addExceptionBreakpoint(@NotNull final String exceptionClassName, final String packageName) { ApplicationManager.getApplication().assertIsDispatchThread(); final JavaExceptionBreakpointType type = XDebuggerUtil.getInstance().findBreakpointType(JavaExceptionBreakpointType.class); - return ApplicationManager.getApplication().runWriteAction((Computable)() -> { + return WriteAction.compute(() -> { XBreakpoint xBreakpoint = XDebuggerManager.getInstance(myProject).getBreakpointManager() .addBreakpoint(type, new JavaExceptionBreakpointProperties(exceptionClassName, packageName)); Breakpoint javaBreakpoint = getJavaBreakpoint(xBreakpoint); @@ -279,7 +279,7 @@ public class BreakpointManager { private > XLineBreakpoint addXLineBreakpoint(Class> typeCls, Document document, final int lineIndex) { final XBreakpointType type = XDebuggerUtil.getInstance().findBreakpointType(typeCls); final VirtualFile file = FileDocumentManager.getInstance().getFile(document); - return ApplicationManager.getApplication().runWriteAction((Computable)() -> XDebuggerManager.getInstance(myProject).getBreakpointManager() + return WriteAction.compute(() -> XDebuggerManager.getInstance(myProject).getBreakpointManager() .addLineBreakpoint((XLineBreakpointType)type, file.getUrl(), lineIndex, ((XLineBreakpointType)type).createBreakpointProperties(file, lineIndex))); } @@ -443,7 +443,7 @@ public class BreakpointManager { private > XBreakpoint createXBreakpoint(Class> typeCls) { final XBreakpointType type = XDebuggerUtil.getInstance().findBreakpointType(typeCls); - return ApplicationManager.getApplication().runWriteAction((Computable)() -> XDebuggerManager.getInstance(myProject).getBreakpointManager().addBreakpoint((XBreakpointType)type, type.createProperties())); + return WriteAction.compute(() -> XDebuggerManager.getInstance(myProject).getBreakpointManager().addBreakpoint((XBreakpointType)type, type.createProperties())); } private > XLineBreakpoint createXLineBreakpoint(Class> typeCls, @@ -479,7 +479,7 @@ public class BreakpointManager { if (breakpoint == null) { return; } - ApplicationManager.getApplication().runWriteAction(() -> getXBreakpointManager().removeBreakpoint(breakpoint.myXBreakpoint)); + WriteAction.run(() -> getXBreakpointManager().removeBreakpoint(breakpoint.myXBreakpoint)); } public void writeExternal(@NotNull final Element parentNode) { diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaFieldBreakpointType.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaFieldBreakpointType.java index d40bc8023c8c..410a8221b751 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaFieldBreakpointType.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaFieldBreakpointType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ import com.intellij.CommonBundle; import com.intellij.debugger.DebuggerBundle; import com.intellij.debugger.HelpID; import com.intellij.icons.AllIcons; -import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.editor.Document; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; @@ -146,7 +146,7 @@ public class JavaFieldBreakpointType extends JavaLineBreakpointTypeBase { + WriteAction.run(() -> { XLineBreakpoint fieldBreakpoint = XDebuggerManager.getInstance(project).getBreakpointManager() .addLineBreakpoint(JavaFieldBreakpointType.this, psiFile.getVirtualFile().getUrl(), line, new JavaFieldBreakpointProperties(fieldName, className)); result.set(fieldBreakpoint); diff --git a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaWildcardMethodBreakpointType.java b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaWildcardMethodBreakpointType.java index 990850708e55..ecab88d344bd 100644 --- a/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaWildcardMethodBreakpointType.java +++ b/java/debugger/impl/src/com/intellij/debugger/ui/breakpoints/JavaWildcardMethodBreakpointType.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,8 @@ package com.intellij.debugger.ui.breakpoints; import com.intellij.debugger.DebuggerBundle; import com.intellij.debugger.HelpID; import com.intellij.icons.AllIcons; -import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.registry.Registry; import com.intellij.xdebugger.XDebuggerManager; import com.intellij.xdebugger.breakpoints.XBreakpoint; @@ -104,7 +103,7 @@ public class JavaWildcardMethodBreakpointType extends JavaBreakpointTypeBase>)() -> { + return WriteAction.compute(() -> { JavaMethodBreakpointProperties properties = new JavaMethodBreakpointProperties(dialog.getClassPattern(), dialog.getMethodName()); if (Registry.is("debugger.emulate.method.breakpoints")) { properties.EMULATED = true; // create all new emulated diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerUtilImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerUtilImpl.java index daf8c9ffa048..8131a59a23a8 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerUtilImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerUtilImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -234,7 +234,7 @@ public class XDebuggerUtilImpl extends XDebuggerUtil { @Override public PopupStep onChosen(final XLineBreakpointType.XLineBreakpointVariant selectedValue, boolean finalChoice) { selectionListener.clearHighlighter(); - ApplicationManager.getApplication().runWriteAction(() -> { + WriteAction.run(() -> { P properties = (P)selectedValue.createProperties(); res.setResult(breakpointManager.addLineBreakpoint(type, file.getUrl(), line, properties, temporary)); }); diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointImpl.java index 9ca82c47ad7a..22af65ff548c 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointImpl.java @@ -17,6 +17,7 @@ package com.intellij.xdebugger.impl.breakpoints; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.colors.EditorColorsScheme; @@ -229,9 +230,9 @@ public class XLineBreakpointImpl

extends XBreak return false; } - public void remove () { - final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(getProject()).getBreakpointManager(); - ApplicationManager.getApplication().runWriteAction(() -> breakpointManager.removeBreakpoint(XLineBreakpointImpl.this)); + public void remove() { + XBreakpointManager breakpointManager = XDebuggerManager.getInstance(getProject()).getBreakpointManager(); + WriteAction.run(() -> breakpointManager.removeBreakpoint(XLineBreakpointImpl.this)); } @Override diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointManager.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointManager.java index 9a7efcaef66f..61034f0cd3ea 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointManager.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import com.intellij.ide.startup.StartupManagerEx; import com.intellij.openapi.actionSystem.IdeActions; import com.intellij.openapi.actionSystem.ex.ActionManagerEx; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; @@ -53,6 +54,7 @@ import com.intellij.util.ui.update.Update; import com.intellij.xdebugger.XDebuggerManager; import com.intellij.xdebugger.breakpoints.SuspendPolicy; import com.intellij.xdebugger.breakpoints.XBreakpoint; +import com.intellij.xdebugger.breakpoints.XBreakpointManager; import com.intellij.xdebugger.impl.XSourcePositionImpl; import com.intellij.xdebugger.impl.ui.DebuggerUIUtil; import gnu.trove.TIntHashSet; @@ -178,11 +180,8 @@ public class XLineBreakpointManager { return; } - ApplicationManager.getApplication().runWriteAction(() -> { - for (XBreakpoint breakpoint : toRemove) { - XDebuggerManager.getInstance(myProject).getBreakpointManager().removeBreakpoint(breakpoint); - } - }); + XBreakpointManager manager = XDebuggerManager.getInstance(myProject).getBreakpointManager(); + WriteAction.run(() -> toRemove.forEach(manager::removeBreakpoint)); } public void breakpointChanged(final XLineBreakpointImpl breakpoint) { diff --git a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/UpdateBreakpointsAfterRenameTest.java b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/UpdateBreakpointsAfterRenameTest.java index ff1155baa609..30e0a1e2b09d 100644 --- a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/UpdateBreakpointsAfterRenameTest.java +++ b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/UpdateBreakpointsAfterRenameTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,7 @@ */ package com.intellij.xdebugger; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.util.Computable; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; @@ -53,12 +52,8 @@ public class UpdateBreakpointsAfterRenameTest extends XBreakpointsTestCase { } private XLineBreakpoint putBreakpoint(final VirtualFile file) { - return ApplicationManager.getApplication().runWriteAction(new Computable>() { - @Override - public XLineBreakpoint compute() { - return getBreakpointManager().addLineBreakpoint(XDebuggerTestCase.MY_LINE_BREAKPOINT_TYPE, file.getUrl(), 0, null, false); - } - }); + return WriteAction.compute(() -> getBreakpointManager() + .addLineBreakpoint(XDebuggerTestCase.MY_LINE_BREAKPOINT_TYPE, file.getUrl(), 0, null, false)); } private VirtualFile createFile(String path) { diff --git a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestCase.java b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestCase.java index 4b296b069d95..d9dde6d1b4ef 100644 --- a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestCase.java +++ b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ package com.intellij.xdebugger; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.extensions.ExtensionPoint; import com.intellij.openapi.extensions.Extensions; -import com.intellij.openapi.util.Computable; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.PlatformTestCase; import com.intellij.util.xmlb.annotations.Attribute; @@ -34,31 +34,20 @@ public abstract class XDebuggerTestCase extends PlatformTestCase { protected static final MySimpleBreakpointType MY_SIMPLE_BREAKPOINT_TYPE = new MySimpleBreakpointType(); @NotNull - static XBreakpoint addBreakpoint(final XBreakpointManagerImpl breakpointManager, - final MyBreakpointProperties abc) { - return ApplicationManager.getApplication().runWriteAction(new Computable>() { - @Override - public XBreakpoint compute() { - return breakpointManager.addBreakpoint(MY_SIMPLE_BREAKPOINT_TYPE, abc); - } - }); + static XBreakpoint addBreakpoint(XBreakpointManagerImpl breakpointManager, MyBreakpointProperties abc) { + return WriteAction.compute(() -> breakpointManager.addBreakpoint(MY_SIMPLE_BREAKPOINT_TYPE, abc)); } @NotNull - static XLineBreakpoint addLineBreakpoint(final XBreakpointManagerImpl breakpointManager, final String url, - final int line, - final MyBreakpointProperties properties) { - return ApplicationManager.getApplication().runWriteAction(new Computable>() { - @Override - public XLineBreakpoint compute() { - return breakpointManager.addLineBreakpoint(MY_LINE_BREAKPOINT_TYPE, url, line, properties); - } - }); + static XLineBreakpoint addLineBreakpoint(XBreakpointManagerImpl breakpointManager, + String url, + int line, + MyBreakpointProperties properties) { + return WriteAction.compute(() -> breakpointManager.addLineBreakpoint(MY_LINE_BREAKPOINT_TYPE, url, line, properties)); } - static void removeBreakPoint(final XBreakpointManagerImpl breakpointManager, - final XBreakpoint breakpoint) { - ApplicationManager.getApplication().runWriteAction(() -> breakpointManager.removeBreakpoint(breakpoint)); + static void removeBreakPoint(XBreakpointManagerImpl breakpointManager, XBreakpoint breakpoint) { + WriteAction.run(() -> breakpointManager.removeBreakpoint(breakpoint)); } @Override diff --git a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestUtil.java b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestUtil.java index a658d3c23c82..ee22b4bd7ade 100644 --- a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestUtil.java +++ b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -207,10 +207,7 @@ public class XDebuggerTestUtil { s.down(); ApplicationManager.getApplication().invokeLater(() -> s.up()); s.waitForUnsafe(); - UIUtil.invokeAndWaitIfNeeded(new Runnable() { - public void run() { - } - }); + UIUtil.invokeAndWaitIfNeeded((Runnable)() -> {}); } @NotNull From bf81fafdcfa200537b4c6a8883c0c01f8dcea865 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 11 Apr 2017 14:30:58 +0200 Subject: [PATCH 38/66] convert RunConfigurableTest to kotlin --- .../execution/impl/RunConfigurableTest.java | 1296 ++++++++--------- 1 file changed, 639 insertions(+), 657 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.java b/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.java index 3a7065e091d2..f41ec09326d2 100644 --- a/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.java +++ b/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.java @@ -13,210 +13,192 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.intellij.execution.impl; +package com.intellij.execution.impl -import com.intellij.execution.application.ApplicationConfigurationType; -import com.intellij.execution.configurations.ConfigurationType; -import com.intellij.execution.junit.JUnitConfigurationType; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Trinity; -import com.intellij.testFramework.LightIdeaTestCase; -import com.intellij.ui.RowsDnDSupport; -import com.intellij.ui.treeStructure.Tree; -import com.intellij.util.JdomKt; -import org.jdom.Element; +import com.intellij.execution.application.ApplicationConfigurationType +import com.intellij.execution.configurations.ConfigurationType +import com.intellij.execution.junit.JUnitConfigurationType +import com.intellij.openapi.project.Project +import com.intellij.openapi.util.Trinity +import com.intellij.testFramework.LightIdeaTestCase +import com.intellij.ui.RowsDnDSupport +import com.intellij.ui.treeStructure.Tree +import com.intellij.util.* +import org.jdom.Element -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.TreePath; -import java.util.ArrayList; -import java.util.List; +import javax.swing.tree.DefaultMutableTreeNode +import javax.swing.tree.TreePath +import java.util.ArrayList -import static com.intellij.execution.impl.RunConfigurable.NodeKind.*; -import static com.intellij.ui.RowsDnDSupport.RefinedDropSupport.Position.*; +import com.intellij.execution.impl.RunConfigurable.NodeKind.* +import com.intellij.testFramework.assertions.Assertions.assertThat +import com.intellij.ui.RowsDnDSupport.RefinedDropSupport.Position.* -/** - * User: Vassiliy.Kudryashov - */ -public class RunConfigurableTest extends LightIdeaTestCase { - private static final RunConfigurable.NodeKind[] ORDER = { - CONFIGURATION_TYPE,//Application - FOLDER,//1 - CONFIGURATION, CONFIGURATION, CONFIGURATION, CONFIGURATION, CONFIGURATION, - TEMPORARY_CONFIGURATION, TEMPORARY_CONFIGURATION, - FOLDER,//2 - TEMPORARY_CONFIGURATION, - FOLDER,//3 - CONFIGURATION, - TEMPORARY_CONFIGURATION, - CONFIGURATION_TYPE,//JUnit - FOLDER,//4 - CONFIGURATION, CONFIGURATION, - FOLDER,//5 - CONFIGURATION, CONFIGURATION, - TEMPORARY_CONFIGURATION, - UNKNOWN//Defaults - }; - private MockRunConfigurable myConfigurable; - private Tree myTree; - private DefaultMutableTreeNode myRoot; - private RunConfigurable.MyTreeModel myModel; +private val ORDER = arrayOf(CONFIGURATION_TYPE, //Application + FOLDER, //1 + CONFIGURATION, CONFIGURATION, CONFIGURATION, CONFIGURATION, CONFIGURATION, TEMPORARY_CONFIGURATION, TEMPORARY_CONFIGURATION, FOLDER, //2 + TEMPORARY_CONFIGURATION, FOLDER, //3 + CONFIGURATION, TEMPORARY_CONFIGURATION, CONFIGURATION_TYPE, //JUnit + FOLDER, //4 + CONFIGURATION, CONFIGURATION, FOLDER, //5 + CONFIGURATION, CONFIGURATION, TEMPORARY_CONFIGURATION, UNKNOWN//Defaults +) - @Override - protected void setUp() throws Exception { - super.setUp(); - myConfigurable = new MockRunConfigurable(createRunManager(JdomKt.loadElement(FOLDERS_CONFIGURATION))); - myTree = myConfigurable.myTree; - myRoot = myConfigurable.myRoot; - myModel = myConfigurable.myTreeModel; +private fun createRunManager(element: Element): RunManagerImpl { + val project = LightPlatformTestCase.getProject() + val runManager = RunManagerImpl(project) + runManager.initializeConfigurationTypes(arrayOf(ApplicationConfigurationType.getInstance(), JUnitConfigurationType.getInstance())) + runManager.loadState(element) + return runManager +} + +class RunConfigurableTest : LightIdeaTestCase() { + private var myConfigurable: MockRunConfigurable? = null + private var myTree: Tree? = null + private var myRoot: DefaultMutableTreeNode? = null + private var myModel: RunConfigurable.MyTreeModel? = null + + protected override fun setUp() { + super.setUp() + myConfigurable = MockRunConfigurable(createRunManager(loadElement(FOLDERS_CONFIGURATION))) + myTree = myConfigurable!!.myTree + myRoot = myConfigurable!!.myRoot + myModel = myConfigurable!!.myTreeModel } - @Override - protected void tearDown() throws Exception { + protected override fun tearDown() { try { - if (myConfigurable != null) myConfigurable.disposeUIResources(); - myConfigurable = null; - myTree = null; - myRoot = null; - myModel = null; + if (myConfigurable != null) { + myConfigurable!!.disposeUIResources() + } + myConfigurable = null + myTree = null + myRoot = null + myModel = null } finally { - super.tearDown(); + super.tearDown() } } - public void testDND() throws Exception { - doExpand(); - int[] never = {-1, 0, 14, 22, 23, 999}; - for (int i = -1; i < 17; i++) { - for (int j : never) { + fun testDND() { + doExpand() + val never = intArrayOf(-1, 0, 14, 22, 23, 999) + for (i in -1..16) { + for (j in never) { if ((j == 14 || j == 21) && i == j) { - continue; + continue } - assertCannot(j,i,ABOVE); - assertCannot(j,i,INTO); - assertCannot(j,i,BELOW); + assertCannot(j, i, ABOVE) + assertCannot(j, i, INTO) + assertCannot(j, i, BELOW) } } - assertCan(3, 3, BELOW); - assertCan(3, 3, ABOVE); - assertCannot(3, 2, BELOW); - assertCan(3, 2, ABOVE); - assertCannot(3, 1, BELOW); - assertCannot(3, 0, BELOW); - assertCan(2, 14, ABOVE); - assertCan(1, 14, ABOVE); - assertCan(1, 11, ABOVE); - assertCannot(1, 10, ABOVE); - assertCannot(1, 10, BELOW); - assertCannot(8, 6, ABOVE); - assertCan(8, 6, BELOW); - assertCannot(5, 7, BELOW); - assertCan(5, 7, ABOVE); - assertCannot(15, 11, INTO); - assertCannot(18, 21, ABOVE); - assertCan(15, 21, ABOVE); + assertCan(3, 3, BELOW) + assertCan(3, 3, ABOVE) + assertCannot(3, 2, BELOW) + assertCan(3, 2, ABOVE) + assertCannot(3, 1, BELOW) + assertCannot(3, 0, BELOW) + assertCan(2, 14, ABOVE) + assertCan(1, 14, ABOVE) + assertCan(1, 11, ABOVE) + assertCannot(1, 10, ABOVE) + assertCannot(1, 10, BELOW) + assertCannot(8, 6, ABOVE) + assertCan(8, 6, BELOW) + assertCannot(5, 7, BELOW) + assertCan(5, 7, ABOVE) + assertCannot(15, 11, INTO) + assertCannot(18, 21, ABOVE) + assertCan(15, 21, ABOVE) - assertTrue(myModel.isDropInto(myTree, 2, 9)); - assertTrue(myModel.isDropInto(myTree, 2, 1)); - assertTrue(myModel.isDropInto(myTree, 12, 9)); - assertTrue(myModel.isDropInto(myTree, 12, 1)); - assertFalse(myModel.isDropInto(myTree, 999, 9)); - assertFalse(myModel.isDropInto(myTree, 999, 1)); - assertFalse(myModel.isDropInto(myTree, 2, 999)); - assertFalse(myModel.isDropInto(myTree, 2, -1)); + assertThat(myModel!!.isDropInto(myTree, 2, 9)).isTrue() + assertThat(myModel!!.isDropInto(myTree, 2, 1)).isTrue() + assertThat(myModel!!.isDropInto(myTree, 12, 9)).isTrue() + assertThat(myModel!!.isDropInto(myTree, 12, 1)).isTrue() + TestCase.assertFalse(myModel!!.isDropInto(myTree, 999, 9)) + TestCase.assertFalse(myModel!!.isDropInto(myTree, 999, 1)) + TestCase.assertFalse(myModel!!.isDropInto(myTree, 2, 999)) + TestCase.assertFalse(myModel!!.isDropInto(myTree, 2, -1)) } - private void doExpand() { - List toExpand = new ArrayList<>(); - RunConfigurable.collectNodesRecursively(myRoot, toExpand, FOLDER); - assertEquals(5, toExpand.size()); - List toExpand2 = new ArrayList<>(); - RunConfigurable.collectNodesRecursively(myRoot, toExpand2, CONFIGURATION_TYPE); - toExpand.addAll(toExpand2); - for (DefaultMutableTreeNode node : toExpand) { - myTree.expandPath(new TreePath(node.getPath())); + private fun doExpand() { + val toExpand = ArrayList() + RunConfigurable.collectNodesRecursively(myRoot, toExpand, FOLDER) + assertThat(toExpand).hasSize(5) + val toExpand2 = ArrayList() + RunConfigurable.collectNodesRecursively(myRoot, toExpand2, CONFIGURATION_TYPE) + toExpand.addAll(toExpand2) + for (node in toExpand) { + myTree!!.expandPath(TreePath(node.getPath())) } - for (int i = 0; i < ORDER.length; i++) { - DefaultMutableTreeNode node = (DefaultMutableTreeNode)myTree.getPathForRow(i).getLastPathComponent(); - assertEquals("Row #" + i, RunConfigurable.getKind(node), ORDER[i]); + + for (i in ORDER.indices) { + val node = myTree!!.getPathForRow(i).getLastPathComponent() as DefaultMutableTreeNode + TestCase.assertEquals("Row #" + i, RunConfigurable.getKind(node), ORDER[i]) } } - private void assertCan(int oldIndex, int newIndex, RowsDnDSupport.RefinedDropSupport.Position position) { - assertDrop(oldIndex, newIndex, position, true); + private fun assertCan(oldIndex: Int, newIndex: Int, position: RowsDnDSupport.RefinedDropSupport.Position) { + assertDrop(oldIndex, newIndex, position, true) } - private void assertCannot(int oldIndex, int newIndex, RowsDnDSupport.RefinedDropSupport.Position position) { - assertDrop(oldIndex, newIndex, position, false); + private fun assertCannot(oldIndex: Int, newIndex: Int, position: RowsDnDSupport.RefinedDropSupport.Position) { + assertDrop(oldIndex, newIndex, position, false) } - private void assertDrop(int oldIndex, int newIndex, RowsDnDSupport.RefinedDropSupport.Position position, boolean canDrop) { - StringBuilder message = new StringBuilder(); - message.append("(").append(oldIndex).append(")").append(myTree.getPathForRow(oldIndex)).append("->"); - message.append("(").append(newIndex).append(")").append(myTree.getPathForRow(newIndex)).append(position); + private fun assertDrop(oldIndex: Int, newIndex: Int, position: RowsDnDSupport.RefinedDropSupport.Position, canDrop: Boolean) { + val message = StringBuilder() + message.append("(").append(oldIndex).append(")").append(myTree!!.getPathForRow(oldIndex)).append("->") + message.append("(").append(newIndex).append(")").append(myTree!!.getPathForRow(newIndex)).append(position) if (canDrop) { - assertTrue(message.toString(), myModel.canDrop(oldIndex, newIndex, position)); + TestCase.assertTrue(message.toString(), myModel!!.canDrop(oldIndex, newIndex, position)) } else { - assertFalse(message.toString(), myModel.canDrop(oldIndex, newIndex, position)); + TestCase.assertFalse(message.toString(), myModel!!.canDrop(oldIndex, newIndex, position)) } } - public void testMoveUpDown() { - doExpand(); - checkPositionToMove(0, 1, null); - checkPositionToMove(2, 1, Trinity.create(2, 3, BELOW)); - checkPositionToMove(2, -1, null); - checkPositionToMove(14, 1, null); - checkPositionToMove(14, -1, null); - checkPositionToMove(15, -1, null); - checkPositionToMove(16, -1, null); - checkPositionToMove(3, -1, Trinity.create(3, 2, ABOVE)); - checkPositionToMove(6, 1, Trinity.create(6, 9, BELOW)); - checkPositionToMove(7, 1, Trinity.create(7, 8, BELOW)); - checkPositionToMove(10, -1, Trinity.create(10, 8, BELOW)); - checkPositionToMove(8, 1, Trinity.create(8, 9, BELOW)); - checkPositionToMove(21, -1, Trinity.create(21, 20, BELOW)); - checkPositionToMove(21, 1, null); - checkPositionToMove(20, 1, Trinity.create(20, 21, ABOVE)); - checkPositionToMove(20, -1, Trinity.create(20, 19, ABOVE)); - checkPositionToMove(19, 1, Trinity.create(19, 20, BELOW)); - checkPositionToMove(19, -1, Trinity.create(19, 17, BELOW)); - checkPositionToMove(17, -1, Trinity.create(17, 16, ABOVE)); - checkPositionToMove(17, 1, Trinity.create(17, 18, BELOW)); + fun testMoveUpDown() { + doExpand() + checkPositionToMove(0, 1, null) + checkPositionToMove(2, 1, Trinity.create(2, 3, BELOW)) + checkPositionToMove(2, -1, null) + checkPositionToMove(14, 1, null) + checkPositionToMove(14, -1, null) + checkPositionToMove(15, -1, null) + checkPositionToMove(16, -1, null) + checkPositionToMove(3, -1, Trinity.create(3, 2, ABOVE)) + checkPositionToMove(6, 1, Trinity.create(6, 9, BELOW)) + checkPositionToMove(7, 1, Trinity.create(7, 8, BELOW)) + checkPositionToMove(10, -1, Trinity.create(10, 8, BELOW)) + checkPositionToMove(8, 1, Trinity.create(8, 9, BELOW)) + checkPositionToMove(21, -1, Trinity.create(21, 20, BELOW)) + checkPositionToMove(21, 1, null) + checkPositionToMove(20, 1, Trinity.create(20, 21, ABOVE)) + checkPositionToMove(20, -1, Trinity.create(20, 19, ABOVE)) + checkPositionToMove(19, 1, Trinity.create(19, 20, BELOW)) + checkPositionToMove(19, -1, Trinity.create(19, 17, BELOW)) + checkPositionToMove(17, -1, Trinity.create(17, 16, ABOVE)) + checkPositionToMove(17, 1, Trinity.create(17, 18, BELOW)) } - private void checkPositionToMove(int selectedRow, - int direction, - Trinity expected) { - myTree.setSelectionRow(selectedRow); - assertEquals(expected, myConfigurable.getAvailableDropPosition(direction)); + private fun checkPositionToMove(selectedRow: Int, direction: Int, expected: Trinity?) { + myTree!!.setSelectionRow(selectedRow) + TestCase.assertEquals(expected, myConfigurable!!.getAvailableDropPosition(direction)) + } +} + +private class MockRunConfigurable(private val testManager: RunManagerImpl) : RunConfigurable(LightPlatformTestCase.getProject()) { + init { + createComponent() } - private static RunManagerImpl createRunManager(Element element) { - Project project = getProject(); - RunManagerImpl runManager = new RunManagerImpl(project); - runManager.initializeConfigurationTypes(new ConfigurationType[]{ApplicationConfigurationType.getInstance(), JUnitConfigurationType.getInstance()}); - runManager.loadState(element); - return runManager; - } + internal override fun getRunManager() = testManager +} - private static class MockRunConfigurable extends RunConfigurable { - private final RunManagerImpl myTestManager; - - private MockRunConfigurable(RunManagerImpl runManager) { - super(getProject()); - myTestManager = runManager; - createComponent(); - } - - @Override - RunManagerImpl getRunManager() { - return myTestManager; - } - } - - /* +/* 00 Application 01 1 02 CodeGenerator @@ -240,495 +222,495 @@ public class RunConfigurableTest extends LightIdeaTestCase { 20 All in titled4 21 All in titled5 16 Defaults - ... - */ - private static final String FOLDERS_CONFIGURATION = " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " localhost\n" + - " 5050\n" + - " \n" + - " \n"; -} + ... + */ +private val FOLDERS_CONFIGURATION = " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " localhost\n" + + " 5050\n" + + " \n" + + " \n" + From ca1c3e9955a929ac2475703dcf1e486e2a9801e6 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 11 Apr 2017 14:31:20 +0200 Subject: [PATCH 39/66] convert RunConfigurableTest to kotlin --- .../execution/impl/RunConfigurableTest.java | 716 ------------------ .../execution/impl/RunConfigurableTest.kt | 194 +++++ .../com/intellij/execution/impl/folders.xml | 489 ++++++++++++ 3 files changed, 683 insertions(+), 716 deletions(-) delete mode 100644 java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.java create mode 100644 java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.kt create mode 100644 java/java-tests/testSrc/com/intellij/execution/impl/folders.xml diff --git a/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.java b/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.java deleted file mode 100644 index f41ec09326d2..000000000000 --- a/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.java +++ /dev/null @@ -1,716 +0,0 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.execution.impl - -import com.intellij.execution.application.ApplicationConfigurationType -import com.intellij.execution.configurations.ConfigurationType -import com.intellij.execution.junit.JUnitConfigurationType -import com.intellij.openapi.project.Project -import com.intellij.openapi.util.Trinity -import com.intellij.testFramework.LightIdeaTestCase -import com.intellij.ui.RowsDnDSupport -import com.intellij.ui.treeStructure.Tree -import com.intellij.util.* -import org.jdom.Element - -import javax.swing.tree.DefaultMutableTreeNode -import javax.swing.tree.TreePath -import java.util.ArrayList - -import com.intellij.execution.impl.RunConfigurable.NodeKind.* -import com.intellij.testFramework.assertions.Assertions.assertThat -import com.intellij.ui.RowsDnDSupport.RefinedDropSupport.Position.* - -private val ORDER = arrayOf(CONFIGURATION_TYPE, //Application - FOLDER, //1 - CONFIGURATION, CONFIGURATION, CONFIGURATION, CONFIGURATION, CONFIGURATION, TEMPORARY_CONFIGURATION, TEMPORARY_CONFIGURATION, FOLDER, //2 - TEMPORARY_CONFIGURATION, FOLDER, //3 - CONFIGURATION, TEMPORARY_CONFIGURATION, CONFIGURATION_TYPE, //JUnit - FOLDER, //4 - CONFIGURATION, CONFIGURATION, FOLDER, //5 - CONFIGURATION, CONFIGURATION, TEMPORARY_CONFIGURATION, UNKNOWN//Defaults -) - -private fun createRunManager(element: Element): RunManagerImpl { - val project = LightPlatformTestCase.getProject() - val runManager = RunManagerImpl(project) - runManager.initializeConfigurationTypes(arrayOf(ApplicationConfigurationType.getInstance(), JUnitConfigurationType.getInstance())) - runManager.loadState(element) - return runManager -} - -class RunConfigurableTest : LightIdeaTestCase() { - private var myConfigurable: MockRunConfigurable? = null - private var myTree: Tree? = null - private var myRoot: DefaultMutableTreeNode? = null - private var myModel: RunConfigurable.MyTreeModel? = null - - protected override fun setUp() { - super.setUp() - myConfigurable = MockRunConfigurable(createRunManager(loadElement(FOLDERS_CONFIGURATION))) - myTree = myConfigurable!!.myTree - myRoot = myConfigurable!!.myRoot - myModel = myConfigurable!!.myTreeModel - } - - protected override fun tearDown() { - try { - if (myConfigurable != null) { - myConfigurable!!.disposeUIResources() - } - myConfigurable = null - myTree = null - myRoot = null - myModel = null - } - finally { - super.tearDown() - } - } - - fun testDND() { - doExpand() - val never = intArrayOf(-1, 0, 14, 22, 23, 999) - for (i in -1..16) { - for (j in never) { - if ((j == 14 || j == 21) && i == j) { - continue - } - assertCannot(j, i, ABOVE) - assertCannot(j, i, INTO) - assertCannot(j, i, BELOW) - } - } - assertCan(3, 3, BELOW) - assertCan(3, 3, ABOVE) - assertCannot(3, 2, BELOW) - assertCan(3, 2, ABOVE) - assertCannot(3, 1, BELOW) - assertCannot(3, 0, BELOW) - assertCan(2, 14, ABOVE) - assertCan(1, 14, ABOVE) - assertCan(1, 11, ABOVE) - assertCannot(1, 10, ABOVE) - assertCannot(1, 10, BELOW) - assertCannot(8, 6, ABOVE) - assertCan(8, 6, BELOW) - assertCannot(5, 7, BELOW) - assertCan(5, 7, ABOVE) - assertCannot(15, 11, INTO) - assertCannot(18, 21, ABOVE) - assertCan(15, 21, ABOVE) - - assertThat(myModel!!.isDropInto(myTree, 2, 9)).isTrue() - assertThat(myModel!!.isDropInto(myTree, 2, 1)).isTrue() - assertThat(myModel!!.isDropInto(myTree, 12, 9)).isTrue() - assertThat(myModel!!.isDropInto(myTree, 12, 1)).isTrue() - TestCase.assertFalse(myModel!!.isDropInto(myTree, 999, 9)) - TestCase.assertFalse(myModel!!.isDropInto(myTree, 999, 1)) - TestCase.assertFalse(myModel!!.isDropInto(myTree, 2, 999)) - TestCase.assertFalse(myModel!!.isDropInto(myTree, 2, -1)) - } - - private fun doExpand() { - val toExpand = ArrayList() - RunConfigurable.collectNodesRecursively(myRoot, toExpand, FOLDER) - assertThat(toExpand).hasSize(5) - val toExpand2 = ArrayList() - RunConfigurable.collectNodesRecursively(myRoot, toExpand2, CONFIGURATION_TYPE) - toExpand.addAll(toExpand2) - for (node in toExpand) { - myTree!!.expandPath(TreePath(node.getPath())) - } - - for (i in ORDER.indices) { - val node = myTree!!.getPathForRow(i).getLastPathComponent() as DefaultMutableTreeNode - TestCase.assertEquals("Row #" + i, RunConfigurable.getKind(node), ORDER[i]) - } - } - - private fun assertCan(oldIndex: Int, newIndex: Int, position: RowsDnDSupport.RefinedDropSupport.Position) { - assertDrop(oldIndex, newIndex, position, true) - } - - private fun assertCannot(oldIndex: Int, newIndex: Int, position: RowsDnDSupport.RefinedDropSupport.Position) { - assertDrop(oldIndex, newIndex, position, false) - } - - private fun assertDrop(oldIndex: Int, newIndex: Int, position: RowsDnDSupport.RefinedDropSupport.Position, canDrop: Boolean) { - val message = StringBuilder() - message.append("(").append(oldIndex).append(")").append(myTree!!.getPathForRow(oldIndex)).append("->") - message.append("(").append(newIndex).append(")").append(myTree!!.getPathForRow(newIndex)).append(position) - if (canDrop) { - TestCase.assertTrue(message.toString(), myModel!!.canDrop(oldIndex, newIndex, position)) - } - else { - TestCase.assertFalse(message.toString(), myModel!!.canDrop(oldIndex, newIndex, position)) - } - } - - fun testMoveUpDown() { - doExpand() - checkPositionToMove(0, 1, null) - checkPositionToMove(2, 1, Trinity.create(2, 3, BELOW)) - checkPositionToMove(2, -1, null) - checkPositionToMove(14, 1, null) - checkPositionToMove(14, -1, null) - checkPositionToMove(15, -1, null) - checkPositionToMove(16, -1, null) - checkPositionToMove(3, -1, Trinity.create(3, 2, ABOVE)) - checkPositionToMove(6, 1, Trinity.create(6, 9, BELOW)) - checkPositionToMove(7, 1, Trinity.create(7, 8, BELOW)) - checkPositionToMove(10, -1, Trinity.create(10, 8, BELOW)) - checkPositionToMove(8, 1, Trinity.create(8, 9, BELOW)) - checkPositionToMove(21, -1, Trinity.create(21, 20, BELOW)) - checkPositionToMove(21, 1, null) - checkPositionToMove(20, 1, Trinity.create(20, 21, ABOVE)) - checkPositionToMove(20, -1, Trinity.create(20, 19, ABOVE)) - checkPositionToMove(19, 1, Trinity.create(19, 20, BELOW)) - checkPositionToMove(19, -1, Trinity.create(19, 17, BELOW)) - checkPositionToMove(17, -1, Trinity.create(17, 16, ABOVE)) - checkPositionToMove(17, 1, Trinity.create(17, 18, BELOW)) - } - - private fun checkPositionToMove(selectedRow: Int, direction: Int, expected: Trinity?) { - myTree!!.setSelectionRow(selectedRow) - TestCase.assertEquals(expected, myConfigurable!!.getAvailableDropPosition(direction)) - } -} - -private class MockRunConfigurable(private val testManager: RunManagerImpl) : RunConfigurable(LightPlatformTestCase.getProject()) { - init { - createComponent() - } - - internal override fun getRunManager() = testManager -} - -/* -00 Application -01 1 -02 CodeGenerator -03 Renamer -04 UI -05 AuTest -06 Simples -07 OutAndErr (tmp) -08 C148C_TersePrincess (tmp) -09 2 -10 Periods (tmp) -11 3 -12 C148E_Porcelain -13 ErrAndOut (tmp) -14 JUnit -15 4 -16 All in titled -17 All in titled2 -18 5 -19 All in titled3 -20 All in titled4 -21 All in titled5 -16 Defaults - ... - */ -private val FOLDERS_CONFIGURATION = " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " localhost\n" + - " 5050\n" + - " \n" + - " \n" - diff --git a/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.kt b/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.kt new file mode 100644 index 000000000000..a10c98304b95 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/execution/impl/RunConfigurableTest.kt @@ -0,0 +1,194 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.execution.impl + +import com.intellij.execution.application.ApplicationConfigurationType +import com.intellij.execution.impl.RunConfigurable.NodeKind.* +import com.intellij.execution.junit.JUnitConfigurationType +import com.intellij.openapi.util.Trinity +import com.intellij.testFramework.LightIdeaTestCase +import com.intellij.testFramework.LightPlatformTestCase +import com.intellij.testFramework.assertions.Assertions.assertThat +import com.intellij.ui.RowsDnDSupport +import com.intellij.ui.RowsDnDSupport.RefinedDropSupport.Position.* +import com.intellij.ui.treeStructure.Tree +import com.intellij.util.loadElement +import org.jdom.Element +import java.util.* +import javax.swing.tree.DefaultMutableTreeNode +import javax.swing.tree.TreePath +import kotlin.properties.Delegates + +private val ORDER = arrayOf(CONFIGURATION_TYPE, //Application + FOLDER, //1 + CONFIGURATION, CONFIGURATION, CONFIGURATION, CONFIGURATION, CONFIGURATION, TEMPORARY_CONFIGURATION, TEMPORARY_CONFIGURATION, FOLDER, //2 + TEMPORARY_CONFIGURATION, FOLDER, //3 + CONFIGURATION, TEMPORARY_CONFIGURATION, CONFIGURATION_TYPE, //JUnit + FOLDER, //4 + CONFIGURATION, CONFIGURATION, FOLDER, //5 + CONFIGURATION, CONFIGURATION, TEMPORARY_CONFIGURATION, UNKNOWN//Defaults +) + +private fun createRunManager(element: Element): RunManagerImpl { + val runManager = RunManagerImpl(LightPlatformTestCase.getProject()) + runManager.initializeConfigurationTypes(arrayOf(ApplicationConfigurationType.getInstance(), JUnitConfigurationType.getInstance())) + runManager.loadState(element) + return runManager +} + +class RunConfigurableTest : LightIdeaTestCase() { + private var configurable: MockRunConfigurable? = null + private var tree: Tree by Delegates.notNull() + private var root: DefaultMutableTreeNode? = null + private var model: RunConfigurable.MyTreeModel by Delegates.notNull() + + override fun setUp() { + super.setUp() + + configurable = MockRunConfigurable(createRunManager(loadElement(RunConfigurableTest::class.java.getResourceAsStream("folders.xml")))) + tree = configurable!!.myTree + root = configurable!!.myRoot + model = configurable!!.myTreeModel + } + + override fun tearDown() { + try { + if (configurable != null) { + configurable!!.disposeUIResources() + } + configurable = null + root = null + } + finally { + super.tearDown() + } + } + + fun testDND() { + doExpand() + val never = intArrayOf(-1, 0, 14, 22, 23, 999) + for (i in -1..16) { + for (j in never) { + if ((j == 14 || j == 21) && i == j) { + continue + } + assertCannot(j, i, ABOVE) + assertCannot(j, i, INTO) + assertCannot(j, i, BELOW) + } + } + assertCan(3, 3, BELOW) + assertCan(3, 3, ABOVE) + assertCannot(3, 2, BELOW) + assertCan(3, 2, ABOVE) + assertCannot(3, 1, BELOW) + assertCannot(3, 0, BELOW) + assertCan(2, 14, ABOVE) + assertCan(1, 14, ABOVE) + assertCan(1, 11, ABOVE) + assertCannot(1, 10, ABOVE) + assertCannot(1, 10, BELOW) + assertCannot(8, 6, ABOVE) + assertCan(8, 6, BELOW) + assertCannot(5, 7, BELOW) + assertCan(5, 7, ABOVE) + assertCannot(15, 11, INTO) + assertCannot(18, 21, ABOVE) + assertCan(15, 21, ABOVE) + + assertThat(model.isDropInto(tree, 2, 9)).isTrue() + assertThat(model.isDropInto(tree, 2, 1)).isTrue() + assertThat(model.isDropInto(tree, 12, 9)).isTrue() + assertThat(model.isDropInto(tree, 12, 1)).isTrue() + assertThat(model.isDropInto(tree, 999, 9)).isFalse() + assertThat(model.isDropInto(tree, 999, 1)).isFalse() + assertThat(model.isDropInto(tree, 2, 999)).isFalse() + assertThat(model.isDropInto(tree, 2, -1)).isFalse() + } + + private fun doExpand() { + val toExpand = ArrayList() + RunConfigurable.collectNodesRecursively(root, toExpand, FOLDER) + assertThat(toExpand).hasSize(5) + val toExpand2 = ArrayList() + RunConfigurable.collectNodesRecursively(root, toExpand2, CONFIGURATION_TYPE) + toExpand.addAll(toExpand2) + for (node in toExpand) { + tree.expandPath(TreePath(node.path)) + } + + assertThat(ORDER.mapIndexed { index, nodeKind -> RunConfigurable.getKind(tree.getPathForRow(index).lastPathComponent as DefaultMutableTreeNode) }).containsExactly(*ORDER) + } + + private fun assertCan(oldIndex: Int, newIndex: Int, position: RowsDnDSupport.RefinedDropSupport.Position) { + assertDrop(oldIndex, newIndex, position, true) + } + + private fun assertCannot(oldIndex: Int, newIndex: Int, position: RowsDnDSupport.RefinedDropSupport.Position) { + assertDrop(oldIndex, newIndex, position, false) + } + + private fun assertDrop(oldIndex: Int, newIndex: Int, position: RowsDnDSupport.RefinedDropSupport.Position, canDrop: Boolean) { + val message = StringBuilder() + message.append("(").append(oldIndex).append(")").append(tree.getPathForRow(oldIndex)).append("->") + message.append("(").append(newIndex).append(")").append(tree.getPathForRow(newIndex)).append(position) + if (canDrop) { + // message.toString() + assertThat(model.canDrop(oldIndex, newIndex, position)).isTrue() + } + else { + // message.toString() + assertThat(model.canDrop(oldIndex, newIndex, position)).isFalse() + } + } + + fun testMoveUpDown() { + doExpand() + checkPositionToMove(0, 1, null) + checkPositionToMove(2, 1, Trinity.create(2, 3, BELOW)) + checkPositionToMove(2, -1, null) + checkPositionToMove(14, 1, null) + checkPositionToMove(14, -1, null) + checkPositionToMove(15, -1, null) + checkPositionToMove(16, -1, null) + checkPositionToMove(3, -1, Trinity.create(3, 2, ABOVE)) + checkPositionToMove(6, 1, Trinity.create(6, 9, BELOW)) + checkPositionToMove(7, 1, Trinity.create(7, 8, BELOW)) + checkPositionToMove(10, -1, Trinity.create(10, 8, BELOW)) + checkPositionToMove(8, 1, Trinity.create(8, 9, BELOW)) + checkPositionToMove(21, -1, Trinity.create(21, 20, BELOW)) + checkPositionToMove(21, 1, null) + checkPositionToMove(20, 1, Trinity.create(20, 21, ABOVE)) + checkPositionToMove(20, -1, Trinity.create(20, 19, ABOVE)) + checkPositionToMove(19, 1, Trinity.create(19, 20, BELOW)) + checkPositionToMove(19, -1, Trinity.create(19, 17, BELOW)) + checkPositionToMove(17, -1, Trinity.create(17, 16, ABOVE)) + checkPositionToMove(17, 1, Trinity.create(17, 18, BELOW)) + } + + private fun checkPositionToMove(selectedRow: Int, direction: Int, expected: Trinity?) { + tree.setSelectionRow(selectedRow) + assertThat(configurable!!.getAvailableDropPosition(direction)).isEqualTo(expected) + } +} + +private class MockRunConfigurable(private val testManager: RunManagerImpl) : RunConfigurable(LightPlatformTestCase.getProject()) { + init { + createComponent() + } + + internal override fun getRunManager() = testManager +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/execution/impl/folders.xml b/java/java-tests/testSrc/com/intellij/execution/impl/folders.xml new file mode 100644 index 000000000000..a32681bd5e72 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/execution/impl/folders.xml @@ -0,0 +1,489 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost + 5050 + + \ No newline at end of file From eebc123f2ad3fb98d543123c3ddb15b76d6bc500 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Tue, 11 Apr 2017 18:32:35 +0300 Subject: [PATCH 40/66] IDEA-171228 Do not auto build during rebase --- .../compiler/server/BuildManager.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java index b1b0c24ac8c5..b40ec67fb65e 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java @@ -160,8 +160,9 @@ public class BuildManager implements Disposable { private final BuildProcessClasspathManager myClasspathManager = new BuildProcessClasspathManager(); private final ExecutorService myRequestsProcessor = SequentialTaskExecutor.createSequentialApplicationPoolExecutor("BuildManager requestProcessor pool"); private final Map myProjectDataMap = Collections.synchronizedMap(new HashMap()); + private volatile int myFileChangeCounter = 0; - private final BuildManagerPeriodicTask myAutoMakeTask = new BuildManagerPeriodicTask(this) { + private final BuildManagerPeriodicTask myAutoMakeTask = new BuildManagerPeriodicTask() { @Override protected int getDelay() { return Registry.intValue("compiler.automake.trigger.delay"); @@ -173,7 +174,7 @@ public class BuildManager implements Disposable { } }; - private final BuildManagerPeriodicTask myDocumentSaveTask = new BuildManagerPeriodicTask(this) { + private final BuildManagerPeriodicTask myDocumentSaveTask = new BuildManagerPeriodicTask() { @Override protected int getDelay() { return Registry.intValue("compiler.document.save.trigger.delay"); @@ -303,8 +304,14 @@ public class BuildManager implements Disposable { conn.subscribe(BatchFileChangeListener.TOPIC, new BatchFileChangeListener.Adapter() { @Override public void batchChangeStarted(Project project) { + myFileChangeCounter++; cancelAutoMakeTasks(project); } + + @Override + public void batchChangeCompleted(Project project) { + myFileChangeCounter--; + } }); EditorFactory.getInstance().getEventMulticaster().addDocumentListener(new DocumentAdapter() { @@ -1438,7 +1445,7 @@ public class BuildManager implements Disposable { } } - private abstract static class BuildManagerPeriodicTask implements Runnable { + private abstract class BuildManagerPeriodicTask implements Runnable { private final Alarm myAlarm; private final AtomicBoolean myInProgress = new AtomicBoolean(false); private final Runnable myTaskRunnable = () -> { @@ -1450,8 +1457,8 @@ public class BuildManager implements Disposable { } }; - protected BuildManagerPeriodicTask(@NotNull Disposable disposable) { - myAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, disposable); + protected BuildManagerPeriodicTask() { + myAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, BuildManager.this); } public final void schedule() { @@ -1470,7 +1477,7 @@ public class BuildManager implements Disposable { @Override public final void run() { - if (!HeavyProcessLatch.INSTANCE.isRunning() && !myInProgress.getAndSet(true)) { + if (!HeavyProcessLatch.INSTANCE.isRunning() && myFileChangeCounter <= 0 && !myInProgress.getAndSet(true)) { try { ApplicationManager.getApplication().executeOnPooledThread(myTaskRunnable); } From fb81f545c9cc8d5fa3ebb1ddf19e699089150879 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Tue, 11 Apr 2017 18:38:14 +0300 Subject: [PATCH 41/66] remove unused code, fix missing resource problem (IDEA-170875) --- .../RepositoryLibraryPropertiesEditor.form | 4 +- .../RepositoryLibraryPropertiesEditor.form | 193 ------------------ .../utils/library/remote/MavenRemoteTask.java | 31 --- 3 files changed, 2 insertions(+), 226 deletions(-) delete mode 100644 plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/propertiesEditor/RepositoryLibraryPropertiesEditor.form delete mode 100644 plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/remote/MavenRemoteTask.java diff --git a/java/idea-ui/src/com/intellij/jarRepository/propertiesEditor/RepositoryLibraryPropertiesEditor.form b/java/idea-ui/src/com/intellij/jarRepository/propertiesEditor/RepositoryLibraryPropertiesEditor.form index 12d569c4dc71..3059e22370da 100644 --- a/java/idea-ui/src/com/intellij/jarRepository/propertiesEditor/RepositoryLibraryPropertiesEditor.form +++ b/java/idea-ui/src/com/intellij/jarRepository/propertiesEditor/RepositoryLibraryPropertiesEditor.form @@ -134,7 +134,7 @@ @@ -148,7 +148,7 @@ diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/propertiesEditor/RepositoryLibraryPropertiesEditor.form b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/propertiesEditor/RepositoryLibraryPropertiesEditor.form deleted file mode 100644 index 5903bd9cafd7..000000000000 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/propertiesEditor/RepositoryLibraryPropertiesEditor.form +++ /dev/null @@ -1,193 +0,0 @@ - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/remote/MavenRemoteTask.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/remote/MavenRemoteTask.java deleted file mode 100644 index 0585cf3caf74..000000000000 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/library/remote/MavenRemoteTask.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2000-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.idea.maven.utils.library.remote; - -import com.intellij.openapi.progress.ProgressIndicator; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public interface MavenRemoteTask { - @NotNull - Result execute(@NotNull Argument arg, ProgressIndicator indicator); - - String getName(@NotNull Argument arg); - - interface ResultProcessor { - void process(@Nullable Result result); - } -} From 0bdb4c169ab42c243e22c6de660ecfc62c15d20d Mon Sep 17 00:00:00 2001 From: Alexander Zolotov Date: Tue, 11 Apr 2017 18:43:24 +0300 Subject: [PATCH 42/66] File references: do not consider FileReferenceResolver as a real context --- .../impl/providers/FileReference.java | 22 ++++++++++++++++--- .../impl/providers/FileReferenceSet.java | 12 ++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/platform/analysis-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileReference.java b/platform/analysis-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileReference.java index fd6e9344201d..98cc641c3b6c 100644 --- a/platform/analysis-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileReference.java +++ b/platform/analysis-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileReference.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,6 +41,7 @@ import com.intellij.psi.search.PsiFileSystemItemProcessor; import com.intellij.refactoring.rename.BindablePsiReference; import com.intellij.util.ArrayUtil; import com.intellij.util.IncorrectOperationException; +import com.intellij.util.containers.ContainerUtil; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -156,9 +157,18 @@ public class FileReference implements PsiFileReference, FileReferenceOwner, PsiP final Collection result, final boolean caseSensitive) { if (isAllowedEmptyPath(text) || ".".equals(text) || "/".equals(text)) { + if (context instanceof FileReferenceResolver) { + ContainerUtil.addIfNotNull(result, resolveFileReferenceResolver((FileReferenceResolver)context, text)); + return; + } result.add(new PsiElementResolveResult(context)); } else if ("..".equals(text)) { + if (context instanceof FileReferenceResolver) { + ContainerUtil.addIfNotNull(result, resolveFileReferenceResolver((FileReferenceResolver)context, text)); + return; + } + final PsiFileSystemItem resolved = context.getParent(); if (resolved != null) { result.add(new PsiElementResolveResult(resolved)); @@ -189,9 +199,9 @@ public class FileReference implements PsiFileReference, FileReferenceOwner, PsiP context = ((PackagePrefixFileSystemItem)context).getDirectory(); } else if (context instanceof FileReferenceResolver) { - PsiFileSystemItem child = ((FileReferenceResolver)context).resolveFileReference(this, decoded); + ResolveResult child = resolveFileReferenceResolver((FileReferenceResolver)context, decoded); if (child != null) { - result.add(new PsiElementResolveResult(getOriginalFile(child))); + result.add(child); return; } } @@ -241,6 +251,12 @@ public class FileReference implements PsiFileReference, FileReferenceOwner, PsiP return null; } + @Nullable + private ResolveResult resolveFileReferenceResolver(@NotNull FileReferenceResolver fileReferenceResolver, @NotNull String text) { + PsiFileSystemItem resolve = fileReferenceResolver.resolveFileReference(this, text); + return resolve != null ? new PsiElementResolveResult(getOriginalFile(resolve)) : null; + } + private static boolean caseSensitivityApplies(PsiDirectory context, boolean caseSensitive) { VirtualFileSystem fs = context.getVirtualFile().getFileSystem(); return fs.isCaseSensitive() == caseSensitive; diff --git a/platform/analysis-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileReferenceSet.java b/platform/analysis-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileReferenceSet.java index a4100b567f25..b1b831196e50 100644 --- a/platform/analysis-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileReferenceSet.java +++ b/platform/analysis-impl/src/com/intellij/psi/impl/source/resolve/reference/impl/providers/FileReferenceSet.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -367,15 +367,23 @@ public class FileReferenceSet { final FileReferenceHelper[] helpers = FileReferenceHelperRegistrar.getHelpers(); final ArrayList list = new ArrayList<>(); final Project project = file.getProject(); + boolean hasRealContexts = false; for (FileReferenceHelper helper : helpers) { if (helper.isMine(project, virtualFile)) { if (!list.isEmpty() && helper.isFallback()) { continue; } - list.addAll(helper.getContexts(project, virtualFile)); + Collection contexts = helper.getContexts(project, virtualFile); + for (PsiFileSystemItem context : contexts) { + list.add(context); + hasRealContexts |= !(context instanceof FileReferenceResolver); + } } } if (!list.isEmpty()) { + if (!hasRealContexts) { + list.addAll(getParentDirectoryContext()); + } return list; } return getParentDirectoryContext(); From 56706c0d451ed33d59bcd19503ee18644a81a719 Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Tue, 11 Apr 2017 19:16:04 +0300 Subject: [PATCH 43/66] [groovy] don't process comment injections in compiled files (IDEA-171298) --- .../inject/groovy/GroovyLanguageInjectionSupport.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/groovy/src/org/intellij/plugins/intelliLang/inject/groovy/GroovyLanguageInjectionSupport.java b/plugins/groovy/src/org/intellij/plugins/intelliLang/inject/groovy/GroovyLanguageInjectionSupport.java index 93f63ccd1fa1..925f74d3942d 100644 --- a/plugins/groovy/src/org/intellij/plugins/intelliLang/inject/groovy/GroovyLanguageInjectionSupport.java +++ b/plugins/groovy/src/org/intellij/plugins/intelliLang/inject/groovy/GroovyLanguageInjectionSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.intellij.plugins.intelliLang.inject.groovy; import com.intellij.lang.Language; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.Ref; import com.intellij.psi.*; import com.intellij.psi.impl.light.LightElement; import com.intellij.psi.tree.IElementType; @@ -76,6 +77,14 @@ public class GroovyLanguageInjectionSupport extends AbstractLanguageInjectionSup return new Class[] {GroovyPatterns.class}; } + @Nullable + @Override + public BaseInjection findCommentInjection(@NotNull PsiElement host, @Nullable Ref commentRef) { + PsiFile containingFile = host.getContainingFile(); + boolean compiled = containingFile != null && containingFile.getOriginalFile() instanceof PsiCompiledFile; + return compiled ? null : super.findCommentInjection(host, commentRef); + } + @Override public boolean isApplicableTo(PsiLanguageInjectionHost host) { return host instanceof GroovyPsiElement; From 0c867b619bf8574767988177d65be8d69b84ca3c Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Tue, 11 Apr 2017 19:34:20 +0300 Subject: [PATCH 44/66] return icons in file chooser --- .../src/com/intellij/ide/util/treeView/NodeRenderer.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/NodeRenderer.java b/platform/platform-api/src/com/intellij/ide/util/treeView/NodeRenderer.java index e0dd778cbf36..948322443ecd 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/NodeRenderer.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/NodeRenderer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,6 +41,13 @@ public class NodeRenderer extends ColoredTreeCellRenderer { public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { Object node = TreeUtil.getUserObject(value); + if (node instanceof NodeDescriptor) { + NodeDescriptor descriptor = (NodeDescriptor)node; + // TODO: use this color somewhere + Color color = descriptor.getColor(); + setIcon(descriptor.getIcon()); + } + PresentationData presentation = node instanceof PresentableNodeDescriptor ? ((PresentableNodeDescriptor)node).getPresentation() : node instanceof NavigationItem ? ObjectUtils.tryCast(((NavigationItem)node).getPresentation(), PresentationData.class) : From 7fad69fc05da7ec035d29cce305b16c510a1233c Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 11 Apr 2017 18:38:44 +0200 Subject: [PATCH 45/66] prefer to use allSettings where we actually need to use settings or don't need configuration at all add hasSettings (later we can optimize it to avoid linear search) no need in the myUnloadedElements since for unknown element UnknownRunConfiguration will be created --- .../intellij/debugger/DebuggerTestCase.java | 8 +--- .../src/com/intellij/execution/RunManager.kt | 2 + .../RunnerAndConfigurationSettings.java | 5 +-- .../configurations/RunConfiguration.java | 6 +-- .../configurations/RunConfigurationBase.java | 6 --- .../UnknownRunConfiguration.java | 6 --- .../actions/CopyConfigurationAction.java | 3 +- .../actions/EditConfigurationAction.java | 3 +- .../actions/RemoveConfigurationAction.java | 3 +- .../dashboard/tree/RunConfigurationNode.java | 4 +- .../impl/ModuleRunConfigurationManager.java | 45 +++++-------------- .../impl/ProjectRunConfigurationManager.java | 42 ++++------------- ...ionRefactoringElementListenerProvider.java | 8 +--- .../intellij/execution/impl/RunManagerImpl.kt | 21 +++------ .../RunnerAndConfigurationSettingsImpl.kt | 10 ++--- .../templates/TemplateModuleBuilder.java | 5 +-- .../AbstractRerunFailedTestsAction.java | 4 -- 17 files changed, 45 insertions(+), 136 deletions(-) diff --git a/java/testFramework/src/com/intellij/debugger/DebuggerTestCase.java b/java/testFramework/src/com/intellij/debugger/DebuggerTestCase.java index 4833e351d2d0..ec90fa0f690f 100644 --- a/java/testFramework/src/com/intellij/debugger/DebuggerTestCase.java +++ b/java/testFramework/src/com/intellij/debugger/DebuggerTestCase.java @@ -512,7 +512,7 @@ public abstract class DebuggerTestCase extends ExecutionWithDebuggerToolsTestCas @Override public ConfigurationFactory getFactory() { - return null; + return UnknownConfigurationType.FACTORY; } @Override @@ -529,12 +529,6 @@ public abstract class DebuggerTestCase extends ExecutionWithDebuggerToolsTestCas return null; } - @Override - @NotNull - public ConfigurationType getType() { - return UnknownConfigurationType.INSTANCE; - } - @Override public RunConfiguration clone() { return null; diff --git a/platform/lang-api/src/com/intellij/execution/RunManager.kt b/platform/lang-api/src/com/intellij/execution/RunManager.kt index e3e9fe774988..2475e16d8670 100644 --- a/platform/lang-api/src/com/intellij/execution/RunManager.kt +++ b/platform/lang-api/src/com/intellij/execution/RunManager.kt @@ -176,6 +176,8 @@ abstract class RunManager { */ abstract fun refreshUsagesList(profile: RunProfile) + fun hasSettings(settings: RunnerAndConfigurationSettings) = allSettings.contains(settings) + fun suggestUniqueName(name: String?, type: ConfigurationType?): String { val settingsList = if (type == null) allSettings else getConfigurationSettingsList(type) return suggestUniqueName(name.nullize() ?: UNNAMED, settingsList.map { it.name }) diff --git a/platform/lang-api/src/com/intellij/execution/RunnerAndConfigurationSettings.java b/platform/lang-api/src/com/intellij/execution/RunnerAndConfigurationSettings.java index 8864b58aa612..555d9d1e10e9 100644 --- a/platform/lang-api/src/com/intellij/execution/RunnerAndConfigurationSettings.java +++ b/platform/lang-api/src/com/intellij/execution/RunnerAndConfigurationSettings.java @@ -31,11 +31,8 @@ import org.jetbrains.annotations.Nullable; public interface RunnerAndConfigurationSettings { /** * Returns the type of the run configuration. - * - * @return the type of the run configuration, or null if the settings object was loaded from disk and no plugin corresponding to the - * stored type of the run configuration is loaded. */ - @Nullable + @NotNull ConfigurationType getType(); /** diff --git a/platform/lang-api/src/com/intellij/execution/configurations/RunConfiguration.java b/platform/lang-api/src/com/intellij/execution/configurations/RunConfiguration.java index 4954fba83c6b..57299e47b8b6 100644 --- a/platform/lang-api/src/com/intellij/execution/configurations/RunConfiguration.java +++ b/platform/lang-api/src/com/intellij/execution/configurations/RunConfiguration.java @@ -44,11 +44,11 @@ public interface RunConfiguration extends RunProfile, Cloneable { /** * Returns the type of the run configuration. - * - * @return the configuration type. */ @NotNull - ConfigurationType getType(); + default ConfigurationType getType() { + return getFactory().getType(); + } /** * Returns the factory that has created the run configuration. diff --git a/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationBase.java b/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationBase.java index bcc8f1ac99ce..f0afd43073a5 100644 --- a/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationBase.java +++ b/platform/lang-api/src/com/intellij/execution/configurations/RunConfigurationBase.java @@ -98,12 +98,6 @@ public abstract class RunConfigurationBase extends UserDataHolderBase implements return myProject; } - @Override - @NotNull - public ConfigurationType getType() { - return myFactory.getType(); - } - @Override public Icon getIcon() { return myIcon; diff --git a/platform/lang-api/src/com/intellij/execution/configurations/UnknownRunConfiguration.java b/platform/lang-api/src/com/intellij/execution/configurations/UnknownRunConfiguration.java index 710d6038b5f9..55c9a96827c7 100644 --- a/platform/lang-api/src/com/intellij/execution/configurations/UnknownRunConfiguration.java +++ b/platform/lang-api/src/com/intellij/execution/configurations/UnknownRunConfiguration.java @@ -83,12 +83,6 @@ public class UnknownRunConfiguration implements RunConfiguration, WithoutOwnBefo return myProject; } - @Override - @NotNull - public ConfigurationType getType() { - return UnknownConfigurationType.INSTANCE; - } - @Override public RunConfiguration clone() { try { diff --git a/platform/lang-impl/src/com/intellij/execution/dashboard/actions/CopyConfigurationAction.java b/platform/lang-impl/src/com/intellij/execution/dashboard/actions/CopyConfigurationAction.java index 903b5d104349..a4a023889730 100644 --- a/platform/lang-impl/src/com/intellij/execution/dashboard/actions/CopyConfigurationAction.java +++ b/platform/lang-impl/src/com/intellij/execution/dashboard/actions/CopyConfigurationAction.java @@ -49,8 +49,7 @@ public class CopyConfigurationAction extends RunConfigurationTreeAction { @Override protected boolean isEnabled4(DashboardRunConfigurationNode node) { - return RunManager.getInstance(node.getProject()).getAllConfigurationsList().contains( - node.getConfigurationSettings().getConfiguration()); + return RunManager.getInstance(node.getProject()).hasSettings(node.getConfigurationSettings()); } @Override diff --git a/platform/lang-impl/src/com/intellij/execution/dashboard/actions/EditConfigurationAction.java b/platform/lang-impl/src/com/intellij/execution/dashboard/actions/EditConfigurationAction.java index 1622456db19a..680652cb74bf 100644 --- a/platform/lang-impl/src/com/intellij/execution/dashboard/actions/EditConfigurationAction.java +++ b/platform/lang-impl/src/com/intellij/execution/dashboard/actions/EditConfigurationAction.java @@ -41,8 +41,7 @@ public class EditConfigurationAction extends RunConfigurationTreeAction { @Override protected boolean isEnabled4(DashboardRunConfigurationNode node) { - return RunManager.getInstance(node.getProject()).getAllConfigurationsList().contains( - node.getConfigurationSettings().getConfiguration()); + return RunManager.getInstance(node.getProject()).hasSettings(node.getConfigurationSettings()); } @Override diff --git a/platform/lang-impl/src/com/intellij/execution/dashboard/actions/RemoveConfigurationAction.java b/platform/lang-impl/src/com/intellij/execution/dashboard/actions/RemoveConfigurationAction.java index d83295f0af97..3733e2f189be 100644 --- a/platform/lang-impl/src/com/intellij/execution/dashboard/actions/RemoveConfigurationAction.java +++ b/platform/lang-impl/src/com/intellij/execution/dashboard/actions/RemoveConfigurationAction.java @@ -40,8 +40,7 @@ public class RemoveConfigurationAction extends RunConfigurationTreeAction { @Override protected boolean isEnabled4(DashboardRunConfigurationNode node) { - return RunManager.getInstance(node.getProject()).getAllConfigurationsList().contains( - node.getConfigurationSettings().getConfiguration()); + return RunManager.getInstance(node.getProject()).hasSettings(node.getConfigurationSettings()); } @Override diff --git a/platform/lang-impl/src/com/intellij/execution/dashboard/tree/RunConfigurationNode.java b/platform/lang-impl/src/com/intellij/execution/dashboard/tree/RunConfigurationNode.java index e0771d60f363..666c8a90067b 100644 --- a/platform/lang-impl/src/com/intellij/execution/dashboard/tree/RunConfigurationNode.java +++ b/platform/lang-impl/src/com/intellij/execution/dashboard/tree/RunConfigurationNode.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,7 +64,7 @@ class RunConfigurationNode extends AbstractTreeNode settings != null && usesMyModule(settings.getConfiguration()); @NotNull private final RunManagerImpl myManager; - @Nullable - private List myUnloadedElements = null; public ModuleRunConfigurationManager(@NotNull final Module module, @NotNull final RunManagerImpl runManager) { myModule = module; @@ -110,11 +105,6 @@ public final class ModuleRunConfigurationManager implements PersistentStateCompo public void writeExternal(@NotNull final Element element) throws WriteExternalException { LOG.debug("writeExternal(" + myModule + ")"); myManager.writeConfigurations(element, getModuleRunConfigurationSettings()); - if (myUnloadedElements != null) { - for (final Element unloadedElement : myUnloadedElements) { - element.addContent(unloadedElement.clone()); - } - } } public void readExternal(@NotNull final Element element) { @@ -125,32 +115,21 @@ public final class ModuleRunConfigurationManager implements PersistentStateCompo private void doReadExternal(@NotNull Element element) { LOG.debug("readExternal(" + myModule + ")"); - myUnloadedElements = null; - final Set existing = new HashSet<>(); + final Set existing = new SmartHashSet<>(); - for (final Element child : element.getChildren()) { - final RunnerAndConfigurationSettings configuration = myManager.loadConfiguration(child, true); - if (configuration == null && Comparing.strEqual(element.getName(), RunManagerImpl.CONFIGURATION)) { - if (myUnloadedElements == null) myUnloadedElements = new ArrayList<>(2); - myUnloadedElements.add(element); - } - - if (configuration != null) { - existing.add(configuration.getUniqueID()); - } + for (final Element child : element.getChildren(RunManagerImpl.CONFIGURATION)) { + existing.add(myManager.loadConfiguration(child, true).getUniqueID()); } - for (final RunConfiguration configuration : myManager.getAllConfigurationsList()) { - if (!usesMyModule(configuration)) { - RunnerAndConfigurationSettings settings = myManager.getSettings(configuration); - if (settings != null) { - existing.add(settings.getUniqueID()); - } - } - } - myManager.removeNotExistingSharedConfigurations(existing); - // IDEA-60004: configs may never be sorted before write, so call it manually after shared configs read myManager.setOrdered(false); + + for (RunnerAndConfigurationSettings settings : myManager.getAllSettings()) { + if (!usesMyModule(settings.getConfiguration())) { + existing.add(settings.getUniqueID()); + } + } + + myManager.removeNotExistingSharedConfigurations(existing); } } diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ProjectRunConfigurationManager.java b/platform/lang-impl/src/com/intellij/execution/impl/ProjectRunConfigurationManager.java index ef606a5dc6a2..24eab6b74941 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ProjectRunConfigurationManager.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ProjectRunConfigurationManager.java @@ -16,27 +16,22 @@ package com.intellij.execution.impl; import com.intellij.execution.RunnerAndConfigurationSettings; -import com.intellij.execution.configurations.RunConfiguration; import com.intellij.execution.configurations.UnknownRunConfiguration; import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.State; import com.intellij.openapi.components.StateSplitterEx; import com.intellij.openapi.components.Storage; import com.intellij.openapi.util.Pair; -import com.intellij.util.SmartList; -import com.intellij.util.containers.ContainerUtil; import gnu.trove.THashSet; import org.jdom.Element; import org.jetbrains.annotations.NotNull; -import java.util.Iterator; import java.util.List; import java.util.Set; @State(name = "ProjectRunConfigurationManager", storages = @Storage(value = "runConfigurations", stateSplitter = ProjectRunConfigurationManager.RunConfigurationStateSplitter.class)) public class ProjectRunConfigurationManager implements PersistentStateComponent { private final RunManagerImpl myManager; - private List myUnloadedElements; public ProjectRunConfigurationManager(@NotNull RunManagerImpl manager) { myManager = manager; @@ -46,50 +41,29 @@ public class ProjectRunConfigurationManager implements PersistentStateComponent< public Element getState() { Element state = new Element("state"); myManager.writeConfigurations(state, myManager.getSharedConfigurations()); - if (!ContainerUtil.isEmpty(myUnloadedElements)) { - for (Element unloadedElement : myUnloadedElements) { - state.addContent(unloadedElement.clone()); - } - } return state; } @Override public void loadState(Element state) { - if (myUnloadedElements != null) { - myUnloadedElements.clear(); - } - Set existing = new THashSet<>(); - for (Iterator iterator = state.getChildren().iterator(); iterator.hasNext(); ) { - Element child = iterator.next(); - RunnerAndConfigurationSettings configuration = myManager.loadConfiguration(child, true); - if (configuration != null) { - existing.add(configuration.getUniqueID()); - } - else if (child.getName().equals(RunManagerImpl.CONFIGURATION)) { - if (myUnloadedElements == null) { - myUnloadedElements = new SmartList<>(); - } - iterator.remove(); - myUnloadedElements.add(child); - } + for (Element child : state.getChildren(RunManagerImpl.CONFIGURATION)) { + existing.add(myManager.loadConfiguration(child, true).getUniqueID()); } myManager.removeNotExistingSharedConfigurations(existing); + + // IDEA-60004: configs may never be sorted before write, so call it manually after shared configs read + myManager.setOrdered(false); + if (myManager.getSelectedConfiguration() == null) { - final List allConfigurations = myManager.getAllConfigurationsList(); - for (final RunConfiguration configuration : allConfigurations) { - final RunnerAndConfigurationSettings settings = myManager.getSettings(allConfigurations.get(0)); - if (!(configuration instanceof UnknownRunConfiguration)) { + for (RunnerAndConfigurationSettings settings : myManager.getAllSettings()) { + if (!(settings.getType() instanceof UnknownRunConfiguration)) { myManager.setSelectedConfiguration(settings); break; } } } - - // IDEA-60004: configs may never be sorted before write, so call it manually after shared configs read - myManager.setOrdered(false); } static class RunConfigurationStateSplitter extends StateSplitterEx { diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationRefactoringElementListenerProvider.java b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationRefactoringElementListenerProvider.java index 94571a9c1927..9a713784c1fe 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationRefactoringElementListenerProvider.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurationRefactoringElementListenerProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,6 @@ import com.intellij.refactoring.listeners.RefactoringElementListener; import com.intellij.refactoring.listeners.RefactoringElementListenerComposite; import com.intellij.refactoring.listeners.RefactoringElementListenerProvider; -import java.util.List; - /** * @author spleaner */ @@ -36,9 +34,7 @@ public class RunConfigurationRefactoringElementListenerProvider implements Refac @Override public RefactoringElementListener getListener(final PsiElement element) { RefactoringElementListenerComposite composite = null; - final List configurations = RunManager.getInstance(element.getProject()).getAllConfigurationsList(); - - for (RunConfiguration configuration : configurations) { + for (RunConfiguration configuration : RunManager.getInstance(element.getProject()).getAllConfigurationsList()) { if (configuration instanceof RefactoringListenerProvider) { // todo: perhaps better way to handle listeners? RefactoringElementListener listener; try { diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt index 4ac12fbbf438..9c7e955638fb 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt @@ -31,7 +31,6 @@ import com.intellij.openapi.components.* import com.intellij.openapi.diagnostic.catchAndLog import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.extensions.Extensions -import com.intellij.openapi.options.Scheme import com.intellij.openapi.options.SchemeManagerFactory import com.intellij.openapi.project.IndexNotReadyException import com.intellij.openapi.project.Project @@ -129,8 +128,8 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent private val schemeManagerProvider = SchemeManagerIprProvider("configuration") private val schemeManager = SchemeManagerFactory.getInstance(project).create("workspace", - object : LazySchemeProcessor() { - override fun createScheme(dataHolder: SchemeDataHolder, name: String, attributeProvider: Function, isBundled: Boolean): RunConfigurationScheme { + object : LazySchemeProcessor() { + override fun createScheme(dataHolder: SchemeDataHolder, name: String, attributeProvider: Function, isBundled: Boolean): RunnerAndConfigurationSettingsImpl { val settings = RunnerAndConfigurationSettingsImpl(this@RunManagerImpl) val element = dataHolder.read() try { @@ -295,7 +294,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent } if (!settings.isShared && existingSettings !== settings) { - schemeManager.addScheme(settings as RunConfigurationScheme) + schemeManager.addScheme(settings as RunnerAndConfigurationSettingsImpl) } } @@ -715,7 +714,7 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent fireRunConfigurationsRemoved(configurations) } - fun loadConfiguration(element: Element, isShared: Boolean): RunnerAndConfigurationSettings? { + fun loadConfiguration(element: Element, isShared: Boolean): RunnerAndConfigurationSettings { val settings = RunnerAndConfigurationSettingsImpl(this) LOG.catchAndLog { settings.readExternal(element, isShared) @@ -1144,14 +1143,4 @@ class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persistent changedSettings.forEach { myDispatcher.multicaster.runConfigurationChanged(it, null) } } -} - -internal interface RunConfigurationScheme : Scheme - -//private class UnknownRunConfigurationScheme(private val name: String) : RunConfigurationScheme, SerializableScheme { -// override fun getSchemeState() = SchemeState.UNCHANGED -// -// override fun writeScheme() = throw AssertionError("Must be not called") -// -// override fun getName() = name -//} \ No newline at end of file +} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.kt b/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.kt index 7bbecd80d1cc..f44040835d50 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.kt +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunnerAndConfigurationSettingsImpl.kt @@ -26,6 +26,7 @@ import com.intellij.openapi.components.PathMacroManager import com.intellij.openapi.components.PersistentStateComponent import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.extensions.ExtensionException +import com.intellij.openapi.options.Scheme import com.intellij.openapi.options.SchemeState import com.intellij.openapi.util.* import com.intellij.openapi.util.text.StringUtil @@ -56,7 +57,7 @@ val SINGLETON = "singleton" class RunnerAndConfigurationSettingsImpl @JvmOverloads constructor(private val manager: RunManagerImpl, private var _configuration: RunConfiguration? = null, private var isTemplate: Boolean = false, - private var singleton: Boolean = false) : Cloneable, RunnerAndConfigurationSettings, Comparable, RunConfigurationScheme, SerializableScheme { + private var singleton: Boolean = false) : Cloneable, RunnerAndConfigurationSettings, Comparable, Scheme, SerializableScheme { enum class Level { WORKSPACE, PROJECT, TEMPORARY } @@ -293,7 +294,7 @@ class RunnerAndConfigurationSettingsImpl @JvmOverloads constructor(private val m override fun getConfigurationSettings(runner: ProgramRunner<*>) = configurationPerRunnerSettings.getOrCreateSettings(runner) - override fun getType() = _configuration?.type + override fun getType(): ConfigurationType = _configuration?.type ?: UnknownConfigurationType.INSTANCE public override fun clone(): RunnerAndConfigurationSettings { val copy = RunnerAndConfigurationSettingsImpl(manager, _configuration!!.clone(), false) @@ -337,10 +338,7 @@ class RunnerAndConfigurationSettingsImpl @JvmOverloads constructor(private val m override fun compareTo(other: Any) = if (other is RunnerAndConfigurationSettings) name.compareTo(other.name) else 0 - override fun toString(): String { - val type = type - return "${if (type == null) "" else "${type.displayName}: "}${if (isTemplate) "