Remove heuristic from PackageCodegen
Implement the logic in a more straightforward way, move the heuristic to JavaElementFinder where it was also used
This commit is contained in:
@@ -34,10 +34,7 @@ import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.SLRUCache;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.codegen.PackageCodegen;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetEnumEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaPsiFacadeKotlinHacks;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
@@ -144,20 +141,30 @@ public class JavaElementFinder extends PsiElementFinder implements JavaPsiFacade
|
||||
|
||||
private void findPackageClass(FqName qualifiedName, GlobalSearchScope scope, List<PsiClass> answer) {
|
||||
Collection<JetFile> filesForPackage = lightClassGenerationSupport.findFilesForPackage(qualifiedName, scope);
|
||||
if (!shouldGeneratePackageClass(filesForPackage)) return;
|
||||
|
||||
if (!filesForPackage.isEmpty() && PackageCodegen.shouldGeneratePackageClass(filesForPackage)) {
|
||||
KotlinLightClassForPackage lightClass = KotlinLightClassForPackage.create(psiManager, qualifiedName, scope, filesForPackage);
|
||||
if (lightClass != null) {
|
||||
answer.add(lightClass);
|
||||
KotlinLightClassForPackage lightClass = KotlinLightClassForPackage.create(psiManager, qualifiedName, scope, filesForPackage);
|
||||
if (lightClass == null) return;
|
||||
|
||||
if (filesForPackage.size() > 1) {
|
||||
for (JetFile file : filesForPackage) {
|
||||
FakeLightClassForFileOfPackage fakeLightClass = new FakeLightClassForFileOfPackage(psiManager, lightClass, file);
|
||||
answer.add(fakeLightClass);
|
||||
}
|
||||
answer.add(lightClass);
|
||||
|
||||
if (filesForPackage.size() > 1) {
|
||||
for (JetFile file : filesForPackage) {
|
||||
answer.add(new FakeLightClassForFileOfPackage(psiManager, lightClass, file));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldGeneratePackageClass(@NotNull Collection<JetFile> packageFiles) {
|
||||
for (JetFile file : packageFiles) {
|
||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||
if (declaration instanceof JetProperty || declaration instanceof JetNamedFunction) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user