KT-800 Implement Navigate->Symbol... for kotlin - done for functions
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.navigation.ItemPresentationProviders;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.StubBasedPsiElement;
|
||||
import com.intellij.psi.stubs.IStubElementType;
|
||||
@@ -124,4 +126,9 @@ public class JetNamedFunction extends JetFunction implements StubBasedPsiElement
|
||||
// TODO (stubs)
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemPresentation getPresentation() {
|
||||
return ItemPresentationProviders.getItemPresentation(this);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ import java.io.IOException;
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public class JetFileElementType extends IStubFileElementType<PsiJetFileStub> {
|
||||
public static final int STUB_VERSION = 2;
|
||||
public static final int STUB_VERSION = 3;
|
||||
|
||||
public JetFileElementType() {
|
||||
super("jet.FILE", JetLanguage.INSTANCE);
|
||||
|
||||
@@ -64,9 +64,7 @@
|
||||
<internalFileTemplate name="Kotlin Enum"/>
|
||||
<internalFileTemplate name="Kotlin Trait"/>
|
||||
|
||||
<!--
|
||||
<gotoSymbolContributor implementation="org.jetbrains.jet.plugin.caches.GotoSymbolContributor"/>
|
||||
-->
|
||||
|
||||
<fileTypeFactory implementation="org.jetbrains.jet.plugin.JetFileFactory"/>
|
||||
|
||||
@@ -139,6 +137,7 @@
|
||||
<configurationProducer implementation="org.jetbrains.jet.plugin.run.JetJUnitConfigurationProducer"/>
|
||||
<codeInsight.lineMarkerProvider language="jet" implementationClass="org.jetbrains.jet.plugin.annotations.JetLineMarkerProvider"/>
|
||||
<iconProvider implementation="org.jetbrains.jet.plugin.JetIconProvider"/>
|
||||
<itemPresentationProvider implementationClass="org.jetbrains.jet.plugin.presentation.JetFunctionPresenter" forClass="org.jetbrains.jet.lang.psi.JetNamedFunction"/>
|
||||
<elementDescriptionProvider implementation="org.jetbrains.jet.plugin.findUsages.JetElementDescriptionProvider"/>
|
||||
<debugger.positionManagerFactory implementation="org.jetbrains.jet.plugin.debugger.JetPositionManagerFactory"/>
|
||||
<codeInsight.implementMethod language="jet" implementationClass="org.jetbrains.jet.plugin.codeInsight.ImplementMethodsHandler"/>
|
||||
@@ -152,6 +151,7 @@
|
||||
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetFullClassNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetShortFunctionNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetExtensionFunctionNameIndex"/>
|
||||
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetAllShortFunctionNameIndex"/>
|
||||
|
||||
<editorNotificationProvider implementation="org.jetbrains.jet.plugin.quickfix.ConfigureKotlinLibraryNotificationProvider"/>
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ public class JetIconProvider extends IconProvider {
|
||||
public static final Icon ICON_FOR_OBJECT = PlatformIcons.ANONYMOUS_CLASS_ICON;
|
||||
public static final Icon KOTLIN_ICON = IconLoader.getIcon("/org/jetbrains/jet/plugin/icons/kotlin16x16.png");
|
||||
|
||||
public static JetIconProvider INSTANCE = new JetIconProvider();
|
||||
|
||||
@Override
|
||||
public Icon getIcon(@NotNull PsiElement psiElement, int flags) {
|
||||
if (psiElement instanceof JetFile) {
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2000-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.caches;
|
||||
|
||||
import com.intellij.navigation.ChooseByNameContributor;
|
||||
import com.intellij.navigation.NavigationItem;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.stubs.StubIndex;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetIndexKeys;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public class GotoSymbolContributor implements ChooseByNameContributor {
|
||||
@NotNull
|
||||
@Override
|
||||
public String[] getNames(Project project, boolean includeNonProjectItems) {
|
||||
final Collection<String> items = StubIndex.getInstance().getAllKeys(JetIndexKeys.FUNCTIONS_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);
|
||||
|
||||
final Collection<? extends NavigationItem> functions = StubIndex.getInstance().get(
|
||||
JetIndexKeys.FUNCTIONS_SHORT_NAME_KEY, name, project, scope);
|
||||
|
||||
final List<NavigationItem> items = new ArrayList<NavigationItem>(functions);
|
||||
return ArrayUtil.toObjectArray(items, NavigationItem.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2000-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.ColoredItemPresentation;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.navigation.ItemPresentationProvider;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.plugin.JetIconProvider;
|
||||
import org.jetbrains.jet.util.QualifiedNamesUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public class JetFunctionPresenter implements ItemPresentationProvider<JetNamedFunction> {
|
||||
@Override
|
||||
public ItemPresentation getPresentation(final JetNamedFunction function) {
|
||||
return new ColoredItemPresentation() {
|
||||
@Override
|
||||
public TextAttributesKey getTextAttributesKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
return function.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocationString() {
|
||||
return String.format("(in %s)", QualifiedNamesUtil.withoutLastSegment(JetPsiUtil.getFQName(function)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon(boolean open) {
|
||||
return JetIconProvider.INSTANCE.getIcon(function, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2000-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.JetNamedFunction;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public class JetAllShortFunctionNameIndex extends StringStubIndexExtension<JetNamedFunction> {
|
||||
private static final JetShortClassNameIndex ourInstance = new JetShortClassNameIndex();
|
||||
public static JetShortClassNameIndex getInstance() {
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public StubIndexKey<String, JetNamedFunction> getKey() {
|
||||
return JetIndexKeys.FUNCTIONS_SHORT_NAME_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<JetNamedFunction> get(final String s, final Project project, @NotNull final GlobalSearchScope scope) {
|
||||
return super.get(s, project, new JetSourceFilterScope(scope));
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.jet.plugin.stubindex;
|
||||
|
||||
import com.intellij.psi.stubs.StringStubIndexExtension;
|
||||
import com.intellij.psi.stubs.StubIndexKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
|
||||
/**
|
||||
@@ -30,6 +31,7 @@ public class JetExtensionFunctionNameIndex extends StringStubIndexExtension<JetN
|
||||
return instance;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public StubIndexKey<String, JetNamedFunction> getKey() {
|
||||
return JetIndexKeys.EXTENSION_FUNCTION_SHORT_NAME_KEY;
|
||||
|
||||
@@ -35,6 +35,7 @@ public class JetFullClassNameIndex extends StringStubIndexExtension<JetClassOrOb
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public StubIndexKey<String, JetClassOrObject> getKey() {
|
||||
return JetIndexKeys.FQN_KEY;
|
||||
|
||||
@@ -32,5 +32,7 @@ public interface JetIndexKeys {
|
||||
|
||||
StubIndexKey<String, JetNamedFunction> EXTENSION_FUNCTION_SHORT_NAME_KEY = StubIndexKey.createIndexKey("jet.top.level.extension.function.short.name");
|
||||
StubIndexKey<String, JetNamedFunction> EXTENSION_FUNCTION_FQNAME_KEY = StubIndexKey.createIndexKey("jet.top.level.extension.function.fqname");
|
||||
|
||||
StubIndexKey<String, JetNamedFunction> FUNCTIONS_SHORT_NAME_KEY = StubIndexKey.createIndexKey("jet.functions.short.name");
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ public class JetShortClassNameIndex extends StringStubIndexExtension<JetClassOrO
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public StubIndexKey<String, JetClassOrObject> getKey() {
|
||||
return JetIndexKeys.SHORT_NAME_KEY;
|
||||
|
||||
@@ -35,6 +35,7 @@ public class JetShortFunctionNameIndex extends StringStubIndexExtension<JetNamed
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public StubIndexKey<String, JetNamedFunction> getKey() {
|
||||
return JetIndexKeys.TOP_LEVEL_FUNCTION_SHORT_NAME_KEY;
|
||||
|
||||
@@ -53,6 +53,8 @@ public class StubIndexServiceImpl implements StubIndexService {
|
||||
// sink.occurrence(JetIndexKeys.EXTENSION_FUNCTION_FQNAME_KEY, name);
|
||||
}
|
||||
}
|
||||
|
||||
sink.occurrence(JetIndexKeys.FUNCTIONS_SHORT_NAME_KEY, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user