diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedFunction.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedFunction.java index 57c3c6f8e8a..7778c2e6834 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedFunction.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamedFunction.java @@ -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); + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java index 7471c18236a..0fdace281de 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java @@ -33,7 +33,7 @@ import java.io.IOException; * @author Nikolay Krasko */ public class JetFileElementType extends IStubFileElementType { - public static final int STUB_VERSION = 2; + public static final int STUB_VERSION = 3; public JetFileElementType() { super("jet.FILE", JetLanguage.INSTANCE); diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 743a36840fb..4d339d8b8c9 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -64,9 +64,7 @@ - @@ -139,6 +137,7 @@ + @@ -152,6 +151,7 @@ + diff --git a/idea/src/org/jetbrains/jet/plugin/JetIconProvider.java b/idea/src/org/jetbrains/jet/plugin/JetIconProvider.java index 8f215a5a3db..73138b780b2 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetIconProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/JetIconProvider.java @@ -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) { diff --git a/idea/src/org/jetbrains/jet/plugin/caches/GotoSymbolContributor.java b/idea/src/org/jetbrains/jet/plugin/caches/GotoSymbolContributor.java new file mode 100644 index 00000000000..2001717f71a --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/caches/GotoSymbolContributor.java @@ -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 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 functions = StubIndex.getInstance().get( + JetIndexKeys.FUNCTIONS_SHORT_NAME_KEY, name, project, scope); + + final List items = new ArrayList(functions); + return ArrayUtil.toObjectArray(items, NavigationItem.class); + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/presentation/JetFunctionPresenter.java b/idea/src/org/jetbrains/jet/plugin/presentation/JetFunctionPresenter.java new file mode 100644 index 00000000000..4b9ec03433f --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/presentation/JetFunctionPresenter.java @@ -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 { + @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); + } + }; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/stubindex/JetAllShortFunctionNameIndex.java b/idea/src/org/jetbrains/jet/plugin/stubindex/JetAllShortFunctionNameIndex.java new file mode 100644 index 00000000000..561e1d1d41d --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/stubindex/JetAllShortFunctionNameIndex.java @@ -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 { + private static final JetShortClassNameIndex ourInstance = new JetShortClassNameIndex(); + public static JetShortClassNameIndex getInstance() { + return ourInstance; + } + + @NotNull + @Override + public StubIndexKey getKey() { + return JetIndexKeys.FUNCTIONS_SHORT_NAME_KEY; + } + + @Override + public Collection get(final String s, final Project project, @NotNull final GlobalSearchScope scope) { + return super.get(s, project, new JetSourceFilterScope(scope)); + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/stubindex/JetExtensionFunctionNameIndex.java b/idea/src/org/jetbrains/jet/plugin/stubindex/JetExtensionFunctionNameIndex.java index ddd772d11a0..0b66b2db7c5 100644 --- a/idea/src/org/jetbrains/jet/plugin/stubindex/JetExtensionFunctionNameIndex.java +++ b/idea/src/org/jetbrains/jet/plugin/stubindex/JetExtensionFunctionNameIndex.java @@ -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 getKey() { return JetIndexKeys.EXTENSION_FUNCTION_SHORT_NAME_KEY; diff --git a/idea/src/org/jetbrains/jet/plugin/stubindex/JetFullClassNameIndex.java b/idea/src/org/jetbrains/jet/plugin/stubindex/JetFullClassNameIndex.java index 3428ec42242..ac1f2a20539 100644 --- a/idea/src/org/jetbrains/jet/plugin/stubindex/JetFullClassNameIndex.java +++ b/idea/src/org/jetbrains/jet/plugin/stubindex/JetFullClassNameIndex.java @@ -35,6 +35,7 @@ public class JetFullClassNameIndex extends StringStubIndexExtension getKey() { return JetIndexKeys.FQN_KEY; diff --git a/idea/src/org/jetbrains/jet/plugin/stubindex/JetIndexKeys.java b/idea/src/org/jetbrains/jet/plugin/stubindex/JetIndexKeys.java index ecf5d2d1377..90e94f197f7 100644 --- a/idea/src/org/jetbrains/jet/plugin/stubindex/JetIndexKeys.java +++ b/idea/src/org/jetbrains/jet/plugin/stubindex/JetIndexKeys.java @@ -32,5 +32,7 @@ public interface JetIndexKeys { StubIndexKey EXTENSION_FUNCTION_SHORT_NAME_KEY = StubIndexKey.createIndexKey("jet.top.level.extension.function.short.name"); StubIndexKey EXTENSION_FUNCTION_FQNAME_KEY = StubIndexKey.createIndexKey("jet.top.level.extension.function.fqname"); + + StubIndexKey FUNCTIONS_SHORT_NAME_KEY = StubIndexKey.createIndexKey("jet.functions.short.name"); } diff --git a/idea/src/org/jetbrains/jet/plugin/stubindex/JetShortClassNameIndex.java b/idea/src/org/jetbrains/jet/plugin/stubindex/JetShortClassNameIndex.java index d099fb94c5d..7821d2eaefe 100644 --- a/idea/src/org/jetbrains/jet/plugin/stubindex/JetShortClassNameIndex.java +++ b/idea/src/org/jetbrains/jet/plugin/stubindex/JetShortClassNameIndex.java @@ -34,6 +34,7 @@ public class JetShortClassNameIndex extends StringStubIndexExtension getKey() { return JetIndexKeys.SHORT_NAME_KEY; diff --git a/idea/src/org/jetbrains/jet/plugin/stubindex/JetShortFunctionNameIndex.java b/idea/src/org/jetbrains/jet/plugin/stubindex/JetShortFunctionNameIndex.java index 2e5a4cdae0b..481d100633e 100644 --- a/idea/src/org/jetbrains/jet/plugin/stubindex/JetShortFunctionNameIndex.java +++ b/idea/src/org/jetbrains/jet/plugin/stubindex/JetShortFunctionNameIndex.java @@ -35,6 +35,7 @@ public class JetShortFunctionNameIndex extends StringStubIndexExtension getKey() { return JetIndexKeys.TOP_LEVEL_FUNCTION_SHORT_NAME_KEY; diff --git a/idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java b/idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java index 923efa85391..81a889f7453 100644 --- a/idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java +++ b/idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java @@ -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); } } }