diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedDeclarationStub.java b/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedDeclarationStub.java index 42a7466506a..eb6d4f4cfa0 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedDeclarationStub.java +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtNamedDeclarationStub.java @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.psi; @@ -22,7 +11,10 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiPackage; -import com.intellij.psi.search.*; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.LocalSearchScope; +import com.intellij.psi.search.PackageScope; +import com.intellij.psi.search.SearchScope; import com.intellij.psi.stubs.IStubElementType; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.IncorrectOperationException; @@ -150,7 +142,7 @@ abstract class KtNamedDeclarationStub> extends } if (enclosingBlock instanceof KtBlockExpression && enclosingParent instanceof KtDoWhileExpression) { KtExpression condition = ((KtDoWhileExpression) enclosingParent).getCondition(); - if (condition != null) return new LocalSearchScope(new PsiElement[] { enclosingBlock, condition }); + if (condition != null) return new LocalSearchScope(new PsiElement[] {enclosingBlock, condition}); } return new LocalSearchScope(enclosingBlock); @@ -181,11 +173,15 @@ abstract class KtNamedDeclarationStub> extends GlobalSearchScope.allScope(project), KotlinFileType.INSTANCE ); + + SearchScope fileScope = GlobalSearchScope.fileScope(ktFile); PsiPackage psiPackage = JavaPsiFacade.getInstance(project).findPackage(ktFile.getPackageFqName().asString()); - SearchScope baseScope = psiPackage != null - ? new PackageScope(psiPackage, false, true) - : super.getUseScope(); - baseScope.intersectWith(GlobalSearchScope.notScope(kotlinFilesScope)); + SearchScope superScope = super.getUseScope(); // TODO: should be replaced with module scope if possible + if (psiPackage == null) return superScope; + + SearchScope jvmScope = PackageScope.packageScope(psiPackage, false).intersectWith(superScope); + SearchScope nonKotlinJvmScope = GlobalSearchScope.notScope(kotlinFilesScope).intersectWith(jvmScope); + return fileScope.union(nonKotlinJvmScope); } else { return new LocalSearchScope(ktFile);