From 0cce542e7bb91b31987240160b12d30a5313f8a6 Mon Sep 17 00:00:00 2001 From: Philipp Smorygo Date: Fri, 6 Nov 2015 15:23:36 +0300 Subject: [PATCH] OC-9697 Include ObjC symbols into search everywhere --- .../DefaultSearchEverywhereClassifier.java | 50 +++++++++++++++ .../ide/actions/SearchEverywhereAction.java | 36 +++++------ .../actions/SearchEverywhereClassifier.java | 63 +++++++++++++++++++ .../src/META-INF/LangExtensionPoints.xml | 1 + .../src/META-INF/LangExtensions.xml | 1 + 5 files changed, 131 insertions(+), 20 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/ide/actions/DefaultSearchEverywhereClassifier.java create mode 100644 platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereClassifier.java diff --git a/platform/lang-impl/src/com/intellij/ide/actions/DefaultSearchEverywhereClassifier.java b/platform/lang-impl/src/com/intellij/ide/actions/DefaultSearchEverywhereClassifier.java new file mode 100644 index 000000000000..f77d294d1aaa --- /dev/null +++ b/platform/lang-impl/src/com/intellij/ide/actions/DefaultSearchEverywhereClassifier.java @@ -0,0 +1,50 @@ +/* + * 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 com.intellij.ide.actions; + +import com.intellij.lang.Language; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class DefaultSearchEverywhereClassifier implements SearchEverywhereClassifier { + @Override + public boolean isClass(@Nullable Object o) { + return o instanceof PsiElement; + } + + @Override + public boolean isSymbol(@Nullable Object o) { + if (o instanceof PsiElement) { + final PsiElement e = (PsiElement)o; + return !e.getLanguage().is(Language.findLanguageByID("JAVA")) || !(e.getParent() instanceof PsiFile); + } + return false; + } + + @Nullable + @Override + public VirtualFile getVirtualFile(@NotNull Object o) { + if (o instanceof PsiElement) { + final PsiElement element = (PsiElement)o; + final PsiFile file = element.getContainingFile(); + return file != null ? file.getVirtualFile() : null; + } + return null; + } +} diff --git a/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java b/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java index 309c78e113a1..5899bf88f37a 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java @@ -49,6 +49,7 @@ import com.intellij.lang.Language; import com.intellij.lang.LanguagePsiElementExternalizer; import com.intellij.navigation.ItemPresentation; import com.intellij.navigation.NavigationItem; +import com.intellij.navigation.PsiElementNavigationItem; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.actionSystem.ex.ActionUtil; @@ -1737,12 +1738,14 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA myProgressIndicator, new Processor() { @Override public boolean process(Object o) { - if (isSymbol(o)) { - final PsiElement element = (PsiElement)o; - final PsiFile file = element.getContainingFile(); - if (!myListModel.contains(o) && !symbols.contains(o) && - //some elements are non-physical like DB columns - (file == null || (file.getVirtualFile() != null && (includeLibs || scope.accept(file.getVirtualFile()))))) { + if (SearchEverywhereClassifier.EP_Manager.isSymbol(o) && !myListModel.contains(o) && !symbols.contains(o)) { + VirtualFile virtualFile = SearchEverywhereClassifier.EP_Manager.getVirtualFile(o); + //some elements are non-physical like DB columns + if (o instanceof PsiElementNavigationItem) { + o = ((PsiElementNavigationItem)o).getTargetElement(); + } + if ((o instanceof PsiElement && ((PsiElement)o).getContainingFile() == null) || + (virtualFile != null && (includeLibs || scope.accept(virtualFile)))) { symbols.add(o); } } @@ -1758,16 +1761,6 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA return symbols; } - protected boolean isSymbol(Object o) { - if (o instanceof PsiElement) { - final PsiElement e = (PsiElement)o; - //todo[kb] need a better way to avoid mixing java classes with symbols. Same to other languages where - //todo[kb] symbol provider returns classes. We need kind of suppressor API & EP here. - return !e.getLanguage().is(Language.findLanguageByID("JAVA")) || !(e.getParent() instanceof PsiFile); - } - return false; - } - private SearchResult getClasses(String pattern, boolean includeLibs, final int max, ChooseByNamePopup chooseByNamePopup) { final SearchResult classes = new SearchResult(); if (chooseByNamePopup == null || shouldSkipPattern(pattern)) { @@ -1777,17 +1770,20 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA myProgressIndicator, new Processor() { @Override public boolean process(Object o) { - if (o instanceof PsiElement && !myListModel.contains(o) && !classes.contains(o)) { + if (SearchEverywhereClassifier.EP_Manager.isClass(o) && !myListModel.contains(o) && !classes.contains(o)) { if (classes.size() == max) { classes.needMore = true; return false; } classes.add(o); + + if (o instanceof PsiElementNavigationItem) { + o = ((PsiElementNavigationItem)o).getTargetElement(); + } if (o instanceof PsiNamedElement) { final String name = ((PsiNamedElement)o).getName(); - final PsiFile file = ((PsiNamedElement)o).getContainingFile(); - if (file != null) { - final VirtualFile virtualFile = file.getVirtualFile(); + VirtualFile virtualFile = SearchEverywhereClassifier.EP_Manager.getVirtualFile(o); + if (virtualFile != null) { if (StringUtil.equals(name, virtualFile.getNameWithoutExtension())) { myAlreadyAddedFiles.add(virtualFile); } diff --git a/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereClassifier.java b/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereClassifier.java new file mode 100644 index 000000000000..df01b72c04f5 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereClassifier.java @@ -0,0 +1,63 @@ +/* + * 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 com.intellij.ide.actions; + +import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.openapi.extensions.Extensions; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Philipp Smorygo + */ +public interface SearchEverywhereClassifier { + class EP_Manager { + private EP_Manager() {} + + public static boolean isClass(@Nullable Object o) { + for (SearchEverywhereClassifier classifier : Extensions.getExtensions(SearchEverywhereClassifier.EP_NAME)) { + if (classifier.isClass(o)) return true; + } + return false; + } + + public static boolean isSymbol(@Nullable Object o) { + for (SearchEverywhereClassifier classifier : Extensions.getExtensions(SearchEverywhereClassifier.EP_NAME)) { + if (classifier.isSymbol(o)) return true; + } + return false; + } + + @Nullable + public static VirtualFile getVirtualFile(@NotNull Object o) { + for (SearchEverywhereClassifier classifier : Extensions.getExtensions(SearchEverywhereClassifier.EP_NAME)) { + VirtualFile virtualFile = classifier.getVirtualFile(o); + if (virtualFile != null) return virtualFile; + } + return null; + } + } + + ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.searchEverywhereClassifier"); + + boolean isClass(@Nullable Object o); + + boolean isSymbol(@Nullable Object o); + + @Nullable + VirtualFile getVirtualFile(@NotNull Object o); +} diff --git a/platform/platform-resources/src/META-INF/LangExtensionPoints.xml b/platform/platform-resources/src/META-INF/LangExtensionPoints.xml index b2ec46225bdc..ac297d36c338 100644 --- a/platform/platform-resources/src/META-INF/LangExtensionPoints.xml +++ b/platform/platform-resources/src/META-INF/LangExtensionPoints.xml @@ -843,6 +843,7 @@ + diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 6f1691dbb1c3..5a9b04f6555a 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -557,6 +557,7 @@ +