From 76a8b3ecf7ccba19758ffe6dc5cb7a850b83c315 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 9 Aug 2018 13:38:38 +0200 Subject: [PATCH] override, do not create LookupManager if not needed --- .../completion/CompletionSortingTestCase.java | 18 +------- .../completion/CompletionStyleTest.java | 41 +++++++------------ .../completion/CompletionTestCase.java | 18 +------- .../completion/CodeCompletionHandlerBase.java | 6 +-- .../codeInsight/lookup/LookupManager.java | 23 ++++------- .../ui/content/impl/ContentManagerImpl.java | 18 +------- .../testFramework/LightPlatformTestCase.java | 24 +++-------- .../impl/CodeInsightTestFixtureImpl.java | 2 +- .../intellij/lang/ant/AntCompletionTest.java | 18 +------- .../groovy/completion/CompletionTestBase.java | 16 ++++---- 10 files changed, 48 insertions(+), 136 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionSortingTestCase.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionSortingTestCase.java index 2e568d390273..3ab0c2a3ff83 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionSortingTestCase.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionSortingTestCase.java @@ -1,18 +1,4 @@ -/* - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.java.codeInsight.completion; import com.intellij.codeInsight.completion.CompletionType; @@ -48,7 +34,7 @@ public abstract class CompletionSortingTestCase extends LightFixtureCompletionTe @Override protected void tearDown() throws Exception { try { - LookupManager.getInstance(getProject()).hideActiveLookup(); + LookupManager.hideActiveLookup(getProject()); UISettings.getInstance().setSortLookupElementsLexicographically(false); } finally { diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionStyleTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionStyleTest.java index 75f90904928d..4a1734b1b493 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionStyleTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/completion/CompletionStyleTest.java @@ -1,21 +1,8 @@ -/* - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.java.codeInsight.completion; import com.intellij.JavaTestUtil; +import com.intellij.application.options.CodeStyle; import com.intellij.codeInsight.completion.CodeCompletionHandlerBase; import com.intellij.codeInsight.completion.CompletionType; import com.intellij.codeInsight.lookup.Lookup; @@ -25,7 +12,6 @@ import com.intellij.codeInsight.lookup.impl.LookupManagerImpl; import com.intellij.lang.java.JavaLanguage; import com.intellij.openapi.roots.LanguageLevelProjectExtension; import com.intellij.pom.java.LanguageLevel; -import com.intellij.psi.codeStyle.CodeStyleSettingsManager; import com.intellij.psi.codeStyle.CommonCodeStyleSettings; import com.intellij.testFramework.LightCodeInsightTestCase; import com.intellij.testFramework.TestDataPath; @@ -123,9 +109,8 @@ public class CompletionStyleTest extends LightCodeInsightTestCase{ } public void testLocalVariablePreselect() { - final String path = BASE_PATH; - configureByFile(path + "/before5.java"); + configureByFile(BASE_PATH + "/before5.java"); performSmartCompletion(); assertEquals("xxxx", getSelected().getLookupString()); } @@ -260,7 +245,7 @@ public class CompletionStyleTest extends LightCodeInsightTestCase{ } private static CommonCodeStyleSettings getCodeStyleSettings() { - return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE); + return CodeStyle.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE); } @@ -319,30 +304,34 @@ public class CompletionStyleTest extends LightCodeInsightTestCase{ checkResultByFile(path + "/after38.java"); } - private void performSmartCompletion(){ + private static void performSmartCompletion(){ new CodeCompletionHandlerBase(CompletionType.SMART).invokeCompletion(getProject(), getEditor()); } - private void performNormalCompletion(){ + private static void performNormalCompletion(){ new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(getProject(), getEditor()); } - private void select(char completionChar, int index){ + private static void select(char completionChar, int index){ ((LookupManagerImpl)LookupManager.getInstance(getProject())).forceSelection(completionChar, index); } - private void select(char completionChar, LookupElement item){ + private static void select(char completionChar, LookupElement item){ ((LookupManagerImpl)LookupManager.getInstance(getProject())).forceSelection(completionChar, item); } - private LookupElement getSelected(){ + private static LookupElement getSelected(){ return LookupManager.getInstance(getProject()).getActiveLookup().getCurrentItem(); } @Override protected void tearDown() throws Exception { - LookupManager.getInstance(getProject()).hideActiveLookup(); - super.tearDown(); + try { + LookupManager.hideActiveLookup(getProject()); + } + finally { + super.tearDown(); + } } public void testAfterNew15() { diff --git a/java/testFramework/src/com/intellij/codeInsight/completion/CompletionTestCase.java b/java/testFramework/src/com/intellij/codeInsight/completion/CompletionTestCase.java index ac69be8b8a53..a2fecdda01bb 100644 --- a/java/testFramework/src/com/intellij/codeInsight/completion/CompletionTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/completion/CompletionTestCase.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2011 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.completion; import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase; @@ -41,7 +27,7 @@ public abstract class CompletionTestCase extends DaemonAnalyzerTestCase { protected void tearDown() throws Exception { myItems = null; try { - LookupManager.getInstance(myProject).hideActiveLookup(); + LookupManager.hideActiveLookup(myProject); } finally { super.tearDown(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java index a94cfcfd545c..da3cd2139529 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -306,7 +306,7 @@ public class CodeCompletionHandlerBase { } private AutoCompletionDecision shouldAutoComplete(CompletionProgressIndicator indicator, - List items, + List items, CompletionParameters parameters) { if (!invokedExplicitly) { return AutoCompletionDecision.SHOW_LOOKUP; @@ -352,7 +352,7 @@ public class CodeCompletionHandlerBase { final List items = indicator.getLookup().getItems(); CompletionParameters parameters = Objects.requireNonNull(indicator.getParameters()); if (items.isEmpty()) { - LookupManager.getInstance(indicator.getProject()).hideActiveLookup(); + LookupManager.hideActiveLookup(indicator.getProject()); Caret nextCaret = getNextCaretToProcess(indicator.getEditor()); if (nextCaret != null) { @@ -391,7 +391,7 @@ public class CodeCompletionHandlerBase { CompletionServiceImpl.setCompletionPhase(hasModifiers? new CompletionPhase.InsertedSingleItem(indicator, restorePrefix) : CompletionPhase.NoCompletion); } } else if (decision == AutoCompletionDecision.CLOSE_LOOKUP) { - LookupManager.getInstance(indicator.getProject()).hideActiveLookup(); + LookupManager.hideActiveLookup(indicator.getProject()); } } catch (Throwable e) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupManager.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupManager.java index e4b9e8a86255..f6a4fa111f88 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupManager.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupManager.java @@ -1,18 +1,4 @@ -/* - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.lookup; @@ -63,6 +49,13 @@ public abstract class LookupManager { public abstract void hideActiveLookup(); + public static void hideActiveLookup(@NotNull Project project) { + LookupManager lookupManager = ServiceManager.getServiceIfCreated(project, LookupManager.class); + if (lookupManager != null) { + lookupManager.hideActiveLookup(); + } + } + @Nullable public abstract LookupEx getActiveLookup(); diff --git a/platform/platform-impl/src/com/intellij/ui/content/impl/ContentManagerImpl.java b/platform/platform-impl/src/com/intellij/ui/content/impl/ContentManagerImpl.java index b66067ca060e..ae9305ce6ba6 100644 --- a/platform/platform-impl/src/com/intellij/ui/content/impl/ContentManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/content/impl/ContentManagerImpl.java @@ -1,18 +1,4 @@ -/* - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ui.content.impl; import com.intellij.ide.DataManager; @@ -52,7 +38,7 @@ import static com.intellij.openapi.wm.IdeFocusManager.getGlobalInstance; * @author Vladimir Kondratyev */ public class ContentManagerImpl implements ContentManager, PropertyChangeListener, Disposable.Parent { - private static final Logger LOG = Logger.getInstance("#com.intellij.ui.content.impl.ContentManagerImpl"); + private static final Logger LOG = Logger.getInstance(ContentManagerImpl.class); private ContentUI myUI; private final List myContents = new ArrayList<>(); diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index 9ed5a9fb98dc..be81ec3ac5be 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -1,18 +1,4 @@ -/* - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.testFramework; import com.intellij.ProjectTopics; @@ -402,9 +388,9 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da new RunAll(). append(() -> ((FileTypeManagerImpl)FileTypeManager.getInstance()).drainReDetectQueue()). append(() -> CodeStyle.dropTemporarySettings(project)). - append(LightPlatformTestCase::checkJavaSwingTimersAreDisposed). + append(() -> checkJavaSwingTimersAreDisposed()). append(() -> UsefulTestCase.doPostponedFormatting(project)). - append(() -> LookupManager.getInstance(project).hideActiveLookup()). + append(() -> LookupManager.hideActiveLookup(project)). append(() -> ((StartupManagerImpl)StartupManager.getInstance(project)).prepareForNextTest()). append(() -> { if (ProjectManager.getInstance() == null) throw new AssertionError("Application components damaged"); }). append(() -> WriteCommandAction.runWriteCommandAction(project, () -> { @@ -458,7 +444,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da }). run(); } - + private static int ourTestCount; @ReviseWhenPortedToJDK("9") @@ -707,7 +693,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da return myModuleType; } - @Nullable + @Nullable @Override public Sdk getSdk() { return mySdk; 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 19f373cb1e05..5a48837222ff 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -1112,7 +1112,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig return; } - LookupManager.getInstance(project).hideActiveLookup(); + LookupManager.hideActiveLookup(project); PsiDocumentManager.getInstance(project).commitAllDocuments(); FileEditorManagerEx.getInstanceEx(project).closeAllFiles(); EditorHistoryManager.getInstance(project).removeAllFiles(); diff --git a/plugins/ant/tests/src/com/intellij/lang/ant/AntCompletionTest.java b/plugins/ant/tests/src/com/intellij/lang/ant/AntCompletionTest.java index 5bb0e1d6dff4..c98752fbe736 100644 --- a/plugins/ant/tests/src/com/intellij/lang/ant/AntCompletionTest.java +++ b/plugins/ant/tests/src/com/intellij/lang/ant/AntCompletionTest.java @@ -1,18 +1,4 @@ -/* - * 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. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.lang.ant; import com.intellij.codeInsight.completion.CodeCompletionHandlerBase; @@ -215,7 +201,7 @@ public class AntCompletionTest extends LightCodeInsightTestCase { @Override protected void tearDown() throws Exception { try { - LookupManager.getInstance(getProject()).hideActiveLookup(); + LookupManager.hideActiveLookup(getProject()); } finally { super.tearDown(); diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/CompletionTestBase.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/CompletionTestBase.java index 7355b3794e5f..6114f3fc62dc 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/CompletionTestBase.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/completion/CompletionTestBase.java @@ -16,6 +16,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; import org.jetbrains.plugins.groovy.util.TestUtils; import java.util.Collections; +import java.util.Comparator; import java.util.List; /** @@ -23,7 +24,6 @@ import java.util.List; * author ven */ public abstract class CompletionTestBase extends JavaCodeInsightFixtureTestCase { - protected void doTest() { doTest(""); } @@ -38,7 +38,7 @@ public abstract class CompletionTestBase extends JavaCodeInsightFixtureTestCase CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = false; - String result = ""; + StringBuilder result = new StringBuilder(); try { myFixture.completeBasic(); @@ -51,20 +51,20 @@ public abstract class CompletionTestBase extends JavaCodeInsightFixtureTestCase return !(o instanceof PsiMember) && !(o instanceof GrVariable) && !(o instanceof GroovyResolveResult) && !(o instanceof PsiPackage); }); } - Collections.sort(items, (o1, o2) -> o1.getLookupString().compareTo(o2.getLookupString())); - result = ""; + Collections.sort(items, Comparator.comparing(LookupElement::getLookupString)); + result = new StringBuilder(); for (LookupElement item : items) { - result = result + "\n" + item.getLookupString(); + result.append("\n").append(item.getLookupString()); } - result = result.trim(); - LookupManager.getInstance(myFixture.getProject()).hideActiveLookup(); + result = new StringBuilder(result.toString().trim()); + LookupManager.hideActiveLookup(myFixture.getProject()); } } finally { CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CODE_COMPLETION = true; } - assertEquals(StringUtil.trimEnd(stringList.get(1), "\n"), result); + assertEquals(StringUtil.trimEnd(stringList.get(1), "\n"), result.toString()); } protected String getExtension() {