Navigation: Implement proper getOriginalElement() for Kotlin declarations.
Run find usages tests with library for both original and navigation elements. Drop duplicating tests. Simplify test class. TODO: Some usages are not found yet since light methods built from library files do not retain original declarations
This commit is contained in:
@@ -52,16 +52,16 @@ abstract class JetDeclarationStub<T extends StubElement> extends JetModifierList
|
|||||||
return super.getParent();
|
return super.getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PsiElement getOriginalElement() {
|
||||||
|
KotlinDeclarationNavigationPolicy navigationPolicy = ServiceManager.getService(KotlinDeclarationNavigationPolicy.class);
|
||||||
|
return navigationPolicy != null ? navigationPolicy.getOriginalElement(this) : this;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public PsiElement getNavigationElement() {
|
public PsiElement getNavigationElement() {
|
||||||
KotlinDeclarationNavigationPolicy navigationPolicy = ServiceManager.getService(KotlinDeclarationNavigationPolicy.class);
|
KotlinDeclarationNavigationPolicy navigationPolicy = ServiceManager.getService(KotlinDeclarationNavigationPolicy.class);
|
||||||
if (navigationPolicy != null) {
|
return navigationPolicy != null ? navigationPolicy.getNavigationElement(this) : this;
|
||||||
JetElement navigationElement = navigationPolicy.getNavigationElement(this);
|
|
||||||
if (navigationElement != null) {
|
|
||||||
return navigationElement;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.psi
|
package org.jetbrains.kotlin.psi
|
||||||
|
|
||||||
public trait KotlinDeclarationNavigationPolicy {
|
public interface KotlinDeclarationNavigationPolicy {
|
||||||
public fun getNavigationElement(declaration: JetDeclaration): JetElement?
|
public fun getOriginalElement(declaration: JetDeclaration): JetElement
|
||||||
|
public fun getNavigationElement(declaration: JetDeclaration): JetElement
|
||||||
}
|
}
|
||||||
|
|||||||
+107
-104
@@ -19,8 +19,11 @@ package org.jetbrains.kotlin.idea.decompiler.navigation;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellij.openapi.module.Module;
|
import com.intellij.openapi.module.Module;
|
||||||
|
import com.intellij.openapi.project.DumbService;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.roots.*;
|
import com.intellij.openapi.roots.OrderEntry;
|
||||||
|
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||||
|
import com.intellij.openapi.roots.ProjectRootManager;
|
||||||
import com.intellij.openapi.util.Condition;
|
import com.intellij.openapi.util.Condition;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import com.intellij.psi.JavaPsiFacade;
|
import com.intellij.psi.JavaPsiFacade;
|
||||||
@@ -31,7 +34,6 @@ import com.intellij.psi.search.GlobalSearchScope;
|
|||||||
import com.intellij.psi.stubs.StringStubIndexExtension;
|
import com.intellij.psi.stubs.StringStubIndexExtension;
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import gnu.trove.THashSet;
|
import gnu.trove.THashSet;
|
||||||
import kotlin.KotlinPackage;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.annotations.TestOnly;
|
import org.jetbrains.annotations.TestOnly;
|
||||||
@@ -44,8 +46,10 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
|||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.kotlin.di.InjectorForLazyResolve;
|
import org.jetbrains.kotlin.di.InjectorForLazyResolve;
|
||||||
import org.jetbrains.kotlin.idea.stubindex.JetFullClassNameIndex;
|
import org.jetbrains.kotlin.idea.stubindex.JetFullClassNameIndex;
|
||||||
|
import org.jetbrains.kotlin.idea.stubindex.JetSourceFilterScope;
|
||||||
import org.jetbrains.kotlin.idea.stubindex.JetTopLevelFunctionFqnNameIndex;
|
import org.jetbrains.kotlin.idea.stubindex.JetTopLevelFunctionFqnNameIndex;
|
||||||
import org.jetbrains.kotlin.idea.stubindex.JetTopLevelPropertyFqnNameIndex;
|
import org.jetbrains.kotlin.idea.stubindex.JetTopLevelPropertyFqnNameIndex;
|
||||||
|
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil;
|
||||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||||
import org.jetbrains.kotlin.name.ClassId;
|
import org.jetbrains.kotlin.name.ClassId;
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
@@ -72,39 +76,34 @@ import static org.jetbrains.kotlin.descriptors.DescriptorsPackage.ModuleParamete
|
|||||||
import static org.jetbrains.kotlin.idea.decompiler.navigation.MemberMatching.*;
|
import static org.jetbrains.kotlin.idea.decompiler.navigation.MemberMatching.*;
|
||||||
|
|
||||||
public class JetSourceNavigationHelper {
|
public class JetSourceNavigationHelper {
|
||||||
|
public enum NavigationKind {
|
||||||
|
CLASS_FILES_TO_SOURCES,
|
||||||
|
SOURCES_TO_CLASS_FILES
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean forceResolve = false;
|
private static boolean forceResolve = false;
|
||||||
|
|
||||||
private JetSourceNavigationHelper() {
|
private JetSourceNavigationHelper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static JetClassOrObject getSourceClassOrObject(@NotNull JetClassOrObject decompiledClassOrObject) {
|
|
||||||
return getSourceForNamedClassOrObject(decompiledClassOrObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static GlobalSearchScope createLibrarySourcesScope(@NotNull JetNamedDeclaration decompiledDeclaration) {
|
private static GlobalSearchScope createLibraryOrSourcesScope(
|
||||||
JetFile containingFile = decompiledDeclaration.getContainingJetFile();
|
@NotNull JetNamedDeclaration declaration,
|
||||||
|
@NotNull NavigationKind navigationKind
|
||||||
|
) {
|
||||||
|
JetFile containingFile = declaration.getContainingJetFile();
|
||||||
VirtualFile libraryFile = containingFile.getVirtualFile();
|
VirtualFile libraryFile = containingFile.getVirtualFile();
|
||||||
if (libraryFile == null) {
|
if (libraryFile == null) return GlobalSearchScope.EMPTY_SCOPE;
|
||||||
|
|
||||||
|
boolean includeLibrarySources = navigationKind == NavigationKind.CLASS_FILES_TO_SOURCES;
|
||||||
|
if (ProjectRootsUtil.isInContent(declaration, false, includeLibrarySources, !includeLibrarySources)) {
|
||||||
return GlobalSearchScope.EMPTY_SCOPE;
|
return GlobalSearchScope.EMPTY_SCOPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
Project project = decompiledDeclaration.getProject();
|
Project project = declaration.getProject();
|
||||||
ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(project);
|
return includeLibrarySources
|
||||||
|
? JetSourceFilterScope.kotlinLibrarySources(GlobalSearchScope.allScope(project), project)
|
||||||
if (!projectFileIndex.isInLibraryClasses(libraryFile)) {
|
: JetSourceFilterScope.kotlinLibraryClassFiles(GlobalSearchScope.allScope(project), project);
|
||||||
return GlobalSearchScope.EMPTY_SCOPE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<VirtualFile> sourceRootSet = Sets.newLinkedHashSet();
|
|
||||||
for (OrderEntry entry : projectFileIndex.getOrderEntriesForFile(libraryFile)) {
|
|
||||||
if (entry instanceof LibraryOrSdkOrderEntry) {
|
|
||||||
KotlinPackage.addAll(sourceRootSet, entry.getFiles(OrderRootType.SOURCES));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new LibrarySourcesScope(project, sourceRootSet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<JetFile> getContainingFiles(@NotNull Iterable<JetNamedDeclaration> declarations) {
|
private static List<JetFile> getContainingFiles(@NotNull Iterable<JetNamedDeclaration> declarations) {
|
||||||
@@ -151,35 +150,48 @@ public class JetSourceNavigationHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static JetNamedDeclaration getSourcePropertyOrFunction(@NotNull JetNamedDeclaration decompiledDeclaration) {
|
private static JetNamedDeclaration convertPropertyOrFunction(
|
||||||
String memberNameAsString = decompiledDeclaration.getName();
|
@NotNull JetNamedDeclaration declaration,
|
||||||
|
@NotNull NavigationKind navigationKind
|
||||||
|
) {
|
||||||
|
if (declaration instanceof JetPrimaryConstructor) {
|
||||||
|
JetClassOrObject sourceClassOrObject =
|
||||||
|
convertNamedClassOrObject(((JetPrimaryConstructor) declaration).getContainingClassOrObject(), navigationKind);
|
||||||
|
JetPrimaryConstructor primaryConstructor = sourceClassOrObject != null ? sourceClassOrObject.getPrimaryConstructor() : null;
|
||||||
|
return primaryConstructor != null ? primaryConstructor : sourceClassOrObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
String memberNameAsString = declaration.getName();
|
||||||
assert memberNameAsString != null;
|
assert memberNameAsString != null;
|
||||||
Name memberName = Name.identifier(memberNameAsString);
|
Name memberName = Name.identifier(memberNameAsString);
|
||||||
|
|
||||||
PsiElement decompiledContainer = decompiledDeclaration.getParent();
|
PsiElement decompiledContainer = declaration.getParent();
|
||||||
|
|
||||||
Collection<JetNamedDeclaration> candidates;
|
Collection<JetNamedDeclaration> candidates;
|
||||||
if (decompiledContainer instanceof JetFile) {
|
if (decompiledContainer instanceof JetFile) {
|
||||||
candidates = getInitialTopLevelCandidates(decompiledDeclaration);
|
candidates = getInitialTopLevelCandidates(declaration, navigationKind);
|
||||||
}
|
}
|
||||||
else if (decompiledContainer instanceof JetClassBody) {
|
else if (decompiledContainer instanceof JetClassBody) {
|
||||||
JetClassOrObject decompiledClassOrObject = (JetClassOrObject) decompiledContainer.getParent();
|
JetClassOrObject decompiledClassOrObject = (JetClassOrObject) decompiledContainer.getParent();
|
||||||
JetClassOrObject sourceClassOrObject = getSourceClassOrObject(decompiledClassOrObject);
|
JetClassOrObject sourceClassOrObject = convertNamedClassOrObject(decompiledClassOrObject, navigationKind);
|
||||||
|
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
candidates = sourceClassOrObject == null
|
candidates = sourceClassOrObject == null
|
||||||
? Collections.<JetNamedDeclaration>emptyList()
|
? Collections.<JetNamedDeclaration>emptyList()
|
||||||
: getInitialMemberCandidates(sourceClassOrObject, memberName, (Class<JetNamedDeclaration>) decompiledDeclaration.getClass());
|
: getInitialMemberCandidates(sourceClassOrObject, memberName,
|
||||||
|
(Class<JetNamedDeclaration>) declaration.getClass());
|
||||||
|
|
||||||
if (candidates.isEmpty()) {
|
if (candidates.isEmpty()) {
|
||||||
if (decompiledDeclaration instanceof JetProperty && sourceClassOrObject instanceof JetClass) {
|
if (declaration instanceof JetProperty && sourceClassOrObject instanceof JetClass) {
|
||||||
return findSpecialProperty(memberName, (JetClass) sourceClassOrObject);
|
return findSpecialProperty(memberName, (JetClass) sourceClassOrObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalStateException("Unexpected container of decompiled declaration: "
|
throw new IllegalStateException("Unexpected container of " +
|
||||||
+ decompiledContainer.getClass().getSimpleName());
|
(navigationKind == NavigationKind.CLASS_FILES_TO_SOURCES ? "decompiled" : "source") +
|
||||||
|
" declaration: " +
|
||||||
|
decompiledContainer.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (candidates.isEmpty()) {
|
if (candidates.isEmpty()) {
|
||||||
@@ -187,14 +199,14 @@ public class JetSourceNavigationHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!forceResolve) {
|
if (!forceResolve) {
|
||||||
candidates = filterByReceiverPresenceAndParametersCount(decompiledDeclaration, candidates);
|
candidates = filterByReceiverPresenceAndParametersCount(declaration, candidates);
|
||||||
|
|
||||||
if (candidates.size() <= 1) {
|
if (candidates.size() <= 1) {
|
||||||
return candidates.isEmpty() ? null : candidates.iterator().next();
|
return candidates.isEmpty() ? null : candidates.iterator().next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!haveRenamesInImports(getContainingFiles(candidates))) {
|
if (!haveRenamesInImports(getContainingFiles(candidates))) {
|
||||||
candidates = filterByReceiverAndParameterTypes(decompiledDeclaration, candidates);
|
candidates = filterByReceiverAndParameterTypes(declaration, candidates);
|
||||||
|
|
||||||
if (candidates.size() <= 1) {
|
if (candidates.size() <= 1) {
|
||||||
return candidates.isEmpty() ? null : candidates.iterator().next();
|
return candidates.isEmpty() ? null : candidates.iterator().next();
|
||||||
@@ -202,14 +214,14 @@ public class JetSourceNavigationHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KotlinCodeAnalyzer analyzer = createAnalyzer(candidates, decompiledDeclaration.getProject());
|
KotlinCodeAnalyzer analyzer = createAnalyzer(candidates, declaration.getProject());
|
||||||
|
|
||||||
for (JetNamedDeclaration candidate : candidates) {
|
for (JetNamedDeclaration candidate : candidates) {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
CallableDescriptor candidateDescriptor = (CallableDescriptor) analyzer.resolveToDescriptor(candidate);
|
CallableDescriptor candidateDescriptor = (CallableDescriptor) analyzer.resolveToDescriptor(candidate);
|
||||||
if (receiversMatch(decompiledDeclaration, candidateDescriptor)
|
if (receiversMatch(declaration, candidateDescriptor)
|
||||||
&& valueParametersTypesMatch(decompiledDeclaration, candidateDescriptor)
|
&& valueParametersTypesMatch(declaration, candidateDescriptor)
|
||||||
&& typeParametersMatch((JetTypeParameterListOwner) decompiledDeclaration, candidateDescriptor.getTypeParameters())) {
|
&& typeParametersMatch((JetTypeParameterListOwner) declaration, candidateDescriptor.getTypeParameters())) {
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,16 +262,19 @@ public class JetSourceNavigationHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static JetClassOrObject getSourceForNamedClassOrObject(@NotNull JetClassOrObject decompiledClassOrObject) {
|
private static JetClassOrObject convertNamedClassOrObject(
|
||||||
FqName classFqName = decompiledClassOrObject.getFqName();
|
@NotNull JetClassOrObject classOrObject,
|
||||||
|
@NotNull NavigationKind navigationKind
|
||||||
|
) {
|
||||||
|
FqName classFqName = classOrObject.getFqName();
|
||||||
assert classFqName != null;
|
assert classFqName != null;
|
||||||
|
|
||||||
GlobalSearchScope librarySourcesScope = createLibrarySourcesScope(decompiledClassOrObject);
|
GlobalSearchScope librarySourcesScope = createLibraryOrSourcesScope(classOrObject, navigationKind);
|
||||||
if (librarySourcesScope == GlobalSearchScope.EMPTY_SCOPE) { // .getProject() == null for EMPTY_SCOPE, and this breaks code
|
if (librarySourcesScope == GlobalSearchScope.EMPTY_SCOPE) { // .getProject() == null for EMPTY_SCOPE, and this breaks code
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Collection<JetClassOrObject> classes = JetFullClassNameIndex.getInstance()
|
Collection<JetClassOrObject> classes = JetFullClassNameIndex.getInstance()
|
||||||
.get(classFqName.asString(), decompiledClassOrObject.getProject(), librarySourcesScope);
|
.get(classFqName.asString(), classOrObject.getProject(), librarySourcesScope);
|
||||||
if (classes.isEmpty()) {
|
if (classes.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -267,18 +282,21 @@ public class JetSourceNavigationHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static Collection<JetNamedDeclaration> getInitialTopLevelCandidates(@NotNull JetNamedDeclaration decompiledDeclaration) {
|
private static Collection<JetNamedDeclaration> getInitialTopLevelCandidates(
|
||||||
FqName memberFqName = decompiledDeclaration.getFqName();
|
@NotNull JetNamedDeclaration declaration,
|
||||||
|
@NotNull NavigationKind navigationKind
|
||||||
|
) {
|
||||||
|
FqName memberFqName = declaration.getFqName();
|
||||||
assert memberFqName != null;
|
assert memberFqName != null;
|
||||||
|
|
||||||
GlobalSearchScope librarySourcesScope = createLibrarySourcesScope(decompiledDeclaration);
|
GlobalSearchScope librarySourcesScope = createLibraryOrSourcesScope(declaration, navigationKind);
|
||||||
if (librarySourcesScope == GlobalSearchScope.EMPTY_SCOPE) { // .getProject() == null for EMPTY_SCOPE, and this breaks code
|
if (librarySourcesScope == GlobalSearchScope.EMPTY_SCOPE) { // .getProject() == null for EMPTY_SCOPE, and this breaks code
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
StringStubIndexExtension<JetNamedDeclaration> index =
|
StringStubIndexExtension<JetNamedDeclaration> index =
|
||||||
(StringStubIndexExtension<JetNamedDeclaration>) getIndexForTopLevelPropertyOrFunction(decompiledDeclaration);
|
(StringStubIndexExtension<JetNamedDeclaration>) getIndexForTopLevelPropertyOrFunction(declaration);
|
||||||
return index.get(memberFqName.asString(), decompiledDeclaration.getProject(), librarySourcesScope);
|
return index.get(memberFqName.asString(), declaration.getProject(), librarySourcesScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static StringStubIndexExtension<? extends JetNamedDeclaration> getIndexForTopLevelPropertyOrFunction(
|
private static StringStubIndexExtension<? extends JetNamedDeclaration> getIndexForTopLevelPropertyOrFunction(
|
||||||
@@ -334,16 +352,6 @@ public class JetSourceNavigationHelper {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static JetNamedDeclaration getSourceProperty(@NotNull JetProperty decompiledProperty) {
|
|
||||||
return getSourcePropertyOrFunction(decompiledProperty);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static JetNamedDeclaration getSourceFunction(@NotNull JetFunction decompiledFunction) {
|
|
||||||
return getSourcePropertyOrFunction(decompiledFunction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestOnly
|
@TestOnly
|
||||||
public static void setForceResolve(boolean forceResolve) {
|
public static void setForceResolve(boolean forceResolve) {
|
||||||
JetSourceNavigationHelper.forceResolve = forceResolve;
|
JetSourceNavigationHelper.forceResolve = forceResolve;
|
||||||
@@ -414,30 +422,60 @@ public class JetSourceNavigationHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JetDeclaration replaceBySourceDeclarationIfPresent(@NotNull JetDeclaration original) {
|
public static JetDeclaration getNavigationElement(@NotNull JetDeclaration declaration) {
|
||||||
JetDeclaration sourceElement = original.accept(new SourceForDecompiledExtractingVisitor(), null);
|
return navigateToDeclaration(declaration, NavigationKind.CLASS_FILES_TO_SOURCES);
|
||||||
return sourceElement != null ? sourceElement : original;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SourceForDecompiledExtractingVisitor extends JetVisitor<JetDeclaration, Void> {
|
@NotNull
|
||||||
|
public static JetDeclaration getOriginalElement(@NotNull JetDeclaration declaration) {
|
||||||
|
return navigateToDeclaration(declaration, NavigationKind.SOURCES_TO_CLASS_FILES);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static JetDeclaration navigateToDeclaration(
|
||||||
|
@NotNull JetDeclaration from,
|
||||||
|
@NotNull NavigationKind navigationKind) {
|
||||||
|
if (DumbService.isDumb(from.getProject())) return from;
|
||||||
|
|
||||||
|
switch (navigationKind) {
|
||||||
|
case CLASS_FILES_TO_SOURCES:
|
||||||
|
if (!from.getContainingJetFile().isCompiled()) return from;
|
||||||
|
break;
|
||||||
|
case SOURCES_TO_CLASS_FILES:
|
||||||
|
if (from.getContainingJetFile().isCompiled()) return from;
|
||||||
|
if (JetPsiUtil.isLocal(from)) return from;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
JetDeclaration result = from.accept(new SourceAndDecompiledConversionVisitor(navigationKind), null);
|
||||||
|
return result != null ? result : from;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SourceAndDecompiledConversionVisitor extends JetVisitor<JetDeclaration, Void> {
|
||||||
|
private final NavigationKind navigationKind;
|
||||||
|
|
||||||
|
public SourceAndDecompiledConversionVisitor(@NotNull NavigationKind navigationKind) {
|
||||||
|
this.navigationKind = navigationKind;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetDeclaration visitNamedFunction(@NotNull JetNamedFunction function, Void data) {
|
public JetDeclaration visitNamedFunction(@NotNull JetNamedFunction function, Void data) {
|
||||||
return getSourceFunction(function);
|
return convertPropertyOrFunction(function, navigationKind);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetDeclaration visitProperty(@NotNull JetProperty property, Void data) {
|
public JetDeclaration visitProperty(@NotNull JetProperty property, Void data) {
|
||||||
return getSourceProperty(property);
|
return convertPropertyOrFunction(property, navigationKind);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetDeclaration visitObjectDeclaration(@NotNull JetObjectDeclaration declaration, Void data) {
|
public JetDeclaration visitObjectDeclaration(@NotNull JetObjectDeclaration declaration, Void data) {
|
||||||
return getSourceClassOrObject(declaration);
|
return convertNamedClassOrObject(declaration, navigationKind);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetDeclaration visitClass(@NotNull JetClass klass, Void data) {
|
public JetDeclaration visitClass(@NotNull JetClass klass, Void data) {
|
||||||
return getSourceClassOrObject(klass);
|
return convertNamedClassOrObject(klass, navigationKind);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -455,47 +493,12 @@ public class JetSourceNavigationHelper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetDeclaration visitPrimaryConstructor(@NotNull JetPrimaryConstructor constructor, Void data) {
|
public JetDeclaration visitPrimaryConstructor(@NotNull JetPrimaryConstructor constructor, Void data) {
|
||||||
return getSourceFunction(constructor);
|
return convertPropertyOrFunction(constructor, navigationKind);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetDeclaration visitSecondaryConstructor(@NotNull JetSecondaryConstructor constructor, Void data) {
|
public JetDeclaration visitSecondaryConstructor(@NotNull JetSecondaryConstructor constructor, Void data) {
|
||||||
return getSourceFunction(constructor);
|
return convertPropertyOrFunction(constructor, navigationKind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class LibrarySourcesScope extends GlobalSearchScope {
|
|
||||||
private final Set<VirtualFile> sources;
|
|
||||||
private final ProjectFileIndex fileIndex;
|
|
||||||
|
|
||||||
public LibrarySourcesScope(Project project, Set<VirtualFile> sources) {
|
|
||||||
super(project);
|
|
||||||
fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
|
|
||||||
this.sources = sources;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean contains(@NotNull VirtualFile file) {
|
|
||||||
if (fileIndex.isInLibrarySource(file)) {
|
|
||||||
return sources.contains(fileIndex.getSourceRootForFile(file));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSearchInModuleContent(@NotNull Module aModule) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSearchInLibraries() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-9
@@ -22,13 +22,8 @@ import org.jetbrains.kotlin.psi.JetDeclaration
|
|||||||
import com.intellij.openapi.project.DumbService
|
import com.intellij.openapi.project.DumbService
|
||||||
|
|
||||||
public class KotlinDeclarationNavigationPolicyImpl : KotlinDeclarationNavigationPolicy {
|
public class KotlinDeclarationNavigationPolicyImpl : KotlinDeclarationNavigationPolicy {
|
||||||
override fun getNavigationElement(declaration: JetDeclaration): JetElement? {
|
override fun getOriginalElement(declaration: JetDeclaration) =
|
||||||
if (DumbService.isDumb(declaration.getProject())) {
|
JetSourceNavigationHelper.getOriginalElement(declaration)
|
||||||
return null
|
override fun getNavigationElement(declaration: JetDeclaration) =
|
||||||
}
|
JetSourceNavigationHelper.getNavigationElement(declaration)
|
||||||
if (declaration.getContainingJetFile().isCompiled()) {
|
|
||||||
return JetSourceNavigationHelper.replaceBySourceDeclarationIfPresent(declaration)
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-13
@@ -34,7 +34,6 @@ import org.jetbrains.kotlin.psi.*;
|
|||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||||
import org.jetbrains.kotlin.types.JetType;
|
import org.jetbrains.kotlin.types.JetType;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -42,24 +41,18 @@ public class MemberMatching {
|
|||||||
/* DECLARATIONS ROUGH MATCHING */
|
/* DECLARATIONS ROUGH MATCHING */
|
||||||
@Nullable
|
@Nullable
|
||||||
private static JetTypeReference getReceiverType(@NotNull JetNamedDeclaration propertyOrFunction) {
|
private static JetTypeReference getReceiverType(@NotNull JetNamedDeclaration propertyOrFunction) {
|
||||||
if (propertyOrFunction instanceof JetNamedFunction) {
|
if (propertyOrFunction instanceof JetCallableDeclaration) {
|
||||||
return ((JetNamedFunction) propertyOrFunction).getReceiverTypeReference();
|
return ((JetCallableDeclaration) propertyOrFunction).getReceiverTypeReference();
|
||||||
}
|
}
|
||||||
if (propertyOrFunction instanceof JetProperty) {
|
throw new IllegalArgumentException("Not a callable declaration: " + propertyOrFunction.getClass().getName());
|
||||||
return ((JetProperty) propertyOrFunction).getReceiverTypeReference();
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException("Neither function nor declaration: " + propertyOrFunction.getClass().getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static List<JetParameter> getValueParameters(@NotNull JetNamedDeclaration propertyOrFunction) {
|
private static List<JetParameter> getValueParameters(@NotNull JetNamedDeclaration propertyOrFunction) {
|
||||||
if (propertyOrFunction instanceof JetNamedFunction) {
|
if (propertyOrFunction instanceof JetCallableDeclaration) {
|
||||||
return ((JetNamedFunction) propertyOrFunction).getValueParameters();
|
return ((JetCallableDeclaration) propertyOrFunction).getValueParameters();
|
||||||
}
|
}
|
||||||
if (propertyOrFunction instanceof JetProperty) {
|
throw new IllegalArgumentException("Not a callable declaration: " + propertyOrFunction.getClass().getName());
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException("Neither function nor declaration: " + propertyOrFunction.getClass().getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getTypeShortName(@NotNull JetTypeReference typeReference) {
|
private static String getTypeShortName(@NotNull JetTypeReference typeReference) {
|
||||||
|
|||||||
+28
-10
@@ -29,22 +29,33 @@ import org.jetbrains.kotlin.idea.util.ProjectRootsUtil;
|
|||||||
public class JetSourceFilterScope extends DelegatingGlobalSearchScope {
|
public class JetSourceFilterScope extends DelegatingGlobalSearchScope {
|
||||||
@NotNull
|
@NotNull
|
||||||
public static GlobalSearchScope kotlinSourcesAndLibraries(@NotNull GlobalSearchScope delegate, @NotNull Project project) {
|
public static GlobalSearchScope kotlinSourcesAndLibraries(@NotNull GlobalSearchScope delegate, @NotNull Project project) {
|
||||||
return create(delegate, true, true, project);
|
return create(delegate, true, true, true, project);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static GlobalSearchScope kotlinSourceAndClassFiles(@NotNull GlobalSearchScope delegate, @NotNull Project project) {
|
public static GlobalSearchScope kotlinSourceAndClassFiles(@NotNull GlobalSearchScope delegate, @NotNull Project project) {
|
||||||
return create(delegate, false, true, project);
|
return create(delegate, true, false, true, project);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static GlobalSearchScope kotlinSources(@NotNull GlobalSearchScope delegate, @NotNull Project project) {
|
public static GlobalSearchScope kotlinSources(@NotNull GlobalSearchScope delegate, @NotNull Project project) {
|
||||||
return create(delegate, false, false, project);
|
return create(delegate, true, false, false, project);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static GlobalSearchScope kotlinLibrarySources(@NotNull GlobalSearchScope delegate, @NotNull Project project) {
|
||||||
|
return create(delegate, false, true, false, project);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static GlobalSearchScope kotlinLibraryClassFiles(@NotNull GlobalSearchScope delegate, @NotNull Project project) {
|
||||||
|
return create(delegate, false, false, true, project);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static GlobalSearchScope create(
|
private static GlobalSearchScope create(
|
||||||
@NotNull GlobalSearchScope delegate,
|
@NotNull GlobalSearchScope delegate,
|
||||||
|
boolean includeProjectSourceFiles,
|
||||||
boolean includeLibrarySourceFiles,
|
boolean includeLibrarySourceFiles,
|
||||||
boolean includeClassFiles,
|
boolean includeClassFiles,
|
||||||
@NotNull Project project
|
@NotNull Project project
|
||||||
@@ -54,29 +65,37 @@ public class JetSourceFilterScope extends DelegatingGlobalSearchScope {
|
|||||||
if (delegate instanceof JetSourceFilterScope) {
|
if (delegate instanceof JetSourceFilterScope) {
|
||||||
JetSourceFilterScope wrappedDelegate = (JetSourceFilterScope) delegate;
|
JetSourceFilterScope wrappedDelegate = (JetSourceFilterScope) delegate;
|
||||||
|
|
||||||
|
boolean doIncludeProjectSourceFiles = wrappedDelegate.includeProjectSourceFiles && includeProjectSourceFiles;
|
||||||
boolean doIncludeLibrarySourceFiles = wrappedDelegate.includeLibrarySourceFiles && includeLibrarySourceFiles;
|
boolean doIncludeLibrarySourceFiles = wrappedDelegate.includeLibrarySourceFiles && includeLibrarySourceFiles;
|
||||||
boolean doIncludeClassFiles = wrappedDelegate.includeClassFiles && includeClassFiles;
|
boolean doIncludeClassFiles = wrappedDelegate.includeClassFiles && includeClassFiles;
|
||||||
|
|
||||||
return new JetSourceFilterScope(wrappedDelegate.myBaseScope, doIncludeLibrarySourceFiles, doIncludeClassFiles, project);
|
return new JetSourceFilterScope(wrappedDelegate.myBaseScope,
|
||||||
|
doIncludeProjectSourceFiles,
|
||||||
|
doIncludeLibrarySourceFiles,
|
||||||
|
doIncludeClassFiles,
|
||||||
|
project);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new JetSourceFilterScope(delegate, includeLibrarySourceFiles, includeClassFiles, project);
|
return new JetSourceFilterScope(delegate, includeProjectSourceFiles, includeLibrarySourceFiles, includeClassFiles, project);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ProjectFileIndex index;
|
private final ProjectFileIndex index;
|
||||||
private final Project project;
|
private final Project project;
|
||||||
|
private final boolean includeProjectSourceFiles;
|
||||||
private final boolean includeLibrarySourceFiles;
|
private final boolean includeLibrarySourceFiles;
|
||||||
private final boolean includeClassFiles;
|
private final boolean includeClassFiles;
|
||||||
private final boolean isJsProject;
|
private final boolean isJsProject;
|
||||||
|
|
||||||
private JetSourceFilterScope(
|
private JetSourceFilterScope(
|
||||||
@NotNull GlobalSearchScope delegate,
|
@NotNull GlobalSearchScope delegate,
|
||||||
|
boolean includeProjectSourceFiles,
|
||||||
boolean includeLibrarySourceFiles,
|
boolean includeLibrarySourceFiles,
|
||||||
boolean includeClassFiles,
|
boolean includeClassFiles,
|
||||||
@NotNull Project project
|
@NotNull Project project
|
||||||
) {
|
) {
|
||||||
super(delegate);
|
super(delegate);
|
||||||
this.project = project;
|
this.project = project;
|
||||||
|
this.includeProjectSourceFiles = includeProjectSourceFiles;
|
||||||
this.includeLibrarySourceFiles = includeLibrarySourceFiles;
|
this.includeLibrarySourceFiles = includeLibrarySourceFiles;
|
||||||
this.includeClassFiles = includeClassFiles;
|
this.includeClassFiles = includeClassFiles;
|
||||||
//NOTE: avoid recomputing in potentially bottleneck 'contains' method
|
//NOTE: avoid recomputing in potentially bottleneck 'contains' method
|
||||||
@@ -91,10 +110,9 @@ public class JetSourceFilterScope extends DelegatingGlobalSearchScope {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(@NotNull VirtualFile file) {
|
public boolean contains(@NotNull VirtualFile file) {
|
||||||
if (!super.contains(file)) {
|
if (!super.contains(file)) return false;
|
||||||
return false;
|
return ProjectRootsUtil.isInContent(
|
||||||
}
|
project, file, includeProjectSourceFiles, includeLibrarySourceFiles, includeClassFiles, index, isJsProject
|
||||||
|
);
|
||||||
return ProjectRootsUtil.isInContent(project, file, true, includeLibrarySourceFiles, includeClassFiles, index, isJsProject);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,11 +127,8 @@ public object OptionalParametersHelper {
|
|||||||
|
|
||||||
//TODO: parameter in overriding method!
|
//TODO: parameter in overriding method!
|
||||||
//TODO: it's a temporary code while we don't have default values accessible from descriptors
|
//TODO: it's a temporary code while we don't have default values accessible from descriptors
|
||||||
var declaration = DescriptorToSourceUtilsIde.getAnyDeclaration(project, parameter) as? JetParameter ?: return null
|
val declaration = DescriptorToSourceUtilsIde.getAnyDeclaration(project, parameter)?.getNavigationElement() as? JetParameter
|
||||||
if (declaration.getContainingJetFile().isCompiled()) {
|
val expression = declaration?.getDefaultValue() ?: return null
|
||||||
declaration = JetSourceNavigationHelper.replaceBySourceDeclarationIfPresent(declaration) as? JetParameter ?: return null
|
|
||||||
}
|
|
||||||
val expression = declaration.getDefaultValue() ?: return null
|
|
||||||
|
|
||||||
val allParameters = (parameter.getContainingDeclaration() as CallableDescriptor).getValueParameters().toSet()
|
val allParameters = (parameter.getContainingDeclaration() as CallableDescriptor).getValueParameters().toSet()
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package library;
|
||||||
|
|
||||||
|
open class A(n: Int) {
|
||||||
|
constructor(): this(1)
|
||||||
|
|
||||||
|
open class T(n: Int) {
|
||||||
|
constructor(): this(1)
|
||||||
|
|
||||||
|
fun bar(b: Int): Int = b
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo(a: Int): Int = a
|
||||||
|
}
|
||||||
|
|
||||||
|
class B: A {
|
||||||
|
constructor(n: Int): super(n)
|
||||||
|
|
||||||
|
class U: A.T {
|
||||||
|
constructor(n: Int): super(n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class C(): A(1) {
|
||||||
|
class V(): A.T(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
class BB: A {
|
||||||
|
constructor(): super()
|
||||||
|
|
||||||
|
class UU: A.T {
|
||||||
|
constructor(): super()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class CC(): A() {
|
||||||
|
class VV(): A.T()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
object O {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
foo()
|
||||||
|
val f = ::foo
|
||||||
|
|
||||||
|
val o = O
|
||||||
|
|
||||||
|
val a = A(1)
|
||||||
|
val aa = A()
|
||||||
|
|
||||||
|
a.foo(2)
|
||||||
|
val ff = A::foo
|
||||||
|
|
||||||
|
val t = A.T(1)
|
||||||
|
val tt = A.T()
|
||||||
|
t.bar(2)
|
||||||
|
val fff = A.T::bar
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// PSI_ELEMENT: com.intellij.psi.PsiClass
|
|
||||||
// OPTIONS: usages
|
|
||||||
// FIND_BY_REF
|
|
||||||
// FIND_BY_MIRROR_ELEMENT
|
|
||||||
fun test() {
|
|
||||||
<caret>System.exit(0)
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Nested class/object (6: 5) System.exit(0)
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
// PSI_ELEMENT: com.intellij.psi.PsiField
|
|
||||||
// OPTIONS: usages
|
|
||||||
// FIND_BY_REF
|
|
||||||
// FIND_BY_MIRROR_ELEMENT
|
|
||||||
import java.awt.Dimension
|
|
||||||
|
|
||||||
fun test() {
|
|
||||||
Dimension().<caret>width = 1
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Value write (8: 17) Dimension().width = 1
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
// PSI_ELEMENT: com.intellij.psi.PsiMethod
|
|
||||||
// OPTIONS: usages
|
|
||||||
// FIND_BY_REF
|
|
||||||
// FIND_BY_MIRROR_ELEMENT
|
|
||||||
import java.awt.Dimension
|
|
||||||
|
|
||||||
fun test() {
|
|
||||||
Dimension().<caret>setSize(1.0, 2.0)
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Function call (8: 17) Dimension().setSize(1.0, 2.0)
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// PSI_ELEMENT: com.intellij.psi.PsiField
|
|
||||||
// OPTIONS: usages
|
|
||||||
// FIND_BY_REF
|
|
||||||
// FIND_BY_MIRROR_ELEMENT
|
|
||||||
fun test() {
|
|
||||||
System.<caret>out.println()
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Receiver (6: 12) System.out.println()
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
// PSI_ELEMENT: com.intellij.psi.PsiMethod
|
|
||||||
// OPTIONS: usages
|
|
||||||
// FIND_BY_REF
|
|
||||||
// FIND_BY_MIRROR_ELEMENT
|
|
||||||
fun test() {
|
|
||||||
System.<caret>exit(0)
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Function call (6: 12) System.exit(0)
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
Local variable declaration (10: 14) val foo: Foo
|
|
||||||
Usage in import (7: 16) import library.Foo
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
New instance creation (10: 5) Foo(1)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Value write (10: 11) Foo().x = 1
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Function call (10: 11) Foo().bar(1)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Value write (10: 9) Foo.X = 1
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
Function call (10: 9) Foo.baz(1)
|
|
||||||
-1
@@ -1,7 +1,6 @@
|
|||||||
// PSI_ELEMENT: com.intellij.psi.PsiClass
|
// PSI_ELEMENT: com.intellij.psi.PsiClass
|
||||||
// OPTIONS: usages
|
// OPTIONS: usages
|
||||||
// FIND_BY_REF
|
// FIND_BY_REF
|
||||||
// FIND_BY_NAVIGATION_ELEMENT
|
|
||||||
package usages
|
package usages
|
||||||
|
|
||||||
import library.Foo
|
import library.Foo
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
Local variable declaration (9: 14) val foo: Foo
|
||||||
|
Usage in import (6: 16) import library.Foo
|
||||||
-1
@@ -1,7 +1,6 @@
|
|||||||
// PSI_ELEMENT: com.intellij.psi.PsiMethod
|
// PSI_ELEMENT: com.intellij.psi.PsiMethod
|
||||||
// OPTIONS: usages
|
// OPTIONS: usages
|
||||||
// FIND_BY_REF
|
// FIND_BY_REF
|
||||||
// FIND_BY_NAVIGATION_ELEMENT
|
|
||||||
package usages
|
package usages
|
||||||
|
|
||||||
import library.Foo
|
import library.Foo
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
New instance creation (9: 5) Foo(1)
|
||||||
-1
@@ -1,7 +1,6 @@
|
|||||||
// PSI_ELEMENT: com.intellij.psi.PsiField
|
// PSI_ELEMENT: com.intellij.psi.PsiField
|
||||||
// OPTIONS: usages
|
// OPTIONS: usages
|
||||||
// FIND_BY_REF
|
// FIND_BY_REF
|
||||||
// FIND_BY_NAVIGATION_ELEMENT
|
|
||||||
package usages
|
package usages
|
||||||
|
|
||||||
import library.Foo
|
import library.Foo
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
Value write (9: 11) Foo().x = 1
|
||||||
-1
@@ -1,7 +1,6 @@
|
|||||||
// PSI_ELEMENT: com.intellij.psi.PsiMethod
|
// PSI_ELEMENT: com.intellij.psi.PsiMethod
|
||||||
// OPTIONS: usages
|
// OPTIONS: usages
|
||||||
// FIND_BY_REF
|
// FIND_BY_REF
|
||||||
// FIND_BY_NAVIGATION_ELEMENT
|
|
||||||
package usages
|
package usages
|
||||||
|
|
||||||
import library.Foo
|
import library.Foo
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
Function call (9: 11) Foo().bar(1)
|
||||||
-1
@@ -1,7 +1,6 @@
|
|||||||
// PSI_ELEMENT: com.intellij.psi.PsiField
|
// PSI_ELEMENT: com.intellij.psi.PsiField
|
||||||
// OPTIONS: usages
|
// OPTIONS: usages
|
||||||
// FIND_BY_REF
|
// FIND_BY_REF
|
||||||
// FIND_BY_NAVIGATION_ELEMENT
|
|
||||||
package usages
|
package usages
|
||||||
|
|
||||||
import library.Foo
|
import library.Foo
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
Value write (9: 9) Foo.X = 1
|
||||||
-1
@@ -1,7 +1,6 @@
|
|||||||
// PSI_ELEMENT: com.intellij.psi.PsiMethod
|
// PSI_ELEMENT: com.intellij.psi.PsiMethod
|
||||||
// OPTIONS: usages
|
// OPTIONS: usages
|
||||||
// FIND_BY_REF
|
// FIND_BY_REF
|
||||||
// FIND_BY_NAVIGATION_ELEMENT
|
|
||||||
package usages
|
package usages
|
||||||
|
|
||||||
import library.Foo
|
import library.Foo
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
Function call (9: 9) Foo.baz(1)
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetClass
|
||||||
|
// OPTIONS: usages, constructorUsages
|
||||||
|
// FIND_BY_REF
|
||||||
|
// WITH_FILE_NAME
|
||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
class X: A {
|
||||||
|
constructor(n: Int): super(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
class Y(): A(1)
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val a: <caret>A = A()
|
||||||
|
val aa = A(1)
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
class J extends A {
|
||||||
|
public J(int n) {
|
||||||
|
super(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test() {
|
||||||
|
A a = new A();
|
||||||
|
A aa = new A(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
[LibraryClassUsages.0.kt] Local variable declaration (16: 12) val a: A = A()
|
||||||
|
[LibraryClassUsages.0.kt] New instance creation (16: 16) val a: A = A()
|
||||||
|
[LibraryClassUsages.0.kt] New instance creation (17: 14) val aa = A(1)
|
||||||
|
[LibraryClassUsages.0.kt] Supertype (13: 12) class Y(): A(1)
|
||||||
|
[LibraryClassUsages.0.kt] Supertype (9: 10) class X: A {
|
||||||
|
[LibraryClassUsages.1.java] Local variable declaration (11: 9) A a = new A();
|
||||||
|
[LibraryClassUsages.1.java] Local variable declaration (12: 9) A aa = new A(1);
|
||||||
|
[LibraryClassUsages.1.java] New instance creation (11: 19) A a = new A();
|
||||||
|
[LibraryClassUsages.1.java] New instance creation (12: 20) A aa = new A(1);
|
||||||
|
[LibraryClassUsages.1.java] Usage in extends/implements clause (5: 17) class J extends A {
|
||||||
|
[library.kt] Nested class/object (59: 13) val t = A.T(1)
|
||||||
|
[library.kt] Nested class/object (60: 14) val tt = A.T()
|
||||||
|
[library.kt] New instance creation (53: 13) val a = A(1)
|
||||||
|
[library.kt] New instance creation (54: 14) val aa = A()
|
||||||
|
[library.kt] Supertype (15: 10) class B: A {
|
||||||
|
[library.kt] Supertype (18: 14) class U: A.T {
|
||||||
|
[library.kt] Supertype (23: 12) class C(): A(1) {
|
||||||
|
[library.kt] Supertype (24: 16) class V(): A.T(1)
|
||||||
|
[library.kt] Supertype (27: 11) class BB: A {
|
||||||
|
[library.kt] Supertype (30: 15) class UU: A.T {
|
||||||
|
[library.kt] Supertype (35: 13) class CC(): A() {
|
||||||
|
[library.kt] Supertype (36: 17) class VV(): A.T()
|
||||||
|
[library.kt] Unclassified usage (57: 14) val ff = A::foo
|
||||||
|
[library.kt] Unclassified usage (62: 15) val fff = A.T::bar
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetNamedFunction
|
||||||
|
// OPTIONS: usages
|
||||||
|
// FIND_BY_REF
|
||||||
|
// WITH_FILE_NAME
|
||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val f = ::foo
|
||||||
|
<caret>foo()
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetNamedFunction
|
||||||
|
// OPTIONS: usages
|
||||||
|
// FIND_BY_REF
|
||||||
|
// WITH_FILE_NAME
|
||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
class J {
|
||||||
|
static void test() {
|
||||||
|
LibraryPackage.foo();
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
[LibraryFunctionUsages.0.kt] Callable reference (10: 15) val f = ::foo
|
||||||
|
[LibraryFunctionUsages.0.kt] Function call (11: 5) foo()
|
||||||
|
[library.kt] Callable reference (49: 15) val f = ::foo
|
||||||
|
[library.kt] Function call (48: 5) foo()
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetNamedFunction
|
||||||
|
// OPTIONS: usages
|
||||||
|
// FIND_BY_REF
|
||||||
|
// WITH_FILE_NAME
|
||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val f = A::foo
|
||||||
|
A().<caret>foo(1)
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetNamedFunction
|
||||||
|
// OPTIONS: usages
|
||||||
|
// FIND_BY_REF
|
||||||
|
// WITH_FILE_NAME
|
||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
class J {
|
||||||
|
static void test() {
|
||||||
|
new A().foo(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
[LibraryMemberFunctionUsages.0.kt] Callable reference (10: 16) val f = A::foo
|
||||||
|
[LibraryMemberFunctionUsages.0.kt] Function call (11: 9) A().foo(1)
|
||||||
|
[library.kt] Callable reference (57: 17) val ff = A::foo
|
||||||
|
[library.kt] Function call (56: 7) a.foo(2)
|
||||||
Vendored
+12
@@ -0,0 +1,12 @@
|
|||||||
|
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetNamedFunction
|
||||||
|
// OPTIONS: usages
|
||||||
|
// FIND_BY_REF
|
||||||
|
// WITH_FILE_NAME
|
||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val f = A.T::bar
|
||||||
|
A.T().<caret>bar(1)
|
||||||
|
}
|
||||||
Vendored
+13
@@ -0,0 +1,13 @@
|
|||||||
|
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetNamedFunction
|
||||||
|
// OPTIONS: usages
|
||||||
|
// FIND_BY_REF
|
||||||
|
// WITH_FILE_NAME
|
||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
class J {
|
||||||
|
static void test() {
|
||||||
|
new A.T().foo(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
[LibraryNestedClassMemberFunctionUsages.0.kt] Callable reference (10: 18) val f = A.T::bar
|
||||||
|
[LibraryNestedClassMemberFunctionUsages.0.kt] Function call (11: 11) A.T().bar(1)
|
||||||
|
[library.kt] Callable reference (62: 20) val fff = A.T::bar
|
||||||
|
[library.kt] Function call (61: 7) t.bar(2)
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetPrimaryConstructor
|
||||||
|
// OPTIONS: usages
|
||||||
|
// FIND_BY_REF
|
||||||
|
// WITH_FILE_NAME
|
||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
class X: A.T {
|
||||||
|
constructor(n: Int): super(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
class Y(): A.T(1)
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val a: A.T = A.T()
|
||||||
|
val aa = A.<caret>T(1)
|
||||||
|
}
|
||||||
|
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
class J extends A.T {
|
||||||
|
public X(int n) {
|
||||||
|
super(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test() {
|
||||||
|
A.T a = new A.T();
|
||||||
|
A.T aa = new A.T(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
[LibraryNestedClassPrimaryConstructorUsages.0.kt] New instance creation (17: 16) val aa = A.T(1)
|
||||||
|
[LibraryNestedClassPrimaryConstructorUsages.0.kt] Supertype (13: 14) class Y(): A.T(1)
|
||||||
|
[library.kt] New instance creation (59: 15) val t = A.T(1)
|
||||||
|
[library.kt] Supertype (24: 18) class V(): A.T(1)
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetSecondaryConstructor
|
||||||
|
// OPTIONS: usages
|
||||||
|
// FIND_BY_REF
|
||||||
|
// WITH_FILE_NAME
|
||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
class X: A.T {
|
||||||
|
constructor(): super()
|
||||||
|
}
|
||||||
|
|
||||||
|
class Y(): A.T()
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val a: A.T = A.<caret>T()
|
||||||
|
val aa = A.T(1)
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
class J extends A.T {
|
||||||
|
public J() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public J(int n) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test() {
|
||||||
|
A.T a = new A.T();
|
||||||
|
A.T aa = new A.T(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
[LibraryNestedClassSecondaryConstructorUsages.0.kt] New instance creation (16: 20) val a: A.T = A.T()
|
||||||
|
[LibraryNestedClassSecondaryConstructorUsages.0.kt] Supertype (13: 14) class Y(): A.T()
|
||||||
|
[library.kt] New instance creation (60: 16) val tt = A.T()
|
||||||
|
[library.kt] Supertype (36: 19) class VV(): A.T()
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetClass
|
||||||
|
// OPTIONS: usages, constructorUsages
|
||||||
|
// FIND_BY_REF
|
||||||
|
// WITH_FILE_NAME
|
||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
class X: A.T {
|
||||||
|
constructor(n: Int): super(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
class Y(): A.T(1)
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val a: A.<caret>T = A.T()
|
||||||
|
val aa = A.T(1)
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
class J extends A.T {
|
||||||
|
public J(int n) {
|
||||||
|
super(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test() {
|
||||||
|
A.T t = new A.T();
|
||||||
|
A.T tt = new A.T(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
[LibraryNestedClassUsages.0.kt] Local variable declaration (16: 14) val a: A.T = A.T()
|
||||||
|
[LibraryNestedClassUsages.0.kt] New instance creation (16: 20) val a: A.T = A.T()
|
||||||
|
[LibraryNestedClassUsages.0.kt] New instance creation (17: 16) val aa = A.T(1)
|
||||||
|
[LibraryNestedClassUsages.0.kt] Supertype (13: 14) class Y(): A.T(1)
|
||||||
|
[LibraryNestedClassUsages.0.kt] Supertype (9: 12) class X: A.T {
|
||||||
|
[library.kt] New instance creation (59: 15) val t = A.T(1)
|
||||||
|
[library.kt] New instance creation (60: 16) val tt = A.T()
|
||||||
|
[library.kt] Supertype (18: 16) class U: A.T {
|
||||||
|
[library.kt] Supertype (24: 18) class V(): A.T(1)
|
||||||
|
[library.kt] Supertype (30: 17) class UU: A.T {
|
||||||
|
[library.kt] Supertype (36: 19) class VV(): A.T()
|
||||||
|
[library.kt] Unclassified usage (62: 17) val fff = A.T::bar
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetObjectDeclaration
|
||||||
|
// OPTIONS: usages
|
||||||
|
// FIND_BY_REF
|
||||||
|
// WITH_FILE_NAME
|
||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val o = <caret>O
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
class J {
|
||||||
|
static void test() {
|
||||||
|
O o = O.INSTANCE$;
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
[LibraryObjectUsages.0.kt] Value read (10: 13) val o = O
|
||||||
|
[LibraryObjectUsages.1.java] Class static member access (7: 15) O o = O.INSTANCE$;
|
||||||
|
[LibraryObjectUsages.1.java] Local variable declaration (7: 9) O o = O.INSTANCE$;
|
||||||
|
[library.kt] Value read (51: 13) val o = O
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetPrimaryConstructor
|
||||||
|
// OPTIONS: usages
|
||||||
|
// FIND_BY_REF
|
||||||
|
// WITH_FILE_NAME
|
||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
class X: A {
|
||||||
|
constructor(n: Int): super(n)
|
||||||
|
}
|
||||||
|
|
||||||
|
class Y(): A(1)
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val a: A = A()
|
||||||
|
val aa = <caret>A(1)
|
||||||
|
}
|
||||||
|
|
||||||
Vendored
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
class J extends A {
|
||||||
|
public X(int n) {
|
||||||
|
super(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test() {
|
||||||
|
A a = new A();
|
||||||
|
A aa = new A(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
[LibraryPrimaryConstructorUsages.0.kt] New instance creation (17: 14) val aa = A(1)
|
||||||
|
[LibraryPrimaryConstructorUsages.0.kt] Supertype (13: 12) class Y(): A(1)
|
||||||
|
[library.kt] New instance creation (53: 13) val a = A(1)
|
||||||
|
[library.kt] Supertype (23: 12) class C(): A(1) {
|
||||||
Vendored
+18
@@ -0,0 +1,18 @@
|
|||||||
|
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetSecondaryConstructor
|
||||||
|
// OPTIONS: usages
|
||||||
|
// FIND_BY_REF
|
||||||
|
// WITH_FILE_NAME
|
||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
class X: A {
|
||||||
|
constructor(): super()
|
||||||
|
}
|
||||||
|
|
||||||
|
class Y(): A()
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
val a: A = <caret>A()
|
||||||
|
val aa = A(1)
|
||||||
|
}
|
||||||
Vendored
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package usages
|
||||||
|
|
||||||
|
import library.*
|
||||||
|
|
||||||
|
class J extends A {
|
||||||
|
public J() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public J(int n) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test() {
|
||||||
|
A a = new A();
|
||||||
|
A aa = new A(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
[LibrarySecondaryConstructorUsages.0.kt] New instance creation (16: 16) val a: A = A()
|
||||||
|
[LibrarySecondaryConstructorUsages.0.kt] Supertype (13: 12) class Y(): A()
|
||||||
|
[library.kt] New instance creation (54: 14) val aa = A()
|
||||||
|
[library.kt] Supertype (35: 13) class CC(): A() {
|
||||||
@@ -33,6 +33,7 @@ import com.intellij.openapi.util.io.FileUtilRt;
|
|||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.psi.*;
|
import com.intellij.psi.*;
|
||||||
import com.intellij.psi.PsiPackage;
|
import com.intellij.psi.PsiPackage;
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
import com.intellij.testFramework.LightProjectDescriptor;
|
import com.intellij.testFramework.LightProjectDescriptor;
|
||||||
import com.intellij.usageView.UsageInfo;
|
import com.intellij.usageView.UsageInfo;
|
||||||
@@ -55,6 +56,7 @@ import org.jetbrains.kotlin.idea.findUsages.KotlinPropertyFindUsagesOptions;
|
|||||||
import org.jetbrains.kotlin.idea.test.JetLightCodeInsightFixtureTestCase;
|
import org.jetbrains.kotlin.idea.test.JetLightCodeInsightFixtureTestCase;
|
||||||
import org.jetbrains.kotlin.idea.test.JetWithJdkAndRuntimeLightProjectDescriptor;
|
import org.jetbrains.kotlin.idea.test.JetWithJdkAndRuntimeLightProjectDescriptor;
|
||||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase;
|
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase;
|
||||||
|
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil;
|
||||||
import org.jetbrains.kotlin.psi.*;
|
import org.jetbrains.kotlin.psi.*;
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils;
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils;
|
||||||
import org.jetbrains.kotlin.test.JetTestUtils;
|
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||||
@@ -325,31 +327,42 @@ public abstract class AbstractJetFindUsagesTest extends JetLightCodeInsightFixtu
|
|||||||
}
|
}
|
||||||
myFixture.configureByFile(path);
|
myFixture.configureByFile(path);
|
||||||
|
|
||||||
PsiElement originalElement =
|
PsiElement caretElement =
|
||||||
InTextDirectivesUtils.isDirectiveDefined(mainFileText, "// FIND_BY_REF")
|
InTextDirectivesUtils.isDirectiveDefined(mainFileText, "// FIND_BY_REF")
|
||||||
? TargetElementUtilBase.findTargetElement(myFixture.getEditor(),
|
? TargetElementUtilBase.findTargetElement(myFixture.getEditor(),
|
||||||
TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtil.NEW_AS_CONSTRUCTOR)
|
TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED |
|
||||||
|
TargetElementUtil.NEW_AS_CONSTRUCTOR)
|
||||||
: myFixture.getElementAtCaret();
|
: myFixture.getElementAtCaret();
|
||||||
boolean findByMirrorElement = InTextDirectivesUtils.isDirectiveDefined(mainFileText, "// FIND_BY_MIRROR_ELEMENT");
|
assertNotNull(caretElement);
|
||||||
boolean findByNavigationElement = InTextDirectivesUtils.isDirectiveDefined(mainFileText, "// FIND_BY_NAVIGATION_ELEMENT");
|
assertInstanceOf(caretElement, caretElementClass);
|
||||||
if (findByMirrorElement && findByNavigationElement) {
|
|
||||||
fail("Incompatible directives");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (findByMirrorElement) {
|
PsiFile containingFile = caretElement.getContainingFile();
|
||||||
assert originalElement instanceof PsiCompiledElement : "PsiCompiledElement is expected: " + originalElement;
|
boolean isLibraryElement = containingFile != null && ProjectRootsUtil.isLibraryFile(getProject(), containingFile.getVirtualFile());
|
||||||
originalElement = ((PsiCompiledElement)originalElement).getMirror();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (findByNavigationElement) {
|
|
||||||
assert originalElement != null : "Original element is not found";
|
|
||||||
originalElement = originalElement.getNavigationElement();
|
|
||||||
}
|
|
||||||
|
|
||||||
T caretElement = PsiTreeUtil.getParentOfType(originalElement, caretElementClass, false);
|
|
||||||
assertNotNull(String.format("Element with type '%s' wasn't found at caret position", caretElementClass), caretElement);
|
|
||||||
|
|
||||||
FindUsagesOptions options = parser != null ? parser.parse(mainFileText, getProject()) : null;
|
FindUsagesOptions options = parser != null ? parser.parse(mainFileText, getProject()) : null;
|
||||||
|
|
||||||
|
// Ensure that search by sources (if present) and decompiled declarations gives the same results
|
||||||
|
if (isLibraryElement) {
|
||||||
|
PsiElement originalElement = caretElement.getOriginalElement();
|
||||||
|
findUsagesAndCheckResults(mainFileText, prefix, rootPath, originalElement, options);
|
||||||
|
|
||||||
|
PsiElement navigationElement = caretElement.getNavigationElement();
|
||||||
|
if (navigationElement != originalElement) {
|
||||||
|
findUsagesAndCheckResults(mainFileText, prefix, rootPath, navigationElement, options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
findUsagesAndCheckResults(mainFileText, prefix, rootPath, caretElement, options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T extends PsiElement> void findUsagesAndCheckResults(
|
||||||
|
String mainFileText,
|
||||||
|
String prefix,
|
||||||
|
String rootPath,
|
||||||
|
T caretElement,
|
||||||
|
FindUsagesOptions options
|
||||||
|
) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
|
||||||
Collection<UsageInfo> usageInfos = findUsages(caretElement, options);
|
Collection<UsageInfo> usageInfos = findUsages(caretElement, options);
|
||||||
|
|
||||||
Collection<UsageFilteringRule> filteringRules = instantiateClasses(mainFileText, "// FILTERING_RULES: ");
|
Collection<UsageFilteringRule> filteringRules = instantiateClasses(mainFileText, "// FILTERING_RULES: ");
|
||||||
@@ -415,6 +428,8 @@ public abstract class AbstractJetFindUsagesTest extends JetLightCodeInsightFixtu
|
|||||||
options = handler.getFindUsagesOptions(null);
|
options = handler.getFindUsagesOptions(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options.searchScope = GlobalSearchScope.allScope(project);
|
||||||
|
|
||||||
CommonProcessors.CollectProcessor<UsageInfo> processor = new CommonProcessors.CollectProcessor<UsageInfo>();
|
CommonProcessors.CollectProcessor<UsageInfo> processor = new CommonProcessors.CollectProcessor<UsageInfo>();
|
||||||
PsiElement[] psiElements = ArrayUtil.mergeArrays(handler.getPrimaryElements(), handler.getSecondaryElements());
|
PsiElement[] psiElements = ArrayUtil.mergeArrays(handler.getPrimaryElements(), handler.getSecondaryElements());
|
||||||
|
|
||||||
|
|||||||
@@ -1000,45 +1000,6 @@ public class JetFindUsagesTestGenerated extends AbstractJetFindUsagesTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/findUsages/kotlin/library")
|
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
|
||||||
public static class Library extends AbstractJetFindUsagesTest {
|
|
||||||
public void testAllFilesPresentInLibrary() throws Exception {
|
|
||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/findUsages/kotlin/library"), Pattern.compile("^(.+)\\.0\\.kt$"), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("LibraryClassUsages.0.kt")
|
|
||||||
public void testLibraryClassUsages() throws Exception {
|
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/library/LibraryClassUsages.0.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("LibraryFieldUsages.0.kt")
|
|
||||||
public void testLibraryFieldUsages() throws Exception {
|
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/library/LibraryFieldUsages.0.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("LibraryMethodUsages.0.kt")
|
|
||||||
public void testLibraryMethodUsages() throws Exception {
|
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/library/LibraryMethodUsages.0.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("LibraryStaticFieldUsages.0.kt")
|
|
||||||
public void testLibraryStaticFieldUsages() throws Exception {
|
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/library/LibraryStaticFieldUsages.0.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("LibraryStaticMethodUsages.0.kt")
|
|
||||||
public void testLibraryStaticMethodUsages() throws Exception {
|
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/library/LibraryStaticMethodUsages.0.kt");
|
|
||||||
doTest(fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@TestMetadata("idea/testData/findUsages/kotlin/unresolvedAnnotation")
|
@TestMetadata("idea/testData/findUsages/kotlin/unresolvedAnnotation")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
+106
-28
@@ -35,39 +35,117 @@ public class KotlinFindUsagesInLibrarySourceTestGenerated extends AbstractKotlin
|
|||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/findUsages/librarySources"), Pattern.compile("^(.+)\\.0\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/findUsages/librarySources"), Pattern.compile("^(.+)\\.0\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("LibraryClassUsages.0.kt")
|
@TestMetadata("idea/testData/findUsages/librarySources/javaLibrary")
|
||||||
public void testLibraryClassUsages() throws Exception {
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/LibraryClassUsages.0.kt");
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
doTest(fileName);
|
public static class JavaLibrary extends AbstractKotlinFindUsagesInLibrarySourceTest {
|
||||||
|
public void testAllFilesPresentInJavaLibrary() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/findUsages/librarySources/javaLibrary"), Pattern.compile("^(.+)\\.0\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("LibraryClassUsages.0.kt")
|
||||||
|
public void testLibraryClassUsages() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/javaLibrary/LibraryClassUsages.0.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("LibraryConstructorUsages.0.kt")
|
||||||
|
public void testLibraryConstructorUsages() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/javaLibrary/LibraryConstructorUsages.0.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("LibraryFieldUsages.0.kt")
|
||||||
|
public void testLibraryFieldUsages() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/javaLibrary/LibraryFieldUsages.0.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("LibraryMethodUsages.0.kt")
|
||||||
|
public void testLibraryMethodUsages() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/javaLibrary/LibraryMethodUsages.0.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("LibraryStaticFieldUsages.0.kt")
|
||||||
|
public void testLibraryStaticFieldUsages() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/javaLibrary/LibraryStaticFieldUsages.0.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("LibraryStaticMethodUsages.0.kt")
|
||||||
|
public void testLibraryStaticMethodUsages() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/javaLibrary/LibraryStaticMethodUsages.0.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("LibraryConstructorUsages.0.kt")
|
@TestMetadata("idea/testData/findUsages/librarySources/kotlinLibrary")
|
||||||
public void testLibraryConstructorUsages() throws Exception {
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/LibraryConstructorUsages.0.kt");
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
doTest(fileName);
|
public static class KotlinLibrary extends AbstractKotlinFindUsagesInLibrarySourceTest {
|
||||||
}
|
public void testAllFilesPresentInKotlinLibrary() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/findUsages/librarySources/kotlinLibrary"), Pattern.compile("^(.+)\\.0\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("LibraryFieldUsages.0.kt")
|
@TestMetadata("LibraryClassUsages.0.kt")
|
||||||
public void testLibraryFieldUsages() throws Exception {
|
public void testLibraryClassUsages() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/LibraryFieldUsages.0.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/kotlinLibrary/LibraryClassUsages.0.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("LibraryMethodUsages.0.kt")
|
@TestMetadata("LibraryFunctionUsages.0.kt")
|
||||||
public void testLibraryMethodUsages() throws Exception {
|
public void testLibraryFunctionUsages() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/LibraryMethodUsages.0.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/kotlinLibrary/LibraryFunctionUsages.0.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("LibraryStaticFieldUsages.0.kt")
|
@TestMetadata("LibraryMemberFunctionUsages.0.kt")
|
||||||
public void testLibraryStaticFieldUsages() throws Exception {
|
public void testLibraryMemberFunctionUsages() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/LibraryStaticFieldUsages.0.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/kotlinLibrary/LibraryMemberFunctionUsages.0.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("LibraryStaticMethodUsages.0.kt")
|
@TestMetadata("LibraryNestedClassMemberFunctionUsages.0.kt")
|
||||||
public void testLibraryStaticMethodUsages() throws Exception {
|
public void testLibraryNestedClassMemberFunctionUsages() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/LibraryStaticMethodUsages.0.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassMemberFunctionUsages.0.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("LibraryNestedClassPrimaryConstructorUsages.0.kt")
|
||||||
|
public void testLibraryNestedClassPrimaryConstructorUsages() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassPrimaryConstructorUsages.0.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("LibraryNestedClassSecondaryConstructorUsages.0.kt")
|
||||||
|
public void testLibraryNestedClassSecondaryConstructorUsages() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassSecondaryConstructorUsages.0.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("LibraryNestedClassUsages.0.kt")
|
||||||
|
public void testLibraryNestedClassUsages() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassUsages.0.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("LibraryObjectUsages.0.kt")
|
||||||
|
public void testLibraryObjectUsages() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/kotlinLibrary/LibraryObjectUsages.0.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("LibraryPrimaryConstructorUsages.0.kt")
|
||||||
|
public void testLibraryPrimaryConstructorUsages() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/kotlinLibrary/LibraryPrimaryConstructorUsages.0.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("LibrarySecondaryConstructorUsages.0.kt")
|
||||||
|
public void testLibrarySecondaryConstructorUsages() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/kotlinLibrary/LibrarySecondaryConstructorUsages.0.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user