diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetDeclarationStub.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetDeclarationStub.java index 3e70efd3656..c370b123d1c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetDeclarationStub.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetDeclarationStub.java @@ -52,16 +52,16 @@ abstract class JetDeclarationStub extends JetModifierList return super.getParent(); } + @Override + public PsiElement getOriginalElement() { + KotlinDeclarationNavigationPolicy navigationPolicy = ServiceManager.getService(KotlinDeclarationNavigationPolicy.class); + return navigationPolicy != null ? navigationPolicy.getOriginalElement(this) : this; + } + @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; + return navigationPolicy != null ? navigationPolicy.getNavigationElement(this) : this; } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KotlinDeclarationNavigationPolicy.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KotlinDeclarationNavigationPolicy.kt index a9746e19b67..420f96361a2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KotlinDeclarationNavigationPolicy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KotlinDeclarationNavigationPolicy.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.psi -public trait KotlinDeclarationNavigationPolicy { - public fun getNavigationElement(declaration: JetDeclaration): JetElement? +public interface KotlinDeclarationNavigationPolicy { + public fun getOriginalElement(declaration: JetDeclaration): JetElement + public fun getNavigationElement(declaration: JetDeclaration): JetElement } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/JetSourceNavigationHelper.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/JetSourceNavigationHelper.java index 12254e2fe56..ed346f2dfa2 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/JetSourceNavigationHelper.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/JetSourceNavigationHelper.java @@ -19,8 +19,11 @@ package org.jetbrains.kotlin.idea.decompiler.navigation; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.DumbService; 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.vfs.VirtualFile; import com.intellij.psi.JavaPsiFacade; @@ -31,7 +34,6 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.stubs.StringStubIndexExtension; import com.intellij.util.containers.ContainerUtil; import gnu.trove.THashSet; -import kotlin.KotlinPackage; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; 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.di.InjectorForLazyResolve; 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.JetTopLevelPropertyFqnNameIndex; +import org.jetbrains.kotlin.idea.util.ProjectRootsUtil; import org.jetbrains.kotlin.lexer.JetTokens; import org.jetbrains.kotlin.name.ClassId; 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.*; public class JetSourceNavigationHelper { + public enum NavigationKind { + CLASS_FILES_TO_SOURCES, + SOURCES_TO_CLASS_FILES + } + private static boolean forceResolve = false; private JetSourceNavigationHelper() { } - @Nullable - public static JetClassOrObject getSourceClassOrObject(@NotNull JetClassOrObject decompiledClassOrObject) { - return getSourceForNamedClassOrObject(decompiledClassOrObject); - } - @NotNull - private static GlobalSearchScope createLibrarySourcesScope(@NotNull JetNamedDeclaration decompiledDeclaration) { - JetFile containingFile = decompiledDeclaration.getContainingJetFile(); + private static GlobalSearchScope createLibraryOrSourcesScope( + @NotNull JetNamedDeclaration declaration, + @NotNull NavigationKind navigationKind + ) { + JetFile containingFile = declaration.getContainingJetFile(); 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; } - Project project = decompiledDeclaration.getProject(); - ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(project); - - if (!projectFileIndex.isInLibraryClasses(libraryFile)) { - return GlobalSearchScope.EMPTY_SCOPE; - } - - Set 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); + Project project = declaration.getProject(); + return includeLibrarySources + ? JetSourceFilterScope.kotlinLibrarySources(GlobalSearchScope.allScope(project), project) + : JetSourceFilterScope.kotlinLibraryClassFiles(GlobalSearchScope.allScope(project), project); } private static List getContainingFiles(@NotNull Iterable declarations) { @@ -151,35 +150,48 @@ public class JetSourceNavigationHelper { } @Nullable - private static JetNamedDeclaration getSourcePropertyOrFunction(@NotNull JetNamedDeclaration decompiledDeclaration) { - String memberNameAsString = decompiledDeclaration.getName(); + private static JetNamedDeclaration convertPropertyOrFunction( + @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; Name memberName = Name.identifier(memberNameAsString); - PsiElement decompiledContainer = decompiledDeclaration.getParent(); + PsiElement decompiledContainer = declaration.getParent(); Collection candidates; if (decompiledContainer instanceof JetFile) { - candidates = getInitialTopLevelCandidates(decompiledDeclaration); + candidates = getInitialTopLevelCandidates(declaration, navigationKind); } else if (decompiledContainer instanceof JetClassBody) { JetClassOrObject decompiledClassOrObject = (JetClassOrObject) decompiledContainer.getParent(); - JetClassOrObject sourceClassOrObject = getSourceClassOrObject(decompiledClassOrObject); + JetClassOrObject sourceClassOrObject = convertNamedClassOrObject(decompiledClassOrObject, navigationKind); //noinspection unchecked candidates = sourceClassOrObject == null ? Collections.emptyList() - : getInitialMemberCandidates(sourceClassOrObject, memberName, (Class) decompiledDeclaration.getClass()); + : getInitialMemberCandidates(sourceClassOrObject, memberName, + (Class) declaration.getClass()); if (candidates.isEmpty()) { - if (decompiledDeclaration instanceof JetProperty && sourceClassOrObject instanceof JetClass) { + if (declaration instanceof JetProperty && sourceClassOrObject instanceof JetClass) { return findSpecialProperty(memberName, (JetClass) sourceClassOrObject); } } } else { - throw new IllegalStateException("Unexpected container of decompiled declaration: " - + decompiledContainer.getClass().getSimpleName()); + throw new IllegalStateException("Unexpected container of " + + (navigationKind == NavigationKind.CLASS_FILES_TO_SOURCES ? "decompiled" : "source") + + " declaration: " + + decompiledContainer.getClass().getSimpleName()); } if (candidates.isEmpty()) { @@ -187,14 +199,14 @@ public class JetSourceNavigationHelper { } if (!forceResolve) { - candidates = filterByReceiverPresenceAndParametersCount(decompiledDeclaration, candidates); + candidates = filterByReceiverPresenceAndParametersCount(declaration, candidates); if (candidates.size() <= 1) { return candidates.isEmpty() ? null : candidates.iterator().next(); } if (!haveRenamesInImports(getContainingFiles(candidates))) { - candidates = filterByReceiverAndParameterTypes(decompiledDeclaration, candidates); + candidates = filterByReceiverAndParameterTypes(declaration, candidates); if (candidates.size() <= 1) { 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) { //noinspection unchecked CallableDescriptor candidateDescriptor = (CallableDescriptor) analyzer.resolveToDescriptor(candidate); - if (receiversMatch(decompiledDeclaration, candidateDescriptor) - && valueParametersTypesMatch(decompiledDeclaration, candidateDescriptor) - && typeParametersMatch((JetTypeParameterListOwner) decompiledDeclaration, candidateDescriptor.getTypeParameters())) { + if (receiversMatch(declaration, candidateDescriptor) + && valueParametersTypesMatch(declaration, candidateDescriptor) + && typeParametersMatch((JetTypeParameterListOwner) declaration, candidateDescriptor.getTypeParameters())) { return candidate; } } @@ -250,16 +262,19 @@ public class JetSourceNavigationHelper { } @Nullable - private static JetClassOrObject getSourceForNamedClassOrObject(@NotNull JetClassOrObject decompiledClassOrObject) { - FqName classFqName = decompiledClassOrObject.getFqName(); + private static JetClassOrObject convertNamedClassOrObject( + @NotNull JetClassOrObject classOrObject, + @NotNull NavigationKind navigationKind + ) { + FqName classFqName = classOrObject.getFqName(); 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 return null; } Collection classes = JetFullClassNameIndex.getInstance() - .get(classFqName.asString(), decompiledClassOrObject.getProject(), librarySourcesScope); + .get(classFqName.asString(), classOrObject.getProject(), librarySourcesScope); if (classes.isEmpty()) { return null; } @@ -267,18 +282,21 @@ public class JetSourceNavigationHelper { } @NotNull - private static Collection getInitialTopLevelCandidates(@NotNull JetNamedDeclaration decompiledDeclaration) { - FqName memberFqName = decompiledDeclaration.getFqName(); + private static Collection getInitialTopLevelCandidates( + @NotNull JetNamedDeclaration declaration, + @NotNull NavigationKind navigationKind + ) { + FqName memberFqName = declaration.getFqName(); 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 return Collections.emptyList(); } //noinspection unchecked StringStubIndexExtension index = - (StringStubIndexExtension) getIndexForTopLevelPropertyOrFunction(decompiledDeclaration); - return index.get(memberFqName.asString(), decompiledDeclaration.getProject(), librarySourcesScope); + (StringStubIndexExtension) getIndexForTopLevelPropertyOrFunction(declaration); + return index.get(memberFqName.asString(), declaration.getProject(), librarySourcesScope); } private static StringStubIndexExtension 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 public static void setForceResolve(boolean forceResolve) { JetSourceNavigationHelper.forceResolve = forceResolve; @@ -414,30 +422,60 @@ public class JetSourceNavigationHelper { } @NotNull - public static JetDeclaration replaceBySourceDeclarationIfPresent(@NotNull JetDeclaration original) { - JetDeclaration sourceElement = original.accept(new SourceForDecompiledExtractingVisitor(), null); - return sourceElement != null ? sourceElement : original; + public static JetDeclaration getNavigationElement(@NotNull JetDeclaration declaration) { + return navigateToDeclaration(declaration, NavigationKind.CLASS_FILES_TO_SOURCES); } - private static class SourceForDecompiledExtractingVisitor extends JetVisitor { + @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 { + private final NavigationKind navigationKind; + + public SourceAndDecompiledConversionVisitor(@NotNull NavigationKind navigationKind) { + this.navigationKind = navigationKind; + } + @Override public JetDeclaration visitNamedFunction(@NotNull JetNamedFunction function, Void data) { - return getSourceFunction(function); + return convertPropertyOrFunction(function, navigationKind); } @Override public JetDeclaration visitProperty(@NotNull JetProperty property, Void data) { - return getSourceProperty(property); + return convertPropertyOrFunction(property, navigationKind); } @Override public JetDeclaration visitObjectDeclaration(@NotNull JetObjectDeclaration declaration, Void data) { - return getSourceClassOrObject(declaration); + return convertNamedClassOrObject(declaration, navigationKind); } @Override public JetDeclaration visitClass(@NotNull JetClass klass, Void data) { - return getSourceClassOrObject(klass); + return convertNamedClassOrObject(klass, navigationKind); } @Override @@ -455,47 +493,12 @@ public class JetSourceNavigationHelper { @Override public JetDeclaration visitPrimaryConstructor(@NotNull JetPrimaryConstructor constructor, Void data) { - return getSourceFunction(constructor); + return convertPropertyOrFunction(constructor, navigationKind); } @Override public JetDeclaration visitSecondaryConstructor(@NotNull JetSecondaryConstructor constructor, Void data) { - return getSourceFunction(constructor); + return convertPropertyOrFunction(constructor, navigationKind); } } - - private static class LibrarySourcesScope extends GlobalSearchScope { - private final Set sources; - private final ProjectFileIndex fileIndex; - - public LibrarySourcesScope(Project project, Set 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; - } - } - } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/KotlinDeclarationNavigationPolicyImpl.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/KotlinDeclarationNavigationPolicyImpl.kt index 13e2b539ad0..961cd3c8252 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/KotlinDeclarationNavigationPolicyImpl.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/KotlinDeclarationNavigationPolicyImpl.kt @@ -22,13 +22,8 @@ import org.jetbrains.kotlin.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 - } + override fun getOriginalElement(declaration: JetDeclaration) = + JetSourceNavigationHelper.getOriginalElement(declaration) + override fun getNavigationElement(declaration: JetDeclaration) = + JetSourceNavigationHelper.getNavigationElement(declaration) } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/MemberMatching.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/MemberMatching.java index e0c08487a5e..b5f9d4bb01b 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/MemberMatching.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/navigation/MemberMatching.java @@ -34,7 +34,6 @@ import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.renderer.DescriptorRenderer; import org.jetbrains.kotlin.types.JetType; -import java.util.Collections; import java.util.List; import java.util.Set; @@ -42,24 +41,18 @@ public class MemberMatching { /* DECLARATIONS ROUGH MATCHING */ @Nullable private static JetTypeReference getReceiverType(@NotNull JetNamedDeclaration propertyOrFunction) { - if (propertyOrFunction instanceof JetNamedFunction) { - return ((JetNamedFunction) propertyOrFunction).getReceiverTypeReference(); + if (propertyOrFunction instanceof JetCallableDeclaration) { + return ((JetCallableDeclaration) propertyOrFunction).getReceiverTypeReference(); } - if (propertyOrFunction instanceof JetProperty) { - return ((JetProperty) propertyOrFunction).getReceiverTypeReference(); - } - throw new IllegalArgumentException("Neither function nor declaration: " + propertyOrFunction.getClass().getName()); + throw new IllegalArgumentException("Not a callable declaration: " + propertyOrFunction.getClass().getName()); } @NotNull private static List getValueParameters(@NotNull JetNamedDeclaration propertyOrFunction) { - if (propertyOrFunction instanceof JetNamedFunction) { - return ((JetNamedFunction) propertyOrFunction).getValueParameters(); + if (propertyOrFunction instanceof JetCallableDeclaration) { + return ((JetCallableDeclaration) propertyOrFunction).getValueParameters(); } - if (propertyOrFunction instanceof JetProperty) { - return Collections.emptyList(); - } - throw new IllegalArgumentException("Neither function nor declaration: " + propertyOrFunction.getClass().getName()); + throw new IllegalArgumentException("Not a callable declaration: " + propertyOrFunction.getClass().getName()); } private static String getTypeShortName(@NotNull JetTypeReference typeReference) { diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/JetSourceFilterScope.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/JetSourceFilterScope.java index 4eee6d2373e..fb13f12e3fa 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/JetSourceFilterScope.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/JetSourceFilterScope.java @@ -29,22 +29,33 @@ import org.jetbrains.kotlin.idea.util.ProjectRootsUtil; public class JetSourceFilterScope extends DelegatingGlobalSearchScope { @NotNull public static GlobalSearchScope kotlinSourcesAndLibraries(@NotNull GlobalSearchScope delegate, @NotNull Project project) { - return create(delegate, true, true, project); + return create(delegate, true, true, true, project); } @NotNull public static GlobalSearchScope kotlinSourceAndClassFiles(@NotNull GlobalSearchScope delegate, @NotNull Project project) { - return create(delegate, false, true, project); + return create(delegate, true, false, true, project); } @NotNull 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 private static GlobalSearchScope create( @NotNull GlobalSearchScope delegate, + boolean includeProjectSourceFiles, boolean includeLibrarySourceFiles, boolean includeClassFiles, @NotNull Project project @@ -54,29 +65,37 @@ public class JetSourceFilterScope extends DelegatingGlobalSearchScope { if (delegate instanceof JetSourceFilterScope) { JetSourceFilterScope wrappedDelegate = (JetSourceFilterScope) delegate; + boolean doIncludeProjectSourceFiles = wrappedDelegate.includeProjectSourceFiles && includeProjectSourceFiles; boolean doIncludeLibrarySourceFiles = wrappedDelegate.includeLibrarySourceFiles && includeLibrarySourceFiles; 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 Project project; + private final boolean includeProjectSourceFiles; private final boolean includeLibrarySourceFiles; private final boolean includeClassFiles; private final boolean isJsProject; private JetSourceFilterScope( @NotNull GlobalSearchScope delegate, + boolean includeProjectSourceFiles, boolean includeLibrarySourceFiles, boolean includeClassFiles, @NotNull Project project ) { super(delegate); this.project = project; + this.includeProjectSourceFiles = includeProjectSourceFiles; this.includeLibrarySourceFiles = includeLibrarySourceFiles; this.includeClassFiles = includeClassFiles; //NOTE: avoid recomputing in potentially bottleneck 'contains' method @@ -91,10 +110,9 @@ public class JetSourceFilterScope extends DelegatingGlobalSearchScope { @Override public boolean contains(@NotNull VirtualFile file) { - if (!super.contains(file)) { - return false; - } - - return ProjectRootsUtil.isInContent(project, file, true, includeLibrarySourceFiles, includeClassFiles, index, isJsProject); + if (!super.contains(file)) return false; + return ProjectRootsUtil.isInContent( + project, file, includeProjectSourceFiles, includeLibrarySourceFiles, includeClassFiles, index, isJsProject + ); } } diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/OptionalParametersHelper.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/OptionalParametersHelper.kt index 1e757200165..732072ccf4f 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/OptionalParametersHelper.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/OptionalParametersHelper.kt @@ -127,11 +127,8 @@ public object OptionalParametersHelper { //TODO: parameter in overriding method! //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 - if (declaration.getContainingJetFile().isCompiled()) { - declaration = JetSourceNavigationHelper.replaceBySourceDeclarationIfPresent(declaration) as? JetParameter ?: return null - } - val expression = declaration.getDefaultValue() ?: return null + val declaration = DescriptorToSourceUtilsIde.getAnyDeclaration(project, parameter)?.getNavigationElement() as? JetParameter + val expression = declaration?.getDefaultValue() ?: return null val allParameters = (parameter.getContainingDeclaration() as CallableDescriptor).getValueParameters().toSet() diff --git a/idea/testData/findUsages/_library/library/library.kt b/idea/testData/findUsages/_library/library/library.kt new file mode 100644 index 00000000000..076eb5f1ac6 --- /dev/null +++ b/idea/testData/findUsages/_library/library/library.kt @@ -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 +} \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryClassUsages.0.kt b/idea/testData/findUsages/kotlin/library/LibraryClassUsages.0.kt deleted file mode 100644 index 70d2760a3d7..00000000000 --- a/idea/testData/findUsages/kotlin/library/LibraryClassUsages.0.kt +++ /dev/null @@ -1,7 +0,0 @@ -// PSI_ELEMENT: com.intellij.psi.PsiClass -// OPTIONS: usages -// FIND_BY_REF -// FIND_BY_MIRROR_ELEMENT -fun test() { - System.exit(0) -} \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryClassUsages.results.txt b/idea/testData/findUsages/kotlin/library/LibraryClassUsages.results.txt deleted file mode 100644 index a76bc46e444..00000000000 --- a/idea/testData/findUsages/kotlin/library/LibraryClassUsages.results.txt +++ /dev/null @@ -1 +0,0 @@ -Nested class/object (6: 5) System.exit(0) \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryFieldUsages.0.kt b/idea/testData/findUsages/kotlin/library/LibraryFieldUsages.0.kt deleted file mode 100644 index d7ec5f2b2fe..00000000000 --- a/idea/testData/findUsages/kotlin/library/LibraryFieldUsages.0.kt +++ /dev/null @@ -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().width = 1 -} \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryFieldUsages.results.txt b/idea/testData/findUsages/kotlin/library/LibraryFieldUsages.results.txt deleted file mode 100644 index 1f976341332..00000000000 --- a/idea/testData/findUsages/kotlin/library/LibraryFieldUsages.results.txt +++ /dev/null @@ -1 +0,0 @@ -Value write (8: 17) Dimension().width = 1 \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryMethodUsages.0.kt b/idea/testData/findUsages/kotlin/library/LibraryMethodUsages.0.kt deleted file mode 100644 index 4646d65eecc..00000000000 --- a/idea/testData/findUsages/kotlin/library/LibraryMethodUsages.0.kt +++ /dev/null @@ -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().setSize(1.0, 2.0) -} \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryMethodUsages.results.txt b/idea/testData/findUsages/kotlin/library/LibraryMethodUsages.results.txt deleted file mode 100644 index 5d28a340adb..00000000000 --- a/idea/testData/findUsages/kotlin/library/LibraryMethodUsages.results.txt +++ /dev/null @@ -1 +0,0 @@ -Function call (8: 17) Dimension().setSize(1.0, 2.0) \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryStaticFieldUsages.0.kt b/idea/testData/findUsages/kotlin/library/LibraryStaticFieldUsages.0.kt deleted file mode 100644 index 64eb241ef44..00000000000 --- a/idea/testData/findUsages/kotlin/library/LibraryStaticFieldUsages.0.kt +++ /dev/null @@ -1,7 +0,0 @@ -// PSI_ELEMENT: com.intellij.psi.PsiField -// OPTIONS: usages -// FIND_BY_REF -// FIND_BY_MIRROR_ELEMENT -fun test() { - System.out.println() -} \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryStaticFieldUsages.results.txt b/idea/testData/findUsages/kotlin/library/LibraryStaticFieldUsages.results.txt deleted file mode 100644 index 2003de82d8c..00000000000 --- a/idea/testData/findUsages/kotlin/library/LibraryStaticFieldUsages.results.txt +++ /dev/null @@ -1 +0,0 @@ -Receiver (6: 12) System.out.println() \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryStaticMethodUsages.0.kt b/idea/testData/findUsages/kotlin/library/LibraryStaticMethodUsages.0.kt deleted file mode 100644 index 130444998c8..00000000000 --- a/idea/testData/findUsages/kotlin/library/LibraryStaticMethodUsages.0.kt +++ /dev/null @@ -1,7 +0,0 @@ -// PSI_ELEMENT: com.intellij.psi.PsiMethod -// OPTIONS: usages -// FIND_BY_REF -// FIND_BY_MIRROR_ELEMENT -fun test() { - System.exit(0) -} \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/library/LibraryStaticMethodUsages.results.txt b/idea/testData/findUsages/kotlin/library/LibraryStaticMethodUsages.results.txt deleted file mode 100644 index e6b937caf67..00000000000 --- a/idea/testData/findUsages/kotlin/library/LibraryStaticMethodUsages.results.txt +++ /dev/null @@ -1 +0,0 @@ -Function call (6: 12) System.exit(0) \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryClassUsages.results.txt b/idea/testData/findUsages/librarySources/LibraryClassUsages.results.txt deleted file mode 100644 index 04929d95f2f..00000000000 --- a/idea/testData/findUsages/librarySources/LibraryClassUsages.results.txt +++ /dev/null @@ -1,2 +0,0 @@ -Local variable declaration (10: 14) val foo: Foo -Usage in import (7: 16) import library.Foo \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryConstructorUsages.results.txt b/idea/testData/findUsages/librarySources/LibraryConstructorUsages.results.txt deleted file mode 100644 index e5ed6ddd7c2..00000000000 --- a/idea/testData/findUsages/librarySources/LibraryConstructorUsages.results.txt +++ /dev/null @@ -1 +0,0 @@ -New instance creation (10: 5) Foo(1) \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryFieldUsages.results.txt b/idea/testData/findUsages/librarySources/LibraryFieldUsages.results.txt deleted file mode 100644 index d9142005099..00000000000 --- a/idea/testData/findUsages/librarySources/LibraryFieldUsages.results.txt +++ /dev/null @@ -1 +0,0 @@ -Value write (10: 11) Foo().x = 1 \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryMethodUsages.results.txt b/idea/testData/findUsages/librarySources/LibraryMethodUsages.results.txt deleted file mode 100644 index 6f3f7ae387b..00000000000 --- a/idea/testData/findUsages/librarySources/LibraryMethodUsages.results.txt +++ /dev/null @@ -1 +0,0 @@ -Function call (10: 11) Foo().bar(1) \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryStaticFieldUsages.results.txt b/idea/testData/findUsages/librarySources/LibraryStaticFieldUsages.results.txt deleted file mode 100644 index 6a8a6b5d2a1..00000000000 --- a/idea/testData/findUsages/librarySources/LibraryStaticFieldUsages.results.txt +++ /dev/null @@ -1 +0,0 @@ -Value write (10: 9) Foo.X = 1 \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryStaticMethodUsages.results.txt b/idea/testData/findUsages/librarySources/LibraryStaticMethodUsages.results.txt deleted file mode 100644 index 7ed17660478..00000000000 --- a/idea/testData/findUsages/librarySources/LibraryStaticMethodUsages.results.txt +++ /dev/null @@ -1 +0,0 @@ -Function call (10: 9) Foo.baz(1) \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryClassUsages.0.kt b/idea/testData/findUsages/librarySources/javaLibrary/LibraryClassUsages.0.kt similarity index 83% rename from idea/testData/findUsages/librarySources/LibraryClassUsages.0.kt rename to idea/testData/findUsages/librarySources/javaLibrary/LibraryClassUsages.0.kt index e13dd51c382..e494fe47989 100644 --- a/idea/testData/findUsages/librarySources/LibraryClassUsages.0.kt +++ b/idea/testData/findUsages/librarySources/javaLibrary/LibraryClassUsages.0.kt @@ -1,7 +1,6 @@ // PSI_ELEMENT: com.intellij.psi.PsiClass // OPTIONS: usages // FIND_BY_REF -// FIND_BY_NAVIGATION_ELEMENT package usages import library.Foo diff --git a/idea/testData/findUsages/librarySources/javaLibrary/LibraryClassUsages.results.txt b/idea/testData/findUsages/librarySources/javaLibrary/LibraryClassUsages.results.txt new file mode 100644 index 00000000000..a0fc5fe0781 --- /dev/null +++ b/idea/testData/findUsages/librarySources/javaLibrary/LibraryClassUsages.results.txt @@ -0,0 +1,2 @@ +Local variable declaration (9: 14) val foo: Foo +Usage in import (6: 16) import library.Foo \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryConstructorUsages.0.kt b/idea/testData/findUsages/librarySources/javaLibrary/LibraryConstructorUsages.0.kt similarity index 82% rename from idea/testData/findUsages/librarySources/LibraryConstructorUsages.0.kt rename to idea/testData/findUsages/librarySources/javaLibrary/LibraryConstructorUsages.0.kt index ea2916aad98..d545f506d0e 100644 --- a/idea/testData/findUsages/librarySources/LibraryConstructorUsages.0.kt +++ b/idea/testData/findUsages/librarySources/javaLibrary/LibraryConstructorUsages.0.kt @@ -1,7 +1,6 @@ // PSI_ELEMENT: com.intellij.psi.PsiMethod // OPTIONS: usages // FIND_BY_REF -// FIND_BY_NAVIGATION_ELEMENT package usages import library.Foo diff --git a/idea/testData/findUsages/librarySources/javaLibrary/LibraryConstructorUsages.results.txt b/idea/testData/findUsages/librarySources/javaLibrary/LibraryConstructorUsages.results.txt new file mode 100644 index 00000000000..4f212dc2d4e --- /dev/null +++ b/idea/testData/findUsages/librarySources/javaLibrary/LibraryConstructorUsages.results.txt @@ -0,0 +1 @@ +New instance creation (9: 5) Foo(1) \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryFieldUsages.0.kt b/idea/testData/findUsages/librarySources/javaLibrary/LibraryFieldUsages.0.kt similarity index 83% rename from idea/testData/findUsages/librarySources/LibraryFieldUsages.0.kt rename to idea/testData/findUsages/librarySources/javaLibrary/LibraryFieldUsages.0.kt index 950de36492e..6976c72f44c 100644 --- a/idea/testData/findUsages/librarySources/LibraryFieldUsages.0.kt +++ b/idea/testData/findUsages/librarySources/javaLibrary/LibraryFieldUsages.0.kt @@ -1,7 +1,6 @@ // PSI_ELEMENT: com.intellij.psi.PsiField // OPTIONS: usages // FIND_BY_REF -// FIND_BY_NAVIGATION_ELEMENT package usages import library.Foo diff --git a/idea/testData/findUsages/librarySources/javaLibrary/LibraryFieldUsages.results.txt b/idea/testData/findUsages/librarySources/javaLibrary/LibraryFieldUsages.results.txt new file mode 100644 index 00000000000..343f4943d40 --- /dev/null +++ b/idea/testData/findUsages/librarySources/javaLibrary/LibraryFieldUsages.results.txt @@ -0,0 +1 @@ +Value write (9: 11) Foo().x = 1 \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryMethodUsages.0.kt b/idea/testData/findUsages/librarySources/javaLibrary/LibraryMethodUsages.0.kt similarity index 83% rename from idea/testData/findUsages/librarySources/LibraryMethodUsages.0.kt rename to idea/testData/findUsages/librarySources/javaLibrary/LibraryMethodUsages.0.kt index d635467383f..d5e8fb1de19 100644 --- a/idea/testData/findUsages/librarySources/LibraryMethodUsages.0.kt +++ b/idea/testData/findUsages/librarySources/javaLibrary/LibraryMethodUsages.0.kt @@ -1,7 +1,6 @@ // PSI_ELEMENT: com.intellij.psi.PsiMethod // OPTIONS: usages // FIND_BY_REF -// FIND_BY_NAVIGATION_ELEMENT package usages import library.Foo diff --git a/idea/testData/findUsages/librarySources/javaLibrary/LibraryMethodUsages.results.txt b/idea/testData/findUsages/librarySources/javaLibrary/LibraryMethodUsages.results.txt new file mode 100644 index 00000000000..e8a628295e0 --- /dev/null +++ b/idea/testData/findUsages/librarySources/javaLibrary/LibraryMethodUsages.results.txt @@ -0,0 +1 @@ +Function call (9: 11) Foo().bar(1) \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryStaticFieldUsages.0.kt b/idea/testData/findUsages/librarySources/javaLibrary/LibraryStaticFieldUsages.0.kt similarity index 83% rename from idea/testData/findUsages/librarySources/LibraryStaticFieldUsages.0.kt rename to idea/testData/findUsages/librarySources/javaLibrary/LibraryStaticFieldUsages.0.kt index 99bc0c05624..b8dca719a3f 100644 --- a/idea/testData/findUsages/librarySources/LibraryStaticFieldUsages.0.kt +++ b/idea/testData/findUsages/librarySources/javaLibrary/LibraryStaticFieldUsages.0.kt @@ -1,7 +1,6 @@ // PSI_ELEMENT: com.intellij.psi.PsiField // OPTIONS: usages // FIND_BY_REF -// FIND_BY_NAVIGATION_ELEMENT package usages import library.Foo diff --git a/idea/testData/findUsages/librarySources/javaLibrary/LibraryStaticFieldUsages.results.txt b/idea/testData/findUsages/librarySources/javaLibrary/LibraryStaticFieldUsages.results.txt new file mode 100644 index 00000000000..086f8c40ce4 --- /dev/null +++ b/idea/testData/findUsages/librarySources/javaLibrary/LibraryStaticFieldUsages.results.txt @@ -0,0 +1 @@ +Value write (9: 9) Foo.X = 1 \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/LibraryStaticMethodUsages.0.kt b/idea/testData/findUsages/librarySources/javaLibrary/LibraryStaticMethodUsages.0.kt similarity index 83% rename from idea/testData/findUsages/librarySources/LibraryStaticMethodUsages.0.kt rename to idea/testData/findUsages/librarySources/javaLibrary/LibraryStaticMethodUsages.0.kt index e2c89664759..a93e8118b38 100644 --- a/idea/testData/findUsages/librarySources/LibraryStaticMethodUsages.0.kt +++ b/idea/testData/findUsages/librarySources/javaLibrary/LibraryStaticMethodUsages.0.kt @@ -1,7 +1,6 @@ // PSI_ELEMENT: com.intellij.psi.PsiMethod // OPTIONS: usages // FIND_BY_REF -// FIND_BY_NAVIGATION_ELEMENT package usages import library.Foo diff --git a/idea/testData/findUsages/librarySources/javaLibrary/LibraryStaticMethodUsages.results.txt b/idea/testData/findUsages/librarySources/javaLibrary/LibraryStaticMethodUsages.results.txt new file mode 100644 index 00000000000..8ebf107cea2 --- /dev/null +++ b/idea/testData/findUsages/librarySources/javaLibrary/LibraryStaticMethodUsages.results.txt @@ -0,0 +1 @@ +Function call (9: 9) Foo.baz(1) \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryClassUsages.0.kt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryClassUsages.0.kt new file mode 100644 index 00000000000..cb5d7d0d471 --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryClassUsages.0.kt @@ -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: A = A() + val aa = A(1) +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryClassUsages.1.java b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryClassUsages.1.java new file mode 100644 index 00000000000..597cd6a93ce --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryClassUsages.1.java @@ -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); + } +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryClassUsages.results.txt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryClassUsages.results.txt new file mode 100644 index 00000000000..94ac0d1b69a --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryClassUsages.results.txt @@ -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 \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryFunctionUsages.0.kt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryFunctionUsages.0.kt new file mode 100644 index 00000000000..a9a1e96d690 --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryFunctionUsages.0.kt @@ -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 + foo() +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryFunctionUsages.1.java b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryFunctionUsages.1.java new file mode 100644 index 00000000000..ffa435b1e03 --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryFunctionUsages.1.java @@ -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(); + } +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryFunctionUsages.results.txt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryFunctionUsages.results.txt new file mode 100644 index 00000000000..207095f85b0 --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryFunctionUsages.results.txt @@ -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() \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryMemberFunctionUsages.0.kt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryMemberFunctionUsages.0.kt new file mode 100644 index 00000000000..6613af6318d --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryMemberFunctionUsages.0.kt @@ -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().foo(1) +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryMemberFunctionUsages.1.java b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryMemberFunctionUsages.1.java new file mode 100644 index 00000000000..d487a039809 --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryMemberFunctionUsages.1.java @@ -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); + } +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryMemberFunctionUsages.results.txt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryMemberFunctionUsages.results.txt new file mode 100644 index 00000000000..e4010b9dae9 --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryMemberFunctionUsages.results.txt @@ -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) \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassMemberFunctionUsages.0.kt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassMemberFunctionUsages.0.kt new file mode 100644 index 00000000000..85ef1fdc78e --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassMemberFunctionUsages.0.kt @@ -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().bar(1) +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassMemberFunctionUsages.1.java b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassMemberFunctionUsages.1.java new file mode 100644 index 00000000000..bc8264d8ded --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassMemberFunctionUsages.1.java @@ -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); + } +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassMemberFunctionUsages.results.txt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassMemberFunctionUsages.results.txt new file mode 100644 index 00000000000..6aaf2c443b5 --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassMemberFunctionUsages.results.txt @@ -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) \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassPrimaryConstructorUsages.0.kt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassPrimaryConstructorUsages.0.kt new file mode 100644 index 00000000000..160505ea5e2 --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassPrimaryConstructorUsages.0.kt @@ -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.T(1) +} + diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassPrimaryConstructorUsages.1.java b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassPrimaryConstructorUsages.1.java new file mode 100644 index 00000000000..fcad2e95c0c --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassPrimaryConstructorUsages.1.java @@ -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); + } +} diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassPrimaryConstructorUsages.results.txt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassPrimaryConstructorUsages.results.txt new file mode 100644 index 00000000000..14cfff4eead --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassPrimaryConstructorUsages.results.txt @@ -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) \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassSecondaryConstructorUsages.0.kt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassSecondaryConstructorUsages.0.kt new file mode 100644 index 00000000000..947ce629765 --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassSecondaryConstructorUsages.0.kt @@ -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.T() + val aa = A.T(1) +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassSecondaryConstructorUsages.1.java b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassSecondaryConstructorUsages.1.java new file mode 100644 index 00000000000..76e5e14e4de --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassSecondaryConstructorUsages.1.java @@ -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); + } +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassSecondaryConstructorUsages.results.txt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassSecondaryConstructorUsages.results.txt new file mode 100644 index 00000000000..eb90158f4b6 --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassSecondaryConstructorUsages.results.txt @@ -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() \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassUsages.0.kt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassUsages.0.kt new file mode 100644 index 00000000000..bb9ccb1d2df --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassUsages.0.kt @@ -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.T = A.T() + val aa = A.T(1) +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassUsages.1.java b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassUsages.1.java new file mode 100644 index 00000000000..ff70be3d8e8 --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassUsages.1.java @@ -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); + } +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassUsages.results.txt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassUsages.results.txt new file mode 100644 index 00000000000..e983e5c1f10 --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassUsages.results.txt @@ -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 \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryObjectUsages.0.kt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryObjectUsages.0.kt new file mode 100644 index 00000000000..d0159b88a59 --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryObjectUsages.0.kt @@ -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 = O +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryObjectUsages.1.java b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryObjectUsages.1.java new file mode 100644 index 00000000000..654b90c4c01 --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryObjectUsages.1.java @@ -0,0 +1,9 @@ +package usages + +import library.* + +class J { + static void test() { + O o = O.INSTANCE$; + } +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryObjectUsages.results.txt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryObjectUsages.results.txt new file mode 100644 index 00000000000..d1bd5ab8c37 --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryObjectUsages.results.txt @@ -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 \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryPrimaryConstructorUsages.0.kt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryPrimaryConstructorUsages.0.kt new file mode 100644 index 00000000000..ef12a6a72ea --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryPrimaryConstructorUsages.0.kt @@ -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 = A(1) +} + diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryPrimaryConstructorUsages.1.java b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryPrimaryConstructorUsages.1.java new file mode 100644 index 00000000000..f10ff203f06 --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryPrimaryConstructorUsages.1.java @@ -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); + } +} diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryPrimaryConstructorUsages.results.txt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryPrimaryConstructorUsages.results.txt new file mode 100644 index 00000000000..d2264dba7e6 --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibraryPrimaryConstructorUsages.results.txt @@ -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) { \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibrarySecondaryConstructorUsages.0.kt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibrarySecondaryConstructorUsages.0.kt new file mode 100644 index 00000000000..046d7939a6a --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibrarySecondaryConstructorUsages.0.kt @@ -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 = A() + val aa = A(1) +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibrarySecondaryConstructorUsages.1.java b/idea/testData/findUsages/librarySources/kotlinLibrary/LibrarySecondaryConstructorUsages.1.java new file mode 100644 index 00000000000..91a17a8f8cf --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibrarySecondaryConstructorUsages.1.java @@ -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); + } +} \ No newline at end of file diff --git a/idea/testData/findUsages/librarySources/kotlinLibrary/LibrarySecondaryConstructorUsages.results.txt b/idea/testData/findUsages/librarySources/kotlinLibrary/LibrarySecondaryConstructorUsages.results.txt new file mode 100644 index 00000000000..0205858daf3 --- /dev/null +++ b/idea/testData/findUsages/librarySources/kotlinLibrary/LibrarySecondaryConstructorUsages.results.txt @@ -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() { \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/findUsages/AbstractJetFindUsagesTest.java b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractJetFindUsagesTest.java index 2d632fe45b6..463d547afec 100644 --- a/idea/tests/org/jetbrains/kotlin/findUsages/AbstractJetFindUsagesTest.java +++ b/idea/tests/org/jetbrains/kotlin/findUsages/AbstractJetFindUsagesTest.java @@ -33,6 +33,7 @@ import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.PsiPackage; +import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.testFramework.LightProjectDescriptor; 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.JetWithJdkAndRuntimeLightProjectDescriptor; import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; +import org.jetbrains.kotlin.idea.util.ProjectRootsUtil; import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.test.InTextDirectivesUtils; import org.jetbrains.kotlin.test.JetTestUtils; @@ -325,31 +327,42 @@ public abstract class AbstractJetFindUsagesTest extends JetLightCodeInsightFixtu } myFixture.configureByFile(path); - PsiElement originalElement = + PsiElement caretElement = InTextDirectivesUtils.isDirectiveDefined(mainFileText, "// FIND_BY_REF") ? TargetElementUtilBase.findTargetElement(myFixture.getEditor(), - TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED | TargetElementUtil.NEW_AS_CONSTRUCTOR) + TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED | + TargetElementUtil.NEW_AS_CONSTRUCTOR) : myFixture.getElementAtCaret(); - boolean findByMirrorElement = InTextDirectivesUtils.isDirectiveDefined(mainFileText, "// FIND_BY_MIRROR_ELEMENT"); - boolean findByNavigationElement = InTextDirectivesUtils.isDirectiveDefined(mainFileText, "// FIND_BY_NAVIGATION_ELEMENT"); - if (findByMirrorElement && findByNavigationElement) { - fail("Incompatible directives"); - } + assertNotNull(caretElement); + assertInstanceOf(caretElement, caretElementClass); - if (findByMirrorElement) { - assert originalElement instanceof PsiCompiledElement : "PsiCompiledElement is expected: " + originalElement; - 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); + PsiFile containingFile = caretElement.getContainingFile(); + boolean isLibraryElement = containingFile != null && ProjectRootsUtil.isLibraryFile(getProject(), containingFile.getVirtualFile()); 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 void findUsagesAndCheckResults( + String mainFileText, + String prefix, + String rootPath, + T caretElement, + FindUsagesOptions options + ) throws ClassNotFoundException, InstantiationException, IllegalAccessException { Collection usageInfos = findUsages(caretElement, options); Collection filteringRules = instantiateClasses(mainFileText, "// FILTERING_RULES: "); @@ -415,6 +428,8 @@ public abstract class AbstractJetFindUsagesTest extends JetLightCodeInsightFixtu options = handler.getFindUsagesOptions(null); } + options.searchScope = GlobalSearchScope.allScope(project); + CommonProcessors.CollectProcessor processor = new CommonProcessors.CollectProcessor(); PsiElement[] psiElements = ArrayUtil.mergeArrays(handler.getPrimaryElements(), handler.getSecondaryElements()); diff --git a/idea/tests/org/jetbrains/kotlin/findUsages/JetFindUsagesTestGenerated.java b/idea/tests/org/jetbrains/kotlin/findUsages/JetFindUsagesTestGenerated.java index 3c17f2ad861..303d2b2227e 100644 --- a/idea/tests/org/jetbrains/kotlin/findUsages/JetFindUsagesTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/findUsages/JetFindUsagesTestGenerated.java @@ -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") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/idea/tests/org/jetbrains/kotlin/findUsages/KotlinFindUsagesInLibrarySourceTestGenerated.java b/idea/tests/org/jetbrains/kotlin/findUsages/KotlinFindUsagesInLibrarySourceTestGenerated.java index ff14c613d34..3295197a29d 100644 --- a/idea/tests/org/jetbrains/kotlin/findUsages/KotlinFindUsagesInLibrarySourceTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/findUsages/KotlinFindUsagesInLibrarySourceTestGenerated.java @@ -35,39 +35,117 @@ public class KotlinFindUsagesInLibrarySourceTestGenerated extends AbstractKotlin JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/findUsages/librarySources"), Pattern.compile("^(.+)\\.0\\.kt$"), true); } - @TestMetadata("LibraryClassUsages.0.kt") - public void testLibraryClassUsages() throws Exception { - String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/LibraryClassUsages.0.kt"); - doTest(fileName); + @TestMetadata("idea/testData/findUsages/librarySources/javaLibrary") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + 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") - public void testLibraryConstructorUsages() throws Exception { - String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/LibraryConstructorUsages.0.kt"); - doTest(fileName); - } + @TestMetadata("idea/testData/findUsages/librarySources/kotlinLibrary") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + 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") - public void testLibraryFieldUsages() throws Exception { - String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/LibraryFieldUsages.0.kt"); - doTest(fileName); - } + @TestMetadata("LibraryClassUsages.0.kt") + public void testLibraryClassUsages() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/kotlinLibrary/LibraryClassUsages.0.kt"); + doTest(fileName); + } - @TestMetadata("LibraryMethodUsages.0.kt") - public void testLibraryMethodUsages() throws Exception { - String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/LibraryMethodUsages.0.kt"); - doTest(fileName); - } + @TestMetadata("LibraryFunctionUsages.0.kt") + public void testLibraryFunctionUsages() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/kotlinLibrary/LibraryFunctionUsages.0.kt"); + doTest(fileName); + } - @TestMetadata("LibraryStaticFieldUsages.0.kt") - public void testLibraryStaticFieldUsages() throws Exception { - String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/LibraryStaticFieldUsages.0.kt"); - doTest(fileName); - } + @TestMetadata("LibraryMemberFunctionUsages.0.kt") + public void testLibraryMemberFunctionUsages() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/kotlinLibrary/LibraryMemberFunctionUsages.0.kt"); + doTest(fileName); + } - @TestMetadata("LibraryStaticMethodUsages.0.kt") - public void testLibraryStaticMethodUsages() throws Exception { - String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/LibraryStaticMethodUsages.0.kt"); - doTest(fileName); + @TestMetadata("LibraryNestedClassMemberFunctionUsages.0.kt") + public void testLibraryNestedClassMemberFunctionUsages() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/librarySources/kotlinLibrary/LibraryNestedClassMemberFunctionUsages.0.kt"); + 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); + } } }