[psi] KtNamedDeclarationStub: fix useScope for private class

The `return` was missed, so the private class did not optimize scope

^KTIJ-20069
This commit is contained in:
Dmitry Gridin
2021-11-03 21:13:44 +07:00
committed by Space
parent 711b882e71
commit 5ecd2aa191
@@ -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<T extends KotlinStubWithFqName<?>> 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<T extends KotlinStubWithFqName<?>> 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);