Fix goto class action in Idea 13.1
This commit is contained in:
@@ -17,6 +17,8 @@
|
|||||||
package org.jetbrains.jet.lang.psi;
|
package org.jetbrains.jet.lang.psi;
|
||||||
|
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
|
import com.intellij.navigation.ItemPresentation;
|
||||||
|
import com.intellij.navigation.ItemPresentationProviders;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.stubs.IStubElementType;
|
import com.intellij.psi.stubs.IStubElementType;
|
||||||
import com.intellij.util.IncorrectOperationException;
|
import com.intellij.util.IncorrectOperationException;
|
||||||
@@ -181,8 +183,8 @@ public class JetObjectDeclaration extends JetNamedDeclarationStub<PsiJetObjectSt
|
|||||||
JetPsiUtil.deleteClass(this);
|
JetPsiUtil.deleteClass(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Override
|
@Override
|
||||||
//public ItemPresentation getPresentation() {
|
public ItemPresentation getPresentation() {
|
||||||
// return ItemPresentationProviders.getItemPresentation(this);
|
return ItemPresentationProviders.getItemPresentation(this);
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -295,7 +295,8 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testClass(javaClass<AbstractKotlinGotoTest>()) {
|
testClass(javaClass<AbstractKotlinGotoTest>()) {
|
||||||
model("navigation/gotoSymbol")
|
model("navigation/gotoClass", testMethod = "doClassTest")
|
||||||
|
model("navigation/gotoSymbol", testMethod = "doSymbolTest")
|
||||||
}
|
}
|
||||||
|
|
||||||
testClass(javaClass<AbstractQuickFixMultiFileTest>()) {
|
testClass(javaClass<AbstractQuickFixMultiFileTest>()) {
|
||||||
|
|||||||
@@ -266,6 +266,8 @@
|
|||||||
forClass="org.jetbrains.jet.lang.psi.JetNamedFunction"/>
|
forClass="org.jetbrains.jet.lang.psi.JetNamedFunction"/>
|
||||||
<itemPresentationProvider implementationClass="org.jetbrains.jet.plugin.presentation.JetClassPresenter"
|
<itemPresentationProvider implementationClass="org.jetbrains.jet.plugin.presentation.JetClassPresenter"
|
||||||
forClass="org.jetbrains.jet.lang.psi.JetClass"/>
|
forClass="org.jetbrains.jet.lang.psi.JetClass"/>
|
||||||
|
<itemPresentationProvider implementationClass="org.jetbrains.jet.plugin.presentation.JetObjectPresenter"
|
||||||
|
forClass="org.jetbrains.jet.lang.psi.JetObjectDeclaration"/>
|
||||||
<itemPresentationProvider implementationClass="org.jetbrains.jet.plugin.presentation.JetPropertyPresenter"
|
<itemPresentationProvider implementationClass="org.jetbrains.jet.plugin.presentation.JetPropertyPresenter"
|
||||||
forClass="org.jetbrains.jet.lang.psi.JetProperty"/>
|
forClass="org.jetbrains.jet.lang.psi.JetProperty"/>
|
||||||
<itemPresentationProvider implementationClass="org.jetbrains.jet.plugin.presentation.JetParameterPresenter"
|
<itemPresentationProvider implementationClass="org.jetbrains.jet.plugin.presentation.JetParameterPresenter"
|
||||||
|
|||||||
@@ -19,21 +19,15 @@ package org.jetbrains.jet.plugin.caches;
|
|||||||
import com.intellij.navigation.GotoClassContributor;
|
import com.intellij.navigation.GotoClassContributor;
|
||||||
import com.intellij.navigation.NavigationItem;
|
import com.intellij.navigation.NavigationItem;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.psi.PsiClass;
|
|
||||||
import com.intellij.psi.search.GlobalSearchScope;
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
import com.intellij.psi.search.PsiShortNamesCache;
|
|
||||||
import com.intellij.util.ArrayUtil;
|
import com.intellij.util.ArrayUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.psi.JetClass;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetNamedDeclaration;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
import org.jetbrains.jet.plugin.stubindex.JetShortClassNameIndex;
|
import org.jetbrains.jet.plugin.stubindex.JetShortClassNameIndex;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class JetGotoClassContributor implements GotoClassContributor {
|
public class JetGotoClassContributor implements GotoClassContributor {
|
||||||
@@ -71,24 +65,9 @@ public class JetGotoClassContributor implements GotoClassContributor {
|
|||||||
return NavigationItem.EMPTY_NAVIGATION_ITEM_ARRAY;
|
return NavigationItem.EMPTY_NAVIGATION_ITEM_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
PsiClass[] classes = PsiShortNamesCache.getInstance(project).getClassesByName(name, scope);
|
|
||||||
Collection<String> javaQualifiedNames = new HashSet<String>();
|
|
||||||
for (PsiClass aClass : classes) {
|
|
||||||
String qualifiedName = aClass.getQualifiedName();
|
|
||||||
if (qualifiedName != null) {
|
|
||||||
javaQualifiedNames.add(qualifiedName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
List<NavigationItem> items = new ArrayList<NavigationItem>();
|
List<NavigationItem> items = new ArrayList<NavigationItem>();
|
||||||
for (JetClassOrObject classOrObject : classesOrObjects) {
|
for (JetClassOrObject classOrObject : classesOrObjects) {
|
||||||
FqName fqName = JetPsiUtil.getFQName(classOrObject);
|
if (classOrObject != null && !(classOrObject instanceof JetEnumEntry)) {
|
||||||
if (fqName == null || javaQualifiedNames.contains(fqName.toString())) {
|
|
||||||
// Elements will be added by Java class contributor
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (classOrObject instanceof JetClass) {
|
|
||||||
items.add(classOrObject);
|
items.add(classOrObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 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.JetObjectDeclaration;
|
||||||
|
|
||||||
|
public class JetObjectPresenter implements ItemPresentationProvider<JetObjectDeclaration> {
|
||||||
|
@Override
|
||||||
|
public ItemPresentation getPresentation(JetObjectDeclaration item) {
|
||||||
|
return new JetDefaultNamedDeclarationPresentation(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package some.small
|
||||||
|
|
||||||
|
public enum class EnumClass {
|
||||||
|
EnumClassTrue
|
||||||
|
EnumClassFalse
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that enum class present but entries are not
|
||||||
|
|
||||||
|
// SEARCH_TEXT: EnumClass
|
||||||
|
// REF: (some.small).EnumClass
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
class InClassObject {
|
||||||
|
class object {
|
||||||
|
class ClassObjectClass {}
|
||||||
|
|
||||||
|
trait ClassObjectTrait {}
|
||||||
|
|
||||||
|
trait ClassObjectTraitWithImpl {
|
||||||
|
fun foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
object ClassObjectObject() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SEARCH_TEXT: ClassObject
|
||||||
|
// REF: (test.InClassObject).ClassObjectClass
|
||||||
|
// REF: (test.InClassObject).ClassObjectObject
|
||||||
|
// REF: (test.InClassObject).ClassObjectTrait
|
||||||
|
// REF: (test.InClassObject).ClassObjectTraitWithImpl
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package small
|
||||||
|
|
||||||
|
class A {
|
||||||
|
class InnerA {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SEARCH_TEXT: Inner
|
||||||
|
// REF: (small.A).InnerA
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
fun foo() {
|
||||||
|
class LocalClass {}
|
||||||
|
|
||||||
|
trait LocalTrait {}
|
||||||
|
|
||||||
|
trait LocalTraitWithImpl {
|
||||||
|
fun foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
object LocalObject() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SEARCH_TEXT: Local
|
||||||
|
// REF: LocalClass
|
||||||
|
// REF: LocalObject
|
||||||
|
// REF: LocalTrait
|
||||||
|
// REF: LocalTraitWithImpl
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
trait NoImplementationTrait {
|
||||||
|
fun foo(): Int
|
||||||
|
fun some(): String
|
||||||
|
}
|
||||||
|
|
||||||
|
// SEARCH_TEXT: NoImplemen
|
||||||
|
// REF: (test).NoImplementationTrait
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
class SimpleClass
|
||||||
|
|
||||||
|
// SEARCH_TEXT: SimpleClass
|
||||||
|
// REF: (<root>).SimpleClass
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
object SimpleObject {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// SEARCH_TEXT: SimpleObject
|
||||||
|
// REF: (<root>).SimpleObject
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
trait TraitWithFunImplement {
|
||||||
|
fun foo(): Int {
|
||||||
|
return 12;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SEARCH_TEXT: Trait
|
||||||
|
// REF: (test).TraitWithFunImplement
|
||||||
@@ -19,7 +19,10 @@ package org.jetbrains.jet.plugin.navigation;
|
|||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Ordering;
|
import com.google.common.collect.Ordering;
|
||||||
|
import com.intellij.ide.util.gotoByName.FilteringGotoByModel;
|
||||||
|
import com.intellij.ide.util.gotoByName.GotoClassModel2;
|
||||||
import com.intellij.ide.util.gotoByName.GotoSymbolModel2;
|
import com.intellij.ide.util.gotoByName.GotoSymbolModel2;
|
||||||
|
import com.intellij.lang.Language;
|
||||||
import com.intellij.openapi.editor.Editor;
|
import com.intellij.openapi.editor.Editor;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
@@ -37,9 +40,14 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class AbstractKotlinGotoTest extends JetLightCodeInsightFixtureTestCase {
|
public abstract class AbstractKotlinGotoTest extends JetLightCodeInsightFixtureTestCase {
|
||||||
protected void doTest(String path) {
|
protected void doSymbolTest(String path) {
|
||||||
myFixture.configureByFile(path);
|
myFixture.configureByFile(path);
|
||||||
assertGotoSymbol(getProject(), myFixture.getEditor());
|
assertGotoSymbol(new GotoSymbolModel2(getProject()), getProject(), myFixture.getEditor());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doClassTest(String path) {
|
||||||
|
myFixture.configureByFile(path);
|
||||||
|
assertGotoSymbol(new GotoClassModel2(getProject()), getProject(), myFixture.getEditor());
|
||||||
}
|
}
|
||||||
|
|
||||||
private String dirPath = null;
|
private String dirPath = null;
|
||||||
@@ -68,7 +76,7 @@ public abstract class AbstractKotlinGotoTest extends JetLightCodeInsightFixtureT
|
|||||||
return getTestName(true) + ".kt";
|
return getTestName(true) + ".kt";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertGotoSymbol(@NotNull Project project, @NotNull Editor editor) {
|
private static void assertGotoSymbol(FilteringGotoByModel<Language> model, @NotNull Project project, @NotNull Editor editor) {
|
||||||
List<String> searchTextList = InTextDirectivesUtils.findListWithPrefixes(editor.getDocument().getText(), "// SEARCH_TEXT:");
|
List<String> searchTextList = InTextDirectivesUtils.findListWithPrefixes(editor.getDocument().getText(), "// SEARCH_TEXT:");
|
||||||
Assert.assertFalse("There's no search text in test data file given. Use '// SEARCH_TEXT:' directive",
|
Assert.assertFalse("There's no search text in test data file given. Use '// SEARCH_TEXT:' directive",
|
||||||
searchTextList.isEmpty());
|
searchTextList.isEmpty());
|
||||||
@@ -80,7 +88,6 @@ public abstract class AbstractKotlinGotoTest extends JetLightCodeInsightFixtureT
|
|||||||
|
|
||||||
List<Object> elementsByName = new ArrayList<Object>();
|
List<Object> elementsByName = new ArrayList<Object>();
|
||||||
|
|
||||||
GotoSymbolModel2 model = new GotoSymbolModel2(project);
|
|
||||||
String[] names = model.getNames(enableCheckbox);
|
String[] names = model.getNames(enableCheckbox);
|
||||||
for (String name : names) {
|
for (String name : names) {
|
||||||
if (name != null && name.startsWith(searchText)) {
|
if (name != null && name.startsWith(searchText)) {
|
||||||
|
|||||||
@@ -30,25 +30,83 @@ import org.jetbrains.jet.plugin.navigation.AbstractKotlinGotoTest;
|
|||||||
|
|
||||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
@TestMetadata("idea/testData/navigation/gotoSymbol")
|
@InnerTestClasses({KotlinGotoTestGenerated.GotoClass.class, KotlinGotoTestGenerated.GotoSymbol.class})
|
||||||
public class KotlinGotoTestGenerated extends AbstractKotlinGotoTest {
|
public class KotlinGotoTestGenerated extends AbstractKotlinGotoTest {
|
||||||
|
@TestMetadata("idea/testData/navigation/gotoClass")
|
||||||
|
public static class GotoClass extends AbstractKotlinGotoTest {
|
||||||
|
public void testAllFilesPresentInGotoClass() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/navigation/gotoClass"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("enumEntries.kt")
|
||||||
|
public void testEnumEntries() throws Exception {
|
||||||
|
doClassTest("idea/testData/navigation/gotoClass/enumEntries.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inClassObject.kt")
|
||||||
|
public void testInClassObject() throws Exception {
|
||||||
|
doClassTest("idea/testData/navigation/gotoClass/inClassObject.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("innerClass.kt")
|
||||||
|
public void testInnerClass() throws Exception {
|
||||||
|
doClassTest("idea/testData/navigation/gotoClass/innerClass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("localDeclarations.kt")
|
||||||
|
public void testLocalDeclarations() throws Exception {
|
||||||
|
doClassTest("idea/testData/navigation/gotoClass/localDeclarations.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noImplementationTrait.kt")
|
||||||
|
public void testNoImplementationTrait() throws Exception {
|
||||||
|
doClassTest("idea/testData/navigation/gotoClass/noImplementationTrait.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("simpleClass.kt")
|
||||||
|
public void testSimpleClass() throws Exception {
|
||||||
|
doClassTest("idea/testData/navigation/gotoClass/simpleClass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("simpleObject.kt")
|
||||||
|
public void testSimpleObject() throws Exception {
|
||||||
|
doClassTest("idea/testData/navigation/gotoClass/simpleObject.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("traitWithFunImplement.kt")
|
||||||
|
public void testTraitWithFunImplement() throws Exception {
|
||||||
|
doClassTest("idea/testData/navigation/gotoClass/traitWithFunImplement.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/navigation/gotoSymbol")
|
||||||
|
public static class GotoSymbol extends AbstractKotlinGotoTest {
|
||||||
public void testAllFilesPresentInGotoSymbol() throws Exception {
|
public void testAllFilesPresentInGotoSymbol() throws Exception {
|
||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/navigation/gotoSymbol"), Pattern.compile("^(.+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/navigation/gotoSymbol"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("functions.kt")
|
@TestMetadata("functions.kt")
|
||||||
public void testFunctions() throws Exception {
|
public void testFunctions() throws Exception {
|
||||||
doTest("idea/testData/navigation/gotoSymbol/functions.kt");
|
doSymbolTest("idea/testData/navigation/gotoSymbol/functions.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("javaMethods.kt")
|
@TestMetadata("javaMethods.kt")
|
||||||
public void testJavaMethods() throws Exception {
|
public void testJavaMethods() throws Exception {
|
||||||
doTest("idea/testData/navigation/gotoSymbol/javaMethods.kt");
|
doSymbolTest("idea/testData/navigation/gotoSymbol/javaMethods.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("properties.kt")
|
@TestMetadata("properties.kt")
|
||||||
public void testProperties() throws Exception {
|
public void testProperties() throws Exception {
|
||||||
doTest("idea/testData/navigation/gotoSymbol/properties.kt");
|
doSymbolTest("idea/testData/navigation/gotoSymbol/properties.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suite() {
|
||||||
|
TestSuite suite = new TestSuite("KotlinGotoTestGenerated");
|
||||||
|
suite.addTestSuite(GotoClass.class);
|
||||||
|
suite.addTestSuite(GotoSymbol.class);
|
||||||
|
return suite;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user