Rework go to symbol/class and getNavigationElement() for kotlin declarations
Based on work by geevee
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.stubs.IStubElementType;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
@@ -50,4 +51,17 @@ abstract class JetDeclarationStub<T extends StubElement> extends JetModifierList
|
||||
}
|
||||
return super.getParent();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElement getNavigationElement() {
|
||||
KotlinDeclarationNavigationPolicy navigationPolicy = ServiceManager.getService(KotlinDeclarationNavigationPolicy.class);
|
||||
if (navigationPolicy != null) {
|
||||
JetElement navigationElement = navigationPolicy.getNavigationElement(this);
|
||||
if (navigationElement != null) {
|
||||
return navigationElement;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.lang.psi
|
||||
|
||||
public trait KotlinDeclarationNavigationPolicy {
|
||||
public fun getNavigationElement(declaration: JetDeclaration): JetElement?
|
||||
}
|
||||
+1
-1
@@ -67,7 +67,7 @@ public object DescriptorToDeclarationUtil {
|
||||
return elements
|
||||
}
|
||||
|
||||
val decompiledDeclaration = DecompiledNavigationUtils.findDeclarationForReference(project, descriptor)
|
||||
val decompiledDeclaration = DecompiledNavigationUtils.getDeclarationFromDecompiledClassFile(project, descriptor)
|
||||
if (decompiledDeclaration != null) {
|
||||
return setOf(decompiledDeclaration)
|
||||
}
|
||||
|
||||
+1
-16
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.decompiler.navigation;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
@@ -38,22 +37,8 @@ import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getFqName;
|
||||
|
||||
public final class DecompiledNavigationUtils {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(DecompiledNavigationUtils.class);
|
||||
|
||||
@Nullable
|
||||
public static JetDeclaration findDeclarationForReference(
|
||||
@NotNull Project project,
|
||||
@NotNull DeclarationDescriptor referencedDescriptor
|
||||
) {
|
||||
JetDeclaration declarationFromDecompiledClassFile = getDeclarationFromDecompiledClassFile(project, referencedDescriptor);
|
||||
if (declarationFromDecompiledClassFile == null) {
|
||||
return null;
|
||||
}
|
||||
return JetSourceNavigationHelper.replaceBySourceDeclarationIfPresent(declarationFromDecompiledClassFile);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JetDeclaration getDeclarationFromDecompiledClassFile(
|
||||
public static JetDeclaration getDeclarationFromDecompiledClassFile(
|
||||
@NotNull Project project,
|
||||
@NotNull DeclarationDescriptor referencedDescriptor
|
||||
) {
|
||||
|
||||
+4
@@ -204,6 +204,10 @@ public class JetSourceNavigationHelper {
|
||||
+ decompiledContainer.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
if (candidates.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!forceResolve) {
|
||||
candidates = filterByReceiverPresenceAndParametersCount(decompiledDeclaration, candidates);
|
||||
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.decompiler.navigation
|
||||
|
||||
import org.jetbrains.jet.lang.psi.KotlinDeclarationNavigationPolicy
|
||||
import org.jetbrains.jet.lang.psi.JetElement
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration
|
||||
import com.intellij.openapi.project.DumbService
|
||||
|
||||
public class KotlinDeclarationNavigationPolicyImpl : KotlinDeclarationNavigationPolicy {
|
||||
override fun getNavigationElement(declaration: JetDeclaration): JetElement? {
|
||||
if (DumbService.isDumb(declaration.getProject())) {
|
||||
return null
|
||||
}
|
||||
if (declaration.getContainingJetFile().isCompiled()) {
|
||||
return JetSourceNavigationHelper.replaceBySourceDeclarationIfPresent(declaration)
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -147,9 +147,13 @@
|
||||
|
||||
<applicationService serviceInterface="org.jetbrains.jet.plugin.configuration.JetModuleTypeManager"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.JetModuleTypeManagerImpl"/>
|
||||
|
||||
<applicationService serviceInterface="org.jetbrains.jet.plugin.quickfix.ImportInsertHelper"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.quickfix.ImportInsertHelperImpl"/>
|
||||
|
||||
<applicationService serviceInterface="org.jetbrains.jet.lang.psi.KotlinDeclarationNavigationPolicy"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.decompiler.navigation.KotlinDeclarationNavigationPolicyImpl"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.jet.plugin.caches.resolve.KotlinCacheService"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.caches.resolve.KotlinCacheService"/>
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.psi.JetEnumEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedDeclaration;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetClassShortNameIndex;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetSourceFilterScope;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -61,7 +62,8 @@ public class JetGotoClassContributor implements GotoClassContributor {
|
||||
@Override
|
||||
public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) {
|
||||
GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
|
||||
Collection<JetClassOrObject> classesOrObjects = JetClassShortNameIndex.getInstance().get(name, project, scope);
|
||||
Collection<JetClassOrObject> classesOrObjects =
|
||||
JetClassShortNameIndex.getInstance().get(name, project, JetSourceFilterScope.kotlinSourceAndClassFiles(scope, project));
|
||||
|
||||
if (classesOrObjects.isEmpty()) {
|
||||
return NavigationItem.EMPTY_NAVIGATION_ITEM_ARRAY;
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetFunctionShortNameIndex;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetPropertyShortNameIndex;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetSourceFilterScope;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -45,10 +46,11 @@ public class JetGotoSymbolContributor implements ChooseByNameContributor {
|
||||
@NotNull
|
||||
@Override
|
||||
public NavigationItem[] getItemsByName(String name, String pattern, Project project, boolean includeNonProjectItems) {
|
||||
GlobalSearchScope scope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
|
||||
GlobalSearchScope baseScope = includeNonProjectItems ? GlobalSearchScope.allScope(project) : GlobalSearchScope.projectScope(project);
|
||||
GlobalSearchScope noLibrarySourceScope = JetSourceFilterScope.kotlinSourceAndClassFiles(baseScope, project);
|
||||
|
||||
Collection<? extends NavigationItem> functions = JetFunctionShortNameIndex.getInstance().get(name, project, scope);
|
||||
Collection<? extends NavigationItem> properties = JetPropertyShortNameIndex.getInstance().get(name, project, scope);
|
||||
Collection<? extends NavigationItem> functions = JetFunctionShortNameIndex.getInstance().get(name, project, noLibrarySourceScope);
|
||||
Collection<? extends NavigationItem> properties = JetPropertyShortNameIndex.getInstance().get(name, project, noLibrarySourceScope);
|
||||
|
||||
List<NavigationItem> items = new ArrayList<NavigationItem>(Collections2.filter(functions, Predicates.notNull()));
|
||||
items.addAll(properties);
|
||||
|
||||
@@ -2,4 +2,3 @@
|
||||
// CHECK_BOX
|
||||
// SEARCH_TEXT: arrayListOf
|
||||
// REF: (in kotlin).arrayListOf(T)
|
||||
// REF: (in kotlin.KotlinPackage).arrayListOf(T...)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// RUNTIME
|
||||
// CHECK_BOX
|
||||
// SEARCH_TEXT: arrayListOf
|
||||
// REF: (in kotlin.KotlinPackage).arrayListOf(T...)
|
||||
// REF: (in kotlin).arrayListOf(T)
|
||||
|
||||
@@ -11,26 +11,4 @@
|
||||
// REF: (for Iterable<T> in kotlin).joinToString(String,String,String,Int,String)
|
||||
// REF: (for LongArray in kotlin).joinToString(String,String,String,Int,String)
|
||||
// REF: (for ShortArray in kotlin).joinToString(String,String,String,Int,String)
|
||||
// REF: (for Stream<T> in kotlin).joinToString(String,String,String,Int,String)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString$default(Iterable, String, String, String, int, String, int)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString$default(Object[], String, String, String, int, String, int)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString$default(Stream, String, String, String, int, String, int)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString$default(boolean[], String, String, String, int, String, int)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString$default(byte[], String, String, String, int, String, int)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString$default(char[], String, String, String, int, String, int)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString$default(double[], String, String, String, int, String, int)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString$default(float[], String, String, String, int, String, int)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString$default(int[], String, String, String, int, String, int)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString$default(long[], String, String, String, int, String, int)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString$default(short[], String, String, String, int, String, int)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString(Iterable<? extends T>, String, String, String, int, String)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString(Stream<? extends T>, String, String, String, int, String)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString(T[], String, String, String, int, String)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString(boolean[], String, String, String, int, String)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString(byte[], String, String, String, int, String)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString(char[], String, String, String, int, String)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString(double[], String, String, String, int, String)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString(float[], String, String, String, int, String)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString(int[], String, String, String, int, String)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString(long[], String, String, String, int, String)
|
||||
// REF: (in kotlin.KotlinPackage).joinToString(short[], String, String, String, int, String)
|
||||
// REF: (for Stream<T> in kotlin).joinToString(String,String,String,Int,String)
|
||||
Reference in New Issue
Block a user