From b390cd3d40ef27e342f41a18720194a5c2be2c00 Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Wed, 9 Mar 2011 18:57:57 +0300 Subject: [PATCH 01/17] WI-1303 highlight html tags not allowed in the context as warnings --- .../HtmlUnknownTagInspection.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/xml/impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownTagInspection.java b/xml/impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownTagInspection.java index f51880dc6ab8..9d91ff55d275 100644 --- a/xml/impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownTagInspection.java +++ b/xml/impl/src/com/intellij/codeInspection/htmlInspections/HtmlUnknownTagInspection.java @@ -194,18 +194,42 @@ public class HtmlUnknownTagInspection extends HtmlLocalInspectionTool { return myCustomValuesEnabled; } + private static boolean isInRightPlace(@NotNull XmlTag tag, @NotNull XmlElementDescriptor tagDescriptor) { + XmlTag parentTag = tag.getParentTag(); + if (parentTag == null) { + return true; + } + XmlElementDescriptor parentDescriptor = parentTag.getDescriptor(); + if (parentDescriptor == null) { + return true; + } + XmlElementDescriptor[] suitableChildDescriptors = parentDescriptor.getElementsDescriptors(parentTag); + for (XmlElementDescriptor descriptor : suitableChildDescriptors) { + if (descriptor.getName().equalsIgnoreCase(tagDescriptor.getName())) { + return true; + } + } + return false; + } + protected void checkTag(@NotNull final XmlTag tag, @NotNull final ProblemsHolder holder, final boolean isOnTheFly) { if (XmlHighlightVisitor.skipValidation(tag)) { return; } final XmlElementDescriptor descriptor = tag.getDescriptor(); - if (tag instanceof HtmlTag && (descriptor instanceof AnyXmlElementDescriptor || descriptor == null)) { + if (tag instanceof HtmlTag && + (descriptor == null || descriptor instanceof AnyXmlElementDescriptor || !isInRightPlace(tag, descriptor))) { final String name = tag.getName(); if (!isCustomValuesEnabled() || !isCustomValue(name)) { final AddCustomTagOrAttributeIntentionAction action = new AddCustomTagOrAttributeIntentionAction(getShortName(), name, XmlEntitiesInspection.UNKNOWN_TAG); - final String message = XmlErrorMessages.message("unknown.html.tag", name); + + // todo: support "element is not allowed" message for html5 + // some tags in html5 cannot be found in xhtml5.xsd if they are located in incorrect context, so they get any-element descriptor (ex. "canvas: tag) + final String message = descriptor == null || descriptor instanceof AnyXmlElementDescriptor + ? XmlErrorMessages.message("unknown.html.tag", name) + : XmlErrorMessages.message("element.is.not.allowed.here", name); final PsiElement startTagName = XmlTagUtil.getStartTagNameElement(tag); assert startTagName != null; From 00c4c9f686e68e13da6853c8d94842706efa12a5 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 10 Mar 2011 14:58:43 +0300 Subject: [PATCH 02/17] set false back. scrolling doesn't work --- platform/platform-resources-en/src/misc/registry.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index 405a73b0a55b..63bf0feab4bc 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -116,6 +116,6 @@ caches.indexerThreadsCount=-1 vcs.show.history.numbers=true navbar.updateMergeTime=250 navbar.userActivityMergeTime=500 -navbar.newpopup=true +navbar.newpopup=false inspectionGadgets.telemetry.enabled=false From 971a82a16a51a1ee9a8c61a0aba478c9a9b7d9ec Mon Sep 17 00:00:00 2001 From: Sergey Evdokimov Date: Thu, 10 Mar 2011 15:34:52 +0300 Subject: [PATCH 03/17] Fix Stress tests. --- .../intellij/ide/ui/search/SearchableOptionsRegistrarImpl.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/ui/search/SearchableOptionsRegistrarImpl.java b/platform/platform-impl/src/com/intellij/ide/ui/search/SearchableOptionsRegistrarImpl.java index 8e069a96fdf9..9da67123c1b8 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/search/SearchableOptionsRegistrarImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/search/SearchableOptionsRegistrarImpl.java @@ -363,7 +363,6 @@ public class SearchableOptionsRegistrarImpl extends SearchableOptionsRegistrar { for (String opt : options) { if (isStopWord(opt)) continue; final String processed = PorterStemmerUtil.stem(opt); - assert processed != null; if (isStopWord(processed)) continue; result.add(opt); } @@ -377,7 +376,7 @@ public class SearchableOptionsRegistrarImpl extends SearchableOptionsRegistrar { for (String opt : options) { if (isStopWord(opt)) continue; opt = PorterStemmerUtil.stem(opt); - assert opt != null; + if (opt == null) continue; result.add(opt); } return result; From 9eaca9b0a627525f5cc3914a378622d44761bb2d Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Thu, 10 Mar 2011 13:56:39 +0100 Subject: [PATCH 04/17] fix test, revert comparator change --- .../com/intellij/codeInspection/ex/InspectionTool.java | 4 ++-- .../ui/InspectionResultsViewComparator.java | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionTool.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionTool.java index 3b72d53b7cbf..ba6ff2431c9d 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionTool.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/InspectionTool.java @@ -209,9 +209,9 @@ public abstract class InspectionTool extends InspectionProfileEntry { return null; } - public InspectionNode createToolNode(final InspectionRVContentProvider provider, final InspectionTreeNode parentNode, final boolean showSructure) { + public InspectionNode createToolNode(final InspectionRVContentProvider provider, final InspectionTreeNode parentNode, final boolean showStructure) { final InspectionNode toolNode = new InspectionNode(this); - provider.appendToolNodeContent(toolNode, parentNode, showSructure); + provider.appendToolNodeContent(toolNode, parentNode, showStructure); return toolNode; } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsViewComparator.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsViewComparator.java index 826ed7730b8e..fd143315a1ab 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsViewComparator.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsViewComparator.java @@ -127,14 +127,10 @@ public class InspectionResultsViewComparator implements Comparator { } private static int compareEntities(final RefEntity entity1, final RefEntity entity2) { - if (entity1 != null && entity2 != null) { - final int nameComparison = entity1.getName().compareToIgnoreCase(entity2.getName()); - if (nameComparison != 0) { - return nameComparison; - } - } if (entity1 instanceof RefElement && entity2 instanceof RefElement) { return PsiUtilBase.compareElementsByPosition(((RefElement)entity1).getElement(), ((RefElement)entity2).getElement()); + } else if (entity1 != null && entity2 != null) { + return entity1.getName().compareToIgnoreCase(entity2.getName()); } return 0; } From 958da8c725bf6daf0b1449bdf223c5a65058fbdb Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 10 Mar 2011 13:25:23 +0100 Subject: [PATCH 05/17] Cleanup --- .../completion/ClassNameCompletionTest.java | 56 +++++++++---------- .../completion/VariablesCompletionTest.java | 2 +- .../codeInsight/CodeInsightTestCase.java | 6 +- .../completion/CompletionTestCase.java | 16 +++--- 4 files changed, 41 insertions(+), 39 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/ClassNameCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/ClassNameCompletionTest.java index 620c4dda55d3..ae09e7ea3386 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/ClassNameCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/ClassNameCompletionTest.java @@ -62,29 +62,29 @@ public class ClassNameCompletionTest extends CompletionTestCase { checkResultByFile(path + "/after2.java"); } - public void testExcessParensAfterNew() throws Throwable { doTest(); } + public void testExcessParensAfterNew() throws Exception { doTest(); } - public void testReuseParensAfterNew() throws Throwable { doTest(); } + public void testReuseParensAfterNew() throws Exception { doTest(); } - public void testBracesAfterNew() throws Throwable { doTest(); } + public void testBracesAfterNew() throws Exception { doTest(); } - public void testInPlainTextFile() throws Throwable { + public void testInPlainTextFile() throws Exception { configureByFile(BASE_PATH + getTestName(false) + ".txt"); checkResultByFile(BASE_PATH + getTestName(false) + "_after.txt"); } - public void testDoubleStringBuffer() throws Throwable { + public void testDoubleStringBuffer() throws Exception { createClass("package java.lang; public class StringBuffer {}"); doTest(); assertNull(myItems); } - public void testReplaceReferenceExpressionWithTypeElement() throws Throwable { + public void testReplaceReferenceExpressionWithTypeElement() throws Exception { createClass("package foo.bar; public class ABCDEF {}"); doTest(); } - public void testCamelHumpPrefix() throws Throwable { + public void testCamelHumpPrefix() throws Exception { String path = BASE_PATH + "/java/"; configureByFile(path + getTestName(false) + ".java"); complete(); @@ -174,34 +174,48 @@ public class ClassNameCompletionTest extends CompletionTestCase { checkResultByFile(path + "/test13-result.java"); } - public void testInMethodCall() throws Throwable { + public void testInMethodCall() throws Exception { final String path = BASE_PATH + "/nameCompletion/java"; configureByFile(path + "/methodCall-source.java"); performAction(); checkResultByFile(path + "/methodCall-result.java"); } - public void testInMethodCallQualifier() throws Throwable { + public void testInMethodCallQualifier() throws Exception { final String path = BASE_PATH + "/nameCompletion/java"; configureByFile(path + "/methodCall1-source.java"); performAction(); checkResultByFile(path + "/methodCall1-result.java"); } - public void testInVariableDeclarationType() throws Throwable { + public void testInVariableDeclarationType() throws Exception { final String path = BASE_PATH + "/nameCompletion/java"; configureByFile(path + "/varType-source.java"); performAction(); checkResultByFile(path + "/varType-result.java"); } - public void testExtraSpace() throws Throwable { doJavaTest(); } + public void testExtraSpace() throws Exception { doJavaTest(); } - public void testAnnotation() throws Throwable { doJavaTest(); } + public void testAnnotation() throws Exception { doJavaTest(); } - public void testInStaticImport() throws Throwable { doJavaTest(); } + public void testInStaticImport() throws Exception { doJavaTest(); } - public void testInCommentWithPackagePrefix() throws Throwable { doJavaTest(); } + public void testInCommentWithPackagePrefix() throws Exception { doJavaTest(); } + + public void testQualifyNameOnSecondCompletion() throws Exception { + new WriteCommandAction.Simple(getProject()) { + @Override + protected void run() throws Exception { + final Module module = ModuleManager.getInstance(getProject()).newModule("second.iml", new JavaModuleType()); + createClass(module, "package foo.bar; class AxBxCxDxEx {}"); + } + }.execute().throwException(); + + configureByFileNoCompletion(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-source.java"); + new CodeCompletionHandlerBase(CompletionType.CLASS_NAME).invokeCompletion(myProject, myEditor, 2, false); + checkResultByFile(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-result.java"); + } private void doJavaTest() throws Exception { final String path = BASE_PATH + "/nameCompletion/java"; @@ -229,18 +243,4 @@ public class ClassNameCompletionTest extends CompletionTestCase { testLookupManager.forceSelection(Lookup.NORMAL_SELECT_CHAR, 0); } } - - public void testQualifyNameOnSecondCompletion() throws Throwable { - new WriteCommandAction.Simple(getProject()) { - @Override - protected void run() throws Throwable { - final Module module = ModuleManager.getInstance(getProject()).newModule("second.iml", new JavaModuleType()); - createClass(module, "package foo.bar; class AxBxCxDxEx {}"); - } - }.execute().throwException(); - - configureByFileNoCompletion(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-source.java"); - new CodeCompletionHandlerBase(CompletionType.CLASS_NAME).invokeCompletion(myProject, myEditor, 2, false); - checkResultByFile(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-result.java"); - } } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.java index bad71b4ecaa6..6c4ebbe4c565 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/VariablesCompletionTest.java @@ -121,7 +121,7 @@ public class VariablesCompletionTest extends CompletionTestCase { configureByFile(FILE_PREFIX + "locals/" + "UnresolvedMethodName.java"); complete(); checkResultByFile(FILE_PREFIX + "locals/" + "UnresolvedMethodName.java"); - testByCount(2, "creAnInt", "createStylesheetCombobox"); + doTestByCount(2, "creAnInt", "createStylesheetCombobox"); } public void testArrayMethodName() throws Throwable { diff --git a/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java b/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java index 478026b15804..9d22a5aba29f 100644 --- a/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/CodeInsightTestCase.java @@ -126,11 +126,11 @@ public abstract class CodeInsightTestCase extends PsiTestCase { return configureByFile(vFile, projectFile); } - protected PsiFile configureByText(final FileType fileType, @NonNls final String text) throws Throwable { + protected PsiFile configureByText(final FileType fileType, @NonNls final String text) throws Exception { return configureByText(fileType, text, null); } - protected PsiFile configureByText(final FileType fileType, @NonNls final String text, final String _extension) throws Throwable { + protected PsiFile configureByText(final FileType fileType, @NonNls final String text, final String _extension) throws Exception { final String extension = _extension == null ? fileType.getDefaultExtension():_extension; File dir = createTempDirectory(); @@ -139,7 +139,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase { if (fileTypeManager.getFileTypeByExtension(extension) != fileType) { new WriteCommandAction(getProject()) { @Override - protected void run(Result result) throws Throwable { + protected void run(Result result) throws Exception { fileTypeManager.associateExtension(fileType, extension); } }.execute(); diff --git a/java/testFramework/src/com/intellij/codeInsight/completion/CompletionTestCase.java b/java/testFramework/src/com/intellij/codeInsight/completion/CompletionTestCase.java index 07ccfeb5bd02..5ce8f5f978da 100644 --- a/java/testFramework/src/com/intellij/codeInsight/completion/CompletionTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/completion/CompletionTestCase.java @@ -7,6 +7,7 @@ import com.intellij.codeInsight.lookup.impl.LookupImpl; import com.intellij.psi.statistics.StatisticsManager; import com.intellij.psi.statistics.impl.StatisticsManagerImpl; import com.intellij.testFramework.PlatformTestCase; +import org.jetbrains.annotations.Nullable; import java.util.Arrays; @@ -51,7 +52,7 @@ public abstract class CompletionTestCase extends DaemonAnalyzerTestCase { new CodeCompletionHandlerBase(myType).invokeCompletion(myProject, myEditor, time, false); LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(myEditor); - myItems = lookup == null ? null : lookup.getItems().toArray(LookupElement.EMPTY_ARRAY); + myItems = lookup == null ? null : lookup.getItems().toArray(new LookupElement[lookup.getItems().size()]); myPrefix = lookup == null ? "" : lookup.getItems().get(0).getPrefixMatcher().getPrefix(); } @@ -61,6 +62,7 @@ public abstract class CompletionTestCase extends DaemonAnalyzerTestCase { protected void selectItem(LookupElement item, char ch) { final LookupImpl lookup = (LookupImpl)LookupManager.getInstance(myProject).getActiveLookup(); + assert lookup != null; lookup.setCurrentItem(item); lookup.finishLookup(ch); } @@ -69,19 +71,18 @@ public abstract class CompletionTestCase extends DaemonAnalyzerTestCase { selectItem(item, (char)0); } - protected void testByCount(int finalCount, String... values) { + protected void doTestByCount(int finalCount, String... values) { int index = 0; if (myItems == null) { assertEquals(0, finalCount); return; } - for (int i = 0; i < myItems.length; i++) { - final LookupElement myItem = myItems[i]; - for (int j = 0; j < values.length; j++) { - if (values[j] == null) { + for (final LookupElement myItem : myItems) { + for (String value : values) { + if (value == null) { assertFalse("Unacceptable value reached", true); } - if (values[j].equals(myItem.getLookupString())) { + if (value.equals(myItem.getLookupString())) { index++; break; } @@ -90,6 +91,7 @@ public abstract class CompletionTestCase extends DaemonAnalyzerTestCase { assertEquals(Arrays.toString(myItems), finalCount, index); } + @Nullable protected LookupImpl getActiveLookup() { return (LookupImpl)LookupManager.getActiveLookup(myEditor); } From 74f50e196a26551048ea5f5a364af1151d4640d3 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 10 Mar 2011 15:26:10 +0100 Subject: [PATCH 06/17] To JB dictionary --- .../spellchecker/src/com/intellij/spellchecker/jetbrains.dic | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic b/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic index ff6711f49221..f9f4494c8ab3 100644 --- a/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic +++ b/plugins/spellchecker/src/com/intellij/spellchecker/jetbrains.dic @@ -73,6 +73,8 @@ filename fileset filesets filesystem +finalizer +finalizers foreach formatter freelist From 33a2f0275e36395df5108876b3c7a620cb06441a Mon Sep 17 00:00:00 2001 From: Eugene Kudelevsky Date: Thu, 10 Mar 2011 18:40:49 +0300 Subject: [PATCH 07/17] WI-1245 support for completion of previously used colors in css --- .../src/com/intellij/xml/util/ColorSampleLookupValue.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xml/impl/src/com/intellij/xml/util/ColorSampleLookupValue.java b/xml/impl/src/com/intellij/xml/util/ColorSampleLookupValue.java index 5f93da6db7ef..da36441b16f8 100644 --- a/xml/impl/src/com/intellij/xml/util/ColorSampleLookupValue.java +++ b/xml/impl/src/com/intellij/xml/util/ColorSampleLookupValue.java @@ -275,7 +275,7 @@ public class ColorSampleLookupValue implements LookupValueWithUIHint, DeferredUs } public String getPresentation() { - return myName; + return myName != null ? myName : myValue; } public String getValue() { @@ -363,7 +363,7 @@ public class ColorSampleLookupValue implements LookupValueWithUIHint, DeferredUs } public String getTypeHint() { - return myValue.charAt(0) == '#' ? myValue : null; + return myName != null && myValue.charAt(0) == '#' ? myValue : null; } @SuppressWarnings({"HardCodedStringLiteral"}) @@ -380,7 +380,7 @@ public class ColorSampleLookupValue implements LookupValueWithUIHint, DeferredUs } public int getPriority() { - return Character.isLowerCase(myName.charAt(0)) ? HIGHER : NORMAL; + return myName == null || Character.isLowerCase(myName.charAt(0)) ? HIGHER : NORMAL; } public static String getHexCodeForColorName(String colorName) { From 9593bfc3f1d804b0c821732acca4d01586820a63 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 10 Mar 2011 16:40:34 +0100 Subject: [PATCH 08/17] Completion in multi-catch --- .../JavaClassNameCompletionContributor.java | 11 ++++--- .../completion/JavaCompletionContributor.java | 5 ++- .../java/Annotation-result.java | 2 +- .../java/InCatchType1-result.java | 7 ++++ .../java/InCatchType1-source.java | 7 ++++ .../java/InCatchType2-result.java | 7 ++++ .../java/InCatchType2-source.java | 7 ++++ .../java/InMultiCatchType1-result.java | 7 ++++ .../java/InMultiCatchType1-source.java | 7 ++++ .../java/InMultiCatchType2-result.java | 7 ++++ .../java/InMultiCatchType2-source.java | 7 ++++ .../completion/ClassNameCompletionTest.java | 33 ++++++++++++++----- 12 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InCatchType1-result.java create mode 100644 java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InCatchType1-source.java create mode 100644 java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InCatchType2-result.java create mode 100644 java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InCatchType2-source.java create mode 100644 java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InMultiCatchType1-result.java create mode 100644 java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InMultiCatchType1-source.java create mode 100644 java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InMultiCatchType2-result.java create mode 100644 java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InMultiCatchType2-source.java diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaClassNameCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaClassNameCompletionContributor.java index c299e311aa80..dbc185aefe39 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaClassNameCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaClassNameCompletionContributor.java @@ -67,7 +67,6 @@ public class JavaClassNameCompletionContributor extends CompletionContributor { }); } }); - } public static void addAllClasses(CompletionParameters parameters, final CompletionResultSet result, @NotNull final Consumer consumer) { @@ -76,10 +75,12 @@ public class JavaClassNameCompletionContributor extends CompletionContributor { final ElementFilter filter = or(JavaSmartCompletionContributor.AFTER_THROW_NEW, JavaCompletionContributor.INSIDE_METHOD_THROWS_CLAUSE, - JavaCompletionContributor.IN_CATCH_TYPE).accepts(insertedElement) ? new AssignableFromFilter(CommonClassNames.JAVA_LANG_THROWABLE) : - IN_TYPE_PARAMETER.accepts(insertedElement) ? new ExcludeDeclaredFilter(new ClassFilter(PsiTypeParameter.class)) : - TrueFilter.INSTANCE; - + JavaCompletionContributor.IN_CATCH_TYPE, + JavaCompletionContributor.IN_MULTI_CATCH_TYPE).accepts(insertedElement) + ? new AssignableFromFilter(CommonClassNames.JAVA_LANG_THROWABLE) + : IN_TYPE_PARAMETER.accepts(insertedElement) + ? new ExcludeDeclaredFilter(new ClassFilter(PsiTypeParameter.class)) + : TrueFilter.INSTANCE; final boolean inJavaContext = parameters.getPosition() instanceof PsiIdentifier; if (AFTER_NEW.accepts(insertedElement)) { diff --git a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java index 6ba1da7d07d4..5fc5e0245ee1 100644 --- a/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java +++ b/java/java-impl/src/com/intellij/codeInsight/completion/JavaCompletionContributor.java @@ -90,6 +90,9 @@ public class JavaCompletionContributor extends CompletionContributor { psiElement().withParent(psiElement(PsiJavaCodeReferenceElement.class).withParent(PsiImportStatementBase.class)); static final PsiJavaElementPattern.Capture IN_CATCH_TYPE = psiElement().afterLeaf(psiElement().withText("(").withParent(PsiCatchSection.class)); + static final ElementPattern IN_MULTI_CATCH_TYPE = + or(psiElement().afterLeaf(psiElement().withText("|").withParent(PsiTypeElement.class).withSuperParent(2, PsiCatchSection.class)), + psiElement().afterLeaf(psiElement().withText("|").withParent(PsiTypeElement.class).withSuperParent(2, PsiParameter.class).withSuperParent(3, PsiCatchSection.class))); static final PsiJavaElementPattern.Capture INSIDE_METHOD_THROWS_CLAUSE = psiElement().afterLeaf(PsiKeyword.THROWS, ",").inside( PsiMethod.class).andNot(psiElement().inside(PsiCodeBlock.class)).andNot(psiElement().inside(PsiParameterList.class)); @@ -128,7 +131,7 @@ public class JavaCompletionContributor extends CompletionContributor { return ElementClassFilter.VARIABLE; } - if (IN_CATCH_TYPE.accepts(position)) { + if (IN_CATCH_TYPE.accepts(position) || IN_MULTI_CATCH_TYPE.accepts(position)) { return new AssignableFromFilter(CommonClassNames.JAVA_LANG_THROWABLE); } diff --git a/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/Annotation-result.java b/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/Annotation-result.java index ded584ee78c4..f410038c7877 100644 --- a/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/Annotation-result.java +++ b/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/Annotation-result.java @@ -2,7 +2,7 @@ String name(); } -@Column() +@Column @interface Annotation { } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InCatchType1-result.java b/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InCatchType1-result.java new file mode 100644 index 000000000000..9ac7b8cbf548 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InCatchType1-result.java @@ -0,0 +1,7 @@ +class MyClass { + static class MyException extends Exception { } + + void m() { + try { } catch (MyException) { } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InCatchType1-source.java b/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InCatchType1-source.java new file mode 100644 index 000000000000..59982da1d7cb --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InCatchType1-source.java @@ -0,0 +1,7 @@ +class MyClass { + static class MyException extends Exception { } + + void m() { + try { } catch (My) { } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InCatchType2-result.java b/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InCatchType2-result.java new file mode 100644 index 000000000000..2a45f98c066d --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InCatchType2-result.java @@ -0,0 +1,7 @@ +class MyClass { + static class MyException extends Exception { } + + void m() { + try { } catch (MyException e) { } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InCatchType2-source.java b/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InCatchType2-source.java new file mode 100644 index 000000000000..892b3b041db7 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InCatchType2-source.java @@ -0,0 +1,7 @@ +class MyClass { + static class MyException extends Exception { } + + void m() { + try { } catch (My e) { } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InMultiCatchType1-result.java b/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InMultiCatchType1-result.java new file mode 100644 index 000000000000..034ff3767c12 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InMultiCatchType1-result.java @@ -0,0 +1,7 @@ +class MyClass { + static class MyException extends Exception { } + + void m() { + try { } catch (RuntimeException | MyException) { } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InMultiCatchType1-source.java b/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InMultiCatchType1-source.java new file mode 100644 index 000000000000..d8594a2b45d3 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InMultiCatchType1-source.java @@ -0,0 +1,7 @@ +class MyClass { + static class MyException extends Exception { } + + void m() { + try { } catch (RuntimeException | My) { } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InMultiCatchType2-result.java b/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InMultiCatchType2-result.java new file mode 100644 index 000000000000..1eb884110104 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InMultiCatchType2-result.java @@ -0,0 +1,7 @@ +class MyClass { + static class MyException extends Exception { } + + void m() { + try { } catch (RuntimeException | MyException e) { } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InMultiCatchType2-source.java b/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InMultiCatchType2-source.java new file mode 100644 index 000000000000..5c5002ef7790 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/className/nameCompletion/java/InMultiCatchType2-source.java @@ -0,0 +1,7 @@ +class MyClass { + static class MyException extends Exception { } + + void m() { + try { } catch (RuntimeException | My e) { } + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/ClassNameCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/ClassNameCompletionTest.java index ae09e7ea3386..3f3ea8c77a2a 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/ClassNameCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/ClassNameCompletionTest.java @@ -9,6 +9,8 @@ import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.module.JavaModuleType; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.pom.java.LanguageLevel; import com.intellij.testFramework.PsiTestUtil; import com.intellij.testFramework.TestDataPath; @@ -70,7 +72,7 @@ public class ClassNameCompletionTest extends CompletionTestCase { public void testInPlainTextFile() throws Exception { configureByFile(BASE_PATH + getTestName(false) + ".txt"); - checkResultByFile(BASE_PATH + getTestName(false) + "_after.txt"); + checkResultByFile(BASE_PATH + getTestName(false) + "_after.txt"); } public void testDoubleStringBuffer() throws Exception { @@ -95,7 +97,7 @@ public class ClassNameCompletionTest extends CompletionTestCase { private void doTest() throws Exception { String path = BASE_PATH + "/java/"; configureByFile(path + getTestName(false) + ".java"); - checkResultByFile(path + getTestName(false) + "_after.java"); + checkResultByFile(path + getTestName(false) + "_after.java"); } public void testNameCompletionJava() throws Exception { @@ -108,14 +110,14 @@ public class ClassNameCompletionTest extends CompletionTestCase { checkResultByFile(path + "/test2-result.java"); } - public void testImplementsFiltering1() throws Exception{ + public void testImplementsFiltering1() throws Exception { final String path = BASE_PATH + "/nameCompletion/java"; configureByFile(path + "/test4-source.java"); performAction(); checkResultByFile(path + "/test4-result.java"); } - public void testImplementsFiltering2() throws Exception{ + public void testImplementsFiltering2() throws Exception { final String path = BASE_PATH + "/nameCompletion/java"; configureByFile(path + "/test3-source.java"); performAction(); @@ -135,7 +137,7 @@ public class ClassNameCompletionTest extends CompletionTestCase { return "testAnnotationFiltering".equals(getName()); } - public void testAnnotationFiltering() throws Exception{ + public void testAnnotationFiltering() throws Exception { final String path = BASE_PATH + "/nameCompletion/java"; configureByFile(path + "/test7-source.java"); performAction(); @@ -217,9 +219,23 @@ public class ClassNameCompletionTest extends CompletionTestCase { checkResultByFile(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-result.java"); } + public void testInCatchType1() throws Exception { doJavaTest(); } + + public void testInCatchType2() throws Exception { doJavaTest(); } + + public void testInMultiCatchType1() throws Exception { + LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7); + doJavaTest(); + } + + public void testInMultiCatchType2() throws Exception { + LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_7); + doJavaTest(); + } + private void doJavaTest() throws Exception { final String path = BASE_PATH + "/nameCompletion/java"; - configureByFile(path + "/" + getTestName(false) + "-source.java"); + configureByFileNoCompletion(path + "/" + getTestName(false) + "-source.java"); performAction(); checkResultByFile(path + "/" + getTestName(false) + "-result.java"); } @@ -237,10 +253,11 @@ public class ClassNameCompletionTest extends CompletionTestCase { CodeCompletionHandlerBase handler = new CodeCompletionHandlerBase(CompletionType.CLASS_NAME); handler.invokeCompletion(myProject, myEditor); final LookupManager instance = LookupManager.getInstance(myProject); - if(instance instanceof LookupManagerImpl){ + if (instance instanceof LookupManagerImpl) { final LookupManagerImpl testLookupManager = ((LookupManagerImpl)instance); - if(testLookupManager.getActiveLookup() != null) + if (testLookupManager.getActiveLookup() != null) { testLookupManager.forceSelection(Lookup.NORMAL_SELECT_CHAR, 0); + } } } } From 54771972521ee52cb6b88cb3672192f5ff4a76f5 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Thu, 10 Mar 2011 17:16:13 +0100 Subject: [PATCH 09/17] fix: mark dependencies for recompilation when the whole class definition was commented (empty java file) --- .../com/intellij/compiler/impl/CompileDriver.java | 13 ++----------- .../src/com/intellij/compiler/make/CacheUtils.java | 4 ++-- .../com/intellij/compiler/make/DependencyCache.java | 8 ++++---- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java index f95e64d655d2..ed5bf54c4460 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java @@ -1047,20 +1047,11 @@ public class CompileDriver { final boolean hasUnprocessedTraverseRoots = context.getDependencyCache().hasUnprocessedTraverseRoots(); if (!isRebuild && (compiledSomethingForThisChunk || hasUnprocessedTraverseRoots)) { - final Set compiledWithSuccess; final Set compiledWithErrors = CacheUtils.getFilesCompiledWithErrors(context); - if (compiledWithErrors.isEmpty()) { - compiledWithSuccess = sink.getCompiledSources(); - } - else { - compiledWithSuccess = new HashSet(); - compiledWithSuccess.addAll(sink.getCompiledSources()); - compiledWithSuccess.removeAll(compiledWithErrors); - } - filesToRecompile.removeAll(compiledWithSuccess); + filesToRecompile.removeAll(sink.getCompiledSources()); filesToRecompile.addAll(compiledWithErrors); - dependentFiles = CacheUtils.findDependentFiles(context, compiledWithSuccess, dependencyFilter); + dependentFiles = CacheUtils.findDependentFiles(context, compiledWithErrors, dependencyFilter); if (!processedModules.isEmpty()) { for (Iterator it = dependentFiles.iterator(); it.hasNext();) { final VirtualFile next = it.next(); diff --git a/java/compiler/impl/src/com/intellij/compiler/make/CacheUtils.java b/java/compiler/impl/src/com/intellij/compiler/make/CacheUtils.java index 17fede94b744..3b72d2048f4d 100644 --- a/java/compiler/impl/src/com/intellij/compiler/make/CacheUtils.java +++ b/java/compiler/impl/src/com/intellij/compiler/make/CacheUtils.java @@ -130,7 +130,7 @@ public class CacheUtils { public static Collection findDependentFiles( final CompileContextEx context, - final Set succesfullyCompiledJavaFiles, + final Set compiledWithErrors, final @Nullable Function>, Pair>> filter) throws CacheCorruptedException { if (!CompilerConfiguration.MAKE_ENABLED) { @@ -141,7 +141,7 @@ public class CacheUtils { final DependencyCache dependencyCache = context.getDependencyCache(); final Pair> deps = - dependencyCache.findDependentClasses(context, context.getProject(), succesfullyCompiledJavaFiles); + dependencyCache.findDependentClasses(context, context.getProject(), compiledWithErrors); final Pair> filteredDeps = filter != null? filter.fun(deps) : deps; final Set dependentFiles = new HashSet(); diff --git a/java/compiler/impl/src/com/intellij/compiler/make/DependencyCache.java b/java/compiler/impl/src/com/intellij/compiler/make/DependencyCache.java index 7cc150d13ff3..f2cb4704c399 100644 --- a/java/compiler/impl/src/com/intellij/compiler/make/DependencyCache.java +++ b/java/compiler/impl/src/com/intellij/compiler/make/DependencyCache.java @@ -390,14 +390,14 @@ public class DependencyCache { /** * @return qualified names of the classes that should be additionally recompiled */ - public Pair> findDependentClasses(CompileContext context, Project project, Set successfullyCompiled) + public Pair> findDependentClasses(CompileContext context, Project project, Set compiledWithErrors) throws CacheCorruptedException { - markDependencies(context, project, successfullyCompiled); + markDependencies(context, project, compiledWithErrors); return new Pair>(myMarkedInfos.toArray(), Collections.unmodifiableSet(myMarkedFiles)); } - private void markDependencies(CompileContext context, Project project, final Set successfullyCompiled) throws CacheCorruptedException { + private void markDependencies(CompileContext context, Project project, final Set compiledWithErrors) throws CacheCorruptedException { try { if (LOG.isDebugEnabled()) { LOG.debug("====================Marking dependent files====================="); @@ -441,7 +441,7 @@ public class DependencyCache { final boolean markAsRemovedSource = ApplicationManager.getApplication().runReadAction(new Computable() { public Boolean compute() { VirtualFile sourceFile = sourceFileFinder.findSourceFile(qualifiedName, sourceFileName); - return sourceFile == null || successfullyCompiled.contains(sourceFile) ? Boolean.TRUE : Boolean.FALSE; + return sourceFile == null || !compiledWithErrors.contains(sourceFile) ? Boolean.TRUE : Boolean.FALSE; } }).booleanValue(); if (markAsRemovedSource) { From 171b22ed3b4c1e04a85c5cc940fcc8d28dd9ccfe Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Thu, 10 Mar 2011 19:56:20 +0300 Subject: [PATCH 10/17] CIDR-387 --- .../intellij/openapi/editor/impl/SelectionModelImpl.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/SelectionModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/SelectionModelImpl.java index 1a5c6c8f5178..996bdb377b12 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/SelectionModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/SelectionModelImpl.java @@ -316,14 +316,11 @@ public class SelectionModelImpl implements SelectionModel, PrioritizedDocumentLi } FoldRegion endFold = foldingModel.getCollapsedRegionAtOffset(endOffset); - if (endFold != null) { - VisualPosition visualFoldStart = myEditor.offsetToVisualPosition(endFold.getStartOffset()); + if (endFold != null && endFold.getStartOffset() < endOffset) { // All visual positions that lay at collapsed fold region placeholder are mapped to the same offset. Hence, there are // at least two distinct situations - selection end is located inside collapsed fold region placeholder and just before it. // We want to expand selection to the fold region end at the former case and keep selection as-is at the latest one. - if (visualFoldStart.column < endPosition.column) { - endOffset = endFold.getEndOffset(); - } + endOffset = endFold.getEndOffset(); } int oldSelectionStart; From 459572c2ae2b10a8383043bc3a696e659097c087 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 10 Mar 2011 19:26:03 +0300 Subject: [PATCH 11/17] +isSelectionButtonDown method --- platform/util/src/com/intellij/util/ui/UIUtil.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platform/util/src/com/intellij/util/ui/UIUtil.java b/platform/util/src/com/intellij/util/ui/UIUtil.java index d99b1c06be9d..1f0ada94107b 100644 --- a/platform/util/src/com/intellij/util/ui/UIUtil.java +++ b/platform/util/src/com/intellij/util/ui/UIUtil.java @@ -1749,6 +1749,10 @@ public class UIUtil { } } + public static boolean isSelectionButtonDown(MouseEvent e) { + return e.isShiftDown() || e.isControlDown() || e.isMetaDown(); + } + public static void setComboBoxEditorBounds(int x, int y, int width, int height, JComponent editor) { if(SystemInfo.isMac && isUnderAquaLookAndFeel()) { // fix for too wide combobox editor, see AquaComboBoxUI.layoutContainer: From 82cdd82ebd092f4cf71ef305140db8714d58ec21 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 10 Mar 2011 19:27:53 +0300 Subject: [PATCH 12/17] client can have actions mapped to LEFT/RIGHT keys. So, use maybeInstall to register actions by default --- .../com/intellij/ui/ListScrollingUtil.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/ListScrollingUtil.java b/platform/platform-api/src/com/intellij/ui/ListScrollingUtil.java index 9694bcc20b5f..5c4899f977a9 100644 --- a/platform/platform-api/src/com/intellij/ui/ListScrollingUtil.java +++ b/platform/platform-api/src/com/intellij/ui/ListScrollingUtil.java @@ -16,9 +16,6 @@ package com.intellij.ui; import com.intellij.ide.ui.UISettings; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CustomShortcutSet; import com.intellij.openapi.diagnostic.Logger; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; @@ -44,6 +41,10 @@ public class ListScrollingUtil { protected static final String SELECT_LAST_ROW_ACTION_ID = "selectLastRow"; @NonNls protected static final String SELECT_FIRST_ROW_ACTION_ID = "selectFirstRow"; + @NonNls + protected static final String MOVE_HOME_ID = "MOVE_HOME"; + @NonNls + protected static final String MOVE_END_ID = "MOVE_END"; public static final int ROW_PADDING = 2; @@ -267,17 +268,18 @@ public class ListScrollingUtil { moveHome(list); } }); - new AnAction() { - public void actionPerformed(AnActionEvent e) { + actionMap.put(MOVE_HOME_ID, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { moveHome(list); } - }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)), list); - new AnAction() { - public void actionPerformed(AnActionEvent e) { + }); + actionMap.put(MOVE_END_ID, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { moveEnd(list); } - }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0)), list); - + }); InputMap map = list.getInputMap(JComponent.WHEN_FOCUSED); UIUtil.maybeInstall(map, SCROLLUP_ACTION_ID, KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0)); @@ -286,6 +288,7 @@ public class ListScrollingUtil { UIUtil.maybeInstall(map, SELECT_NEXT_ROW_ACTION_ID, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)); UIUtil.maybeInstall(map, SELECT_FIRST_ROW_ACTION_ID, KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0)); UIUtil.maybeInstall(map, SELECT_LAST_ROW_ACTION_ID, KeyStroke.getKeyStroke(KeyEvent.VK_END, 0)); - + UIUtil.maybeInstall(map, MOVE_HOME_ID, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0)); + UIUtil.maybeInstall(map, MOVE_END_ID, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0)); } } From 99aaf2dcf0fe34640977fd45775f7c0267db7dfd Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 10 Mar 2011 19:29:04 +0300 Subject: [PATCH 13/17] use UIUtil method --- .../intellij/openapi/ui/popup/PopupChooserBuilder.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/ui/popup/PopupChooserBuilder.java b/platform/platform-api/src/com/intellij/openapi/ui/popup/PopupChooserBuilder.java index 5bfc0857fa73..8aa1dbbd027d 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/popup/PopupChooserBuilder.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/popup/PopupChooserBuilder.java @@ -192,7 +192,7 @@ public class PopupChooserBuilder { (list != null ? list : myChooserComponent).addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { - if (UIUtil.isActionClick(e) && !isSelectionButtonDown(e) && !e.isConsumed()) { + if (UIUtil.isActionClick(e) && !UIUtil.isSelectionButtonDown(e) && !e.isConsumed()) { closePopup(true, e, true); } } @@ -385,10 +385,6 @@ public class PopupChooserBuilder { return this; } - private static boolean isSelectionButtonDown(MouseEvent e) { - return e.isShiftDown() || e.isControlDown() || e.isMetaDown(); - } - public PopupChooserBuilder setSettingButton(Component abutton) { mySettingsButtons = abutton; return this; @@ -409,7 +405,7 @@ public class PopupChooserBuilder { list.addMouseMotionListener(new MouseMotionAdapter() { boolean myIsEngaged = false; public void mouseMoved(MouseEvent e) { - if (myIsEngaged && !isSelectionButtonDown(e)) { + if (myIsEngaged && !UIUtil.isSelectionButtonDown(e)) { Point point = e.getPoint(); int index = list.locationToIndex(point); list.setSelectedIndex(index); From 1692242c8f108ca273e7a835bfb9b4f32232576f Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 10 Mar 2011 19:31:13 +0300 Subject: [PATCH 14/17] hide path optimization to navigateInside --- .../ide/navigationToolbar/NavBarPanel.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java index e4cb30031b95..1d19a5f2e05d 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPanel.java @@ -119,7 +119,7 @@ public class NavBarPanel extends OpaquePanel.List implements DataProvider, Popup public boolean isNodePopupActive() { return (myNodePopup != null && myNodePopup.isVisible() && myNodePopup.isFocused()) - || (myNodeHint != null && myNodeHint.isVisible() && myNodeHint.getComponent().hasFocus()); + || (myNodeHint != null && myNodeHint.isVisible()); } public LightweightHint getHint() { @@ -153,8 +153,7 @@ public class NavBarPanel extends OpaquePanel.List implements DataProvider, Popup } public void enter() { - final Object o = myModel.getSelectedValue(); - navigateInsideBar(optimizeTarget(o)); + navigateInsideBar(myModel.getSelectedValue()); } public void moveHome() { @@ -439,7 +438,7 @@ public class NavBarPanel extends OpaquePanel.List implements DataProvider, Popup public PopupStep onChosen(final Object selectedValue, final boolean finalChoice) { return doFinalStep(new Runnable() { public void run() { - navigateInsideBar(optimizeTarget(selectedValue)); + navigateInsideBar(selectedValue); } }); } @@ -488,25 +487,26 @@ public class NavBarPanel extends OpaquePanel.List implements DataProvider, Popup } void navigateInsideBar(final Object object) { + final Object obj = optimizeTarget(object); myContextObject = null; myUpdateQueue.cancelAllUpdates(); - myUpdateQueue.queueModelUpdateForObject(object); + myUpdateQueue.queueModelUpdateForObject(obj); myUpdateQueue.queueRebuildUi(); myUpdateQueue.queueAfterAll(new Runnable() { public void run() { - int index = myModel.indexOf(object); + int index = myModel.indexOf(obj); if (index >= 0) { myModel.setSelectedIndex(index); } - if (myModel.hasChildren(object)) { + if (myModel.hasChildren(obj)) { restorePopup(); } else { - doubleClick(object); + doubleClick(obj); } } }, NavBarUpdateQueue.ID.NAVIGATE_INSIDE); From 321fa82d51a988dd85332012c32db042f79f69f0 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 10 Mar 2011 19:49:18 +0300 Subject: [PATCH 15/17] scrolling + quick search --- .../ide/navigationToolbar/NavBarPopup.java | 117 +++++++++++++++--- 1 file changed, 102 insertions(+), 15 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPopup.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPopup.java index 28d195a70478..c4a6616cf6f6 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPopup.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarPopup.java @@ -16,35 +16,39 @@ package com.intellij.ide.navigationToolbar; import com.intellij.openapi.actionSystem.DataProvider; +import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.wm.IdeFocusManager; -import com.intellij.ui.HintHint; -import com.intellij.ui.IdeBorderFactory; -import com.intellij.ui.LightweightHint; -import com.intellij.ui.ListenerUtil; +import com.intellij.ui.*; import com.intellij.ui.awt.RelativePoint; import com.intellij.ui.components.JBList; +import com.intellij.ui.components.JBScrollPane; +import com.intellij.ui.speedSearch.ListWithFilter; +import com.intellij.util.Function; import com.intellij.util.NotNullFunction; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.swing.*; +import javax.swing.border.Border; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; +import java.awt.event.*; /** * @author Konstantin Bulenkov */ public class NavBarPopup extends LightweightHint { + private static final String JBLIST_KEY = "OriginalList"; private final NavBarPanel myPanel; + private int myIndex; public NavBarPopup(NavBarPanel panel, Object[] siblings, final int selectedIndex) { - super(createPopupContent(panel, siblings, selectedIndex)); + super(createPopupContent(panel, siblings)); myPanel = panel; + myIndex = selectedIndex; setFocusRequestor(getComponent()); setForceShowAsPopup(true); ListenerUtil.addMouseListener(getComponent(), new MouseAdapter() { @@ -66,6 +70,11 @@ public class NavBarPopup extends LightweightHint { IdeFocusManager.getInstance(myPanel.getProject()).requestFocus(myPanel, true); myPanel.rightClick(selectedIndex); e.consume(); + } else { + final Object value = getList().getSelectedValue(); + if (value != null) { + myPanel.navigateInsideBar(value); + } } } }); @@ -87,10 +96,11 @@ public class NavBarPopup extends LightweightHint { }); } else { show(myPanel, p.x, p.y, myPanel, new HintHint(myPanel, p)); + getList().setSelectedIndex(myIndex); } } - private static JBList createPopupContent(final NavBarPanel panel, Object[] siblings, int selectedIndex) { + private static JComponent createPopupContent(final NavBarPanel panel, Object[] siblings) { final JBList list = new JBList(siblings); list.setDataProvider(new DataProvider() { @Override @@ -105,26 +115,47 @@ public class NavBarPopup extends LightweightHint { return new NavBarItem(panel, obj); } }); - list.setBorder(IdeBorderFactory.createEmptyBorder(5,5,5,5)); - list.setSelectedIndex(selectedIndex); + list.setBorder(IdeBorderFactory.createEmptyBorder(5, 5, 5, 5)); installMoveAction(list, panel, -1, KeyEvent.VK_LEFT); installMoveAction(list, panel, 1, KeyEvent.VK_RIGHT); installEnterAction(list, panel, KeyEvent.VK_ENTER); - return list; + installEscapeAction(list, panel, KeyEvent.VK_ESCAPE); + final JComponent component = ListWithFilter.wrap(list, new MyListWrapper(list), new Function() { + @Override + public String fun(Object o) { + return NavBarPresentation.getPresentableText(o, panel.getWindow()); + } + }); + component.putClientProperty(JBLIST_KEY, list); + return component; } private static void installEnterAction(final JBList list, final NavBarPanel panel, int keyCode) { final AbstractAction action = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { - panel.navigateInsideBar(NavBarPanel.optimizeTarget(list.getSelectedValue())); + panel.navigateInsideBar(list.getSelectedValue()); + } + }; + list.registerKeyboardAction(action, KeyStroke.getKeyStroke(keyCode, 0), JComponent.WHEN_FOCUSED); + } + + private static void installEscapeAction(final JBList list, final NavBarPanel panel, int keyCode) { + final AbstractAction action = new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + panel.cancelPopup(); } }; list.registerKeyboardAction(action, KeyStroke.getKeyStroke(keyCode, 0), JComponent.WHEN_FOCUSED); } public Object getSelectedValue() { - return ((JBList)getComponent()).getSelectedValue(); + return getList().getSelectedValue(); + } + + private JBList getList() { + return ((JBList)getComponent().getClientProperty(JBLIST_KEY)); } private static void installMoveAction(JBList list, final NavBarPanel panel, final int direction, final int keyCode) { @@ -138,4 +169,60 @@ public class NavBarPopup extends LightweightHint { }; list.registerKeyboardAction(action, KeyStroke.getKeyStroke(keyCode, 0), JComponent.WHEN_FOCUSED); } + + static class MyListWrapper extends JBScrollPane implements DataProvider { + private static final int MAX_SIZE = 20; + private final JList myList; + + public MyListWrapper(final JList list) { + super(list); + list.addMouseMotionListener(new MouseMotionAdapter() { + boolean myIsEngaged = false; + public void mouseMoved(MouseEvent e) { + if (myIsEngaged && !UIUtil.isSelectionButtonDown(e)) { + final Point point = e.getPoint(); + final int index = list.locationToIndex(point); + list.setSelectedIndex(index); + } else { + myIsEngaged = true; + } + } + }); + + ListScrollingUtil.installActions(list); + + final int modelSize = list.getModel().getSize(); + setBorder(BorderFactory.createEmptyBorder()); + if (modelSize > 0 && modelSize <= MAX_SIZE) { + list.setVisibleRowCount(0); + getViewport().setPreferredSize(list.getPreferredSize()); + } else { + list.setVisibleRowCount(MAX_SIZE); + } + myList = list; + } + + + @Nullable + public Object getData(@NonNls String dataId) { + if (PlatformDataKeys.SELECTED_ITEM.is(dataId)){ + return myList.getSelectedValue(); + } + return null; + } + + public void setBorder(Border border) { + if (myList != null){ + myList.setBorder(border); + } + } + + public void requestFocus() { + myList.requestFocus(); + } + + public synchronized void addMouseListener(MouseListener l) { + myList.addMouseListener(l); + } + } } From 7aee4529db0c431646c46ba88cd5d433362bacec Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 10 Mar 2011 19:50:03 +0300 Subject: [PATCH 16/17] fix selection blinking --- .../ide/navigationToolbar/NavBarItem.java | 29 +++---------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarItem.java b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarItem.java index 628a12fff7f2..b1f4e9b0d7de 100644 --- a/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarItem.java +++ b/platform/lang-impl/src/com/intellij/ide/navigationToolbar/NavBarItem.java @@ -15,16 +15,11 @@ */ package com.intellij.ide.navigationToolbar; -import com.intellij.openapi.actionSystem.DataProvider; -import com.intellij.openapi.actionSystem.LangDataKeys; -import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.psi.PsiElement; import com.intellij.ui.SimpleColoredComponent; import com.intellij.ui.SimpleTextAttributes; import com.intellij.util.Icons; import com.intellij.util.ui.EmptyIcon; import com.intellij.util.ui.UIUtil; -import org.jetbrains.annotations.NonNls; import javax.swing.*; import java.awt.*; @@ -32,7 +27,7 @@ import java.awt.*; /** * @author Konstantin Bulenkov */ -class NavBarItem extends SimpleColoredComponent implements DataProvider{ +class NavBarItem extends SimpleColoredComponent { private final String myText; private final SimpleTextAttributes myAttributes; private final int myIndex; @@ -91,10 +86,11 @@ class NavBarItem extends SimpleColoredComponent implements DataProvider{ setIcon(myIcon); final Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); - boolean focused = isPopupElement ? myPanel.isNodePopupActive() : focusOwner == myPanel; + final boolean focused = isPopupElement || (focusOwner == myPanel && !myPanel.isNodePopupShowing()); final NavBarModel model = myPanel.getModel(); - boolean selected = isPopupElement ? myPanel.isSelectedInPopup(myObject) : model.getSelectedIndex() == myIndex; + final boolean selected = isPopupElement ? myPanel.isSelectedInPopup(myObject) + : model.getSelectedIndex() == myIndex; setPaintFocusBorder(!focused && selected && !isPopupElement); setFocusBorderAroundIcon(false); @@ -136,21 +132,4 @@ class NavBarItem extends SimpleColoredComponent implements DataProvider{ } }; } - - @Override - public Object getData(@NonNls String dataId) { - if (PlatformDataKeys.PROJECT.is(dataId)) { - return myPanel.getProject(); - } - - if (LangDataKeys.PSI_ELEMENT.is(dataId)) { - return myObject instanceof PsiElement ? myObject : null; - } - - if (LangDataKeys.PSI_FILE.is(dataId)) { - return myObject instanceof PsiElement ? ((PsiElement)myObject).getContainingFile() : null; - } - - return null; - } } From ba9d68e826f9c30a7f49f0bc647d9cff370f0b40 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 10 Mar 2011 19:51:52 +0300 Subject: [PATCH 17/17] enable new navbar popup back --- platform/platform-resources-en/src/misc/registry.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index 63bf0feab4bc..405a73b0a55b 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -116,6 +116,6 @@ caches.indexerThreadsCount=-1 vcs.show.history.numbers=true navbar.updateMergeTime=250 navbar.userActivityMergeTime=500 -navbar.newpopup=false +navbar.newpopup=true inspectionGadgets.telemetry.enabled=false