Navigate to symbol for kotlin properties

This commit is contained in:
Nikolay Krasko
2012-10-16 14:52:28 +04:00
parent bc85a8bf6b
commit 04670d5d6e
11 changed files with 227 additions and 7 deletions
+2
View File
@@ -184,6 +184,7 @@
<iconProvider implementation="org.jetbrains.jet.plugin.JetIconProvider"/>
<itemPresentationProvider implementationClass="org.jetbrains.jet.plugin.presentation.JetFunctionPresenter" forClass="org.jetbrains.jet.lang.psi.JetNamedFunction"/>
<itemPresentationProvider implementationClass="org.jetbrains.jet.plugin.presentation.JetClassPresenter" forClass="org.jetbrains.jet.lang.psi.JetClass"/>
<itemPresentationProvider implementationClass="org.jetbrains.jet.plugin.presentation.JetPropertyPresenter" forClass="org.jetbrains.jet.lang.psi.JetProperty"/>
<gotoTargetRendererProvider id="JetGotoTargetRenderProvider" implementation="org.jetbrains.jet.plugin.JetGotoTargetRenderProvider" order="first"/>
<elementDescriptionProvider implementation="org.jetbrains.jet.plugin.findUsages.JetElementDescriptionProvider"/>
<findUsagesHandlerFactory implementation="org.jetbrains.jet.plugin.findUsages.KotlinFindUsagesHandlerFactory"/>
@@ -198,6 +199,7 @@
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetShortClassNameIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetFullClassNameIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetShortFunctionNameIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetShortPropertiesNameIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetExtensionFunctionNameIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetAllShortFunctionNameIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetSuperClassIndex"/>
@@ -38,19 +38,26 @@ public class JetGotoSymbolContributor implements ChooseByNameContributor {
@NotNull
@Override
public String[] getNames(Project project, boolean includeNonProjectItems) {
final Collection<String> items = StubIndex.getInstance().getAllKeys(JetIndexKeys.FUNCTIONS_SHORT_NAME_KEY, project);
Collection<String> items = StubIndex.getInstance().getAllKeys(JetIndexKeys.FUNCTIONS_SHORT_NAME_KEY, project);
items.addAll(StubIndex.getInstance().getAllKeys(JetIndexKeys.PROPERTIES_SHORT_NAME_KEY, project));
return ArrayUtil.toStringArray(items);
}
@NotNull
@Override
public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) {
final GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
final Collection<? extends NavigationItem> functions = StubIndex.getInstance().get(
Collection<? extends NavigationItem> functions = StubIndex.getInstance().get(
JetIndexKeys.FUNCTIONS_SHORT_NAME_KEY, name, project, scope);
Collection<? extends NavigationItem> properties = StubIndex.getInstance().get(
JetIndexKeys.PROPERTIES_SHORT_NAME_KEY, name, project, scope);
final List<NavigationItem> items = new ArrayList<NavigationItem>(Collections2.filter(functions, Predicates.notNull()));
items.addAll(properties);
return ArrayUtil.toObjectArray(items, NavigationItem.class);
}
}
@@ -0,0 +1,28 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.plugin.presentation;
import com.intellij.navigation.ItemPresentation;
import com.intellij.navigation.ItemPresentationProvider;
import org.jetbrains.jet.lang.psi.JetProperty;
public class JetPropertyPresenter implements ItemPresentationProvider<JetProperty> {
@Override
public ItemPresentation getPresentation(final JetProperty item) {
return new JetDefaultNamedDeclarationPresentation(item);
}
}
@@ -44,6 +44,7 @@ public interface JetIndexKeys {
StubIndexKey.createIndexKey("jet.top.level.property.fqn.name");
StubIndexKey<String, JetNamedFunction> FUNCTIONS_SHORT_NAME_KEY = StubIndexKey.createIndexKey("jet.functions.short.name");
StubIndexKey<String, JetProperty> PROPERTIES_SHORT_NAME_KEY = StubIndexKey.createIndexKey("jet.properties.short.name");
StubIndexKey<String, JetAnnotationEntry> ANNOTATIONS_KEY = StubIndexKey.createIndexKey("jet.annotations");
}
@@ -0,0 +1,45 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.plugin.stubindex;
import com.intellij.openapi.project.Project;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.stubs.StringStubIndexExtension;
import com.intellij.psi.stubs.StubIndexKey;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetProperty;
import java.util.Collection;
public class JetShortPropertiesNameIndex extends StringStubIndexExtension<JetProperty> {
private static final JetShortPropertiesNameIndex ourInstance = new JetShortPropertiesNameIndex();
public static JetShortPropertiesNameIndex getInstance() {
return ourInstance;
}
@NotNull
@Override
public StubIndexKey<String, JetProperty> getKey() {
return JetIndexKeys.PROPERTIES_SHORT_NAME_KEY;
}
@Override
public Collection<JetProperty> get(final String s, final Project project, @NotNull final GlobalSearchScope scope) {
return super.get(s, project, new JetSourceFilterScope(scope));
}
}
@@ -81,11 +81,16 @@ public class StubIndexServiceImpl implements StubIndexService {
@Override
public void indexProperty(PsiJetPropertyStub stub, IndexSink sink) {
if (stub.isTopLevel()) {
FqName topFQName = stub.getTopFQName();
if (topFQName != null) {
sink.occurrence(JetIndexKeys.TOP_LEVEL_PROPERTY_FQN_NAME_KEY, topFQName.toString());
String propertyName = stub.getName();
if (propertyName != null) {
if (stub.isTopLevel()) {
FqName topFQName = stub.getTopFQName();
if (topFQName != null) {
sink.occurrence(JetIndexKeys.TOP_LEVEL_PROPERTY_FQN_NAME_KEY, topFQName.toString());
}
}
sink.occurrence(JetIndexKeys.PROPERTIES_SHORT_NAME_KEY, propertyName);
}
}