From af6e705092ad7786007aadbf45e0517d5a7f8b7d Mon Sep 17 00:00:00 2001 From: Andrey Starovoyt Date: Mon, 1 Dec 2014 16:42:07 +0300 Subject: [PATCH] disable autocompletion for live/postfix templates --- ...ompleteCompletionElementIfTemplateUnique.java | 7 +++++++ ...eCompletionElementIfTemplateUnique_after.java | 7 +++++++ .../completion/TemplatesCompletionTest.java | 7 +++++++ .../codeInsight/lookup/AutoCompletionPolicy.java | 16 ++++++++++------ .../codeInsight/lookup/LookupElement.java | 4 ++++ .../lookup/LookupElementDecorator.java | 7 ++++++- .../completion/CodeCompletionHandlerBase.java | 12 +----------- .../intellij/codeInsight/lookup/LookupItem.java | 3 ++- .../template/impl/LiveTemplateLookupElement.java | 8 +++++++- 9 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/template/postfix/completion/doNotAutoCompleteCompletionElementIfTemplateUnique.java create mode 100644 java/java-tests/testData/codeInsight/template/postfix/completion/doNotAutoCompleteCompletionElementIfTemplateUnique_after.java diff --git a/java/java-tests/testData/codeInsight/template/postfix/completion/doNotAutoCompleteCompletionElementIfTemplateUnique.java b/java/java-tests/testData/codeInsight/template/postfix/completion/doNotAutoCompleteCompletionElementIfTemplateUnique.java new file mode 100644 index 000000000000..13e7671819c8 --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/completion/doNotAutoCompleteCompletionElementIfTemplateUnique.java @@ -0,0 +1,7 @@ +import java.lang.Object; + +public class Foo { + void m() { + new Object().instan + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/template/postfix/completion/doNotAutoCompleteCompletionElementIfTemplateUnique_after.java b/java/java-tests/testData/codeInsight/template/postfix/completion/doNotAutoCompleteCompletionElementIfTemplateUnique_after.java new file mode 100644 index 000000000000..13e7671819c8 --- /dev/null +++ b/java/java-tests/testData/codeInsight/template/postfix/completion/doNotAutoCompleteCompletionElementIfTemplateUnique_after.java @@ -0,0 +1,7 @@ +import java.lang.Object; + +public class Foo { + void m() { + new Object().instan + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/completion/TemplatesCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/completion/TemplatesCompletionTest.java index b5a04873e8d3..277a15b5b53a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/completion/TemplatesCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/template/postfix/completion/TemplatesCompletionTest.java @@ -126,6 +126,13 @@ public class TemplatesCompletionTest extends CompletionAutoPopupTestCase { doAutoPopupTest("instanceof", null); } + public void testDoNotAutoCompleteCompletionElementIfTemplateUnique() { + LiveTemplateCompletionContributor.ourShowTemplatesInTests = true; + configureByFile(); + myFixture.completeBasic(); + checkResultByFile(); + } + public void testDoNotCompleteTemplateInMultiCaretMode() { LiveTemplateCompletionContributor.ourShowTemplatesInTests = true; configureByFile(); diff --git a/platform/lang-api/src/com/intellij/codeInsight/lookup/AutoCompletionPolicy.java b/platform/lang-api/src/com/intellij/codeInsight/lookup/AutoCompletionPolicy.java index e9b76972dcde..4185fd4a9d80 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/lookup/AutoCompletionPolicy.java +++ b/platform/lang-api/src/com/intellij/codeInsight/lookup/AutoCompletionPolicy.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -55,13 +55,13 @@ public enum AutoCompletionPolicy { return new PolicyDecorator(element, this); } + /** + * @deprecated use direct call {@link LookupElement#getAutoCompletionPolicy()} instead + */ @Nullable + @Deprecated public static AutoCompletionPolicy getPolicy(LookupElement element) { - final PolicyDecorator decorator = element.as(PolicyDecorator.CLASS_CONDITION_KEY); - if (decorator != null) { - return decorator.myPolicy; - } - return null; + return element.getAutoCompletionPolicy(); } private static class PolicyDecorator extends LookupElementDecorator { @@ -73,5 +73,9 @@ public enum AutoCompletionPolicy { myPolicy = policy; } + @Override + public AutoCompletionPolicy getAutoCompletionPolicy() { + return myPolicy; + } } } diff --git a/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElement.java b/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElement.java index f2eb233259c7..d6deb948dfcb 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElement.java +++ b/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElement.java @@ -80,6 +80,10 @@ public abstract class LookupElement extends UserDataHolderBase { public void handleInsert(InsertionContext context) { } + public AutoCompletionPolicy getAutoCompletionPolicy() { + return AutoCompletionPolicy.SETTINGS_DEPENDENT; + } + @Override public String toString() { return getLookupString(); diff --git a/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementDecorator.java b/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementDecorator.java index 4af180b08b04..f7896e76b54e 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementDecorator.java +++ b/platform/lang-api/src/com/intellij/codeInsight/lookup/LookupElementDecorator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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,6 +64,11 @@ public abstract class LookupElementDecorator extends Lo myDelegate.handleInsert(context); } + @Override + public AutoCompletionPolicy getAutoCompletionPolicy() { + return myDelegate.getAutoCompletionPolicy(); + } + @Override public String toString() { return myDelegate.toString(); 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 397d30993ac9..0701673e71e0 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -390,17 +390,7 @@ public class CodeCompletionHandlerBase { @Nullable private static AutoCompletionPolicy getAutocompletionPolicy(LookupElement element) { - final AutoCompletionPolicy policy = AutoCompletionPolicy.getPolicy(element); - if (policy != null) { - return policy; - } - - final LookupItem item = element.as(LookupItem.CLASS_CONDITION_KEY); - if (item != null) { - return item.getAutoCompletionPolicy(); - } - - return null; + return element.getAutoCompletionPolicy(); } private static boolean isInsideIdentifier(final OffsetMap offsetMap) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupItem.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupItem.java index d8e53cf15730..cfd9b11ee3c4 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupItem.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/LookupItem.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -293,6 +293,7 @@ public class LookupItem extends MutableLookupElement implements Comparable return this; } + @Override public AutoCompletionPolicy getAutoCompletionPolicy() { return myAutoCompletionPolicy; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateLookupElement.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateLookupElement.java index 830d7b004060..6badd0286cd6 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateLookupElement.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/LiveTemplateLookupElement.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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,6 +15,7 @@ */ package com.intellij.codeInsight.template.impl; +import com.intellij.codeInsight.lookup.AutoCompletionPolicy; import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.LookupElementPresentation; import com.intellij.codeInsight.lookup.RealLookupElementPresentation; @@ -84,6 +85,11 @@ abstract public class LiveTemplateLookupElement extends LookupElement { } } + @Override + public AutoCompletionPolicy getAutoCompletionPolicy() { + return AutoCompletionPolicy.NEVER_AUTOCOMPLETE; + } + @Override public boolean isWorthShowingInAutoPopup() { return myWorthShowingInAutoPopup;