Refactor: refine API of LightClassGenerationSupport
Move some specific code to IDELightClassGenerationSupport
This commit is contained in:
@@ -36,10 +36,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
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.resolve.java.JavaPsiFacadeKotlinHacks;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.PackagePartClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.NamePackage;
|
||||
|
||||
@@ -121,7 +119,7 @@ public class JavaElementFinder extends PsiElementFinder implements JavaPsiFacade
|
||||
findClassesAndObjects(qualifiedName, scope, answer);
|
||||
|
||||
if (PackageClassUtils.isPackageClassFqName(qualifiedName)) {
|
||||
findPackageClass(qualifiedName.parent(), scope, answer);
|
||||
answer.addAll(lightClassGenerationSupport.getPackageClasses(qualifiedName.parent(), scope));
|
||||
}
|
||||
|
||||
return answer.toArray(new PsiClass[answer.size()]);
|
||||
@@ -142,26 +140,6 @@ public class JavaElementFinder extends PsiElementFinder implements JavaPsiFacade
|
||||
}
|
||||
}
|
||||
|
||||
private void findPackageClass(FqName qualifiedName, GlobalSearchScope scope, List<PsiClass> answer) {
|
||||
List<LightClassGenerationSupport.KotlinLightPackageClassInfo>
|
||||
packageClassesInfos = lightClassGenerationSupport.findPackageClassesInfos(qualifiedName, scope);
|
||||
for (LightClassGenerationSupport.KotlinLightPackageClassInfo info : packageClassesInfos) {
|
||||
Collection<JetFile> files = info.getFiles();
|
||||
if (PackagePartClassUtils.getPackageFilesWithCallables(files).isEmpty()) continue;
|
||||
KotlinLightClassForPackage lightClass =
|
||||
KotlinLightClassForPackage.create(psiManager, qualifiedName, info.getScope(), files);
|
||||
if (lightClass == null) continue;
|
||||
|
||||
answer.add(lightClass);
|
||||
|
||||
if (files.size() > 1) {
|
||||
for (JetFile file : files) {
|
||||
answer.add(new FakeLightClassForFileOfPackage(psiManager, lightClass, file));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<String> getClassNames(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
|
||||
@@ -222,7 +200,7 @@ public class JavaElementFinder extends PsiElementFinder implements JavaPsiFacade
|
||||
List<PsiClass> answer = new SmartList<PsiClass>();
|
||||
FqName packageFQN = new FqName(psiPackage.getQualifiedName());
|
||||
|
||||
findPackageClass(packageFQN, scope, answer);
|
||||
answer.addAll(lightClassGenerationSupport.getPackageClasses(packageFQN, scope));
|
||||
|
||||
Collection<JetClassOrObject> declarations = lightClassGenerationSupport.findClassOrObjectDeclarationsInPackage(packageFQN, scope);
|
||||
for (JetClassOrObject declaration : declarations) {
|
||||
|
||||
+2
-26
@@ -27,7 +27,6 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class LightClassGenerationSupport {
|
||||
|
||||
@@ -55,12 +54,6 @@ public abstract class LightClassGenerationSupport {
|
||||
@NotNull
|
||||
public abstract Collection<JetFile> findFilesForPackage(@NotNull FqName fqName, @NotNull GlobalSearchScope searchScope);
|
||||
|
||||
@NotNull
|
||||
public abstract List<KotlinLightPackageClassInfo> findPackageClassesInfos(
|
||||
@NotNull FqName fqName,
|
||||
@NotNull GlobalSearchScope wholeScope
|
||||
);
|
||||
|
||||
// Returns only immediately declared classes/objects, package classes are not included (they have no declarations)
|
||||
@NotNull
|
||||
public abstract Collection<JetClassOrObject> findClassOrObjectDeclarationsInPackage(
|
||||
@@ -76,23 +69,6 @@ public abstract class LightClassGenerationSupport {
|
||||
@Nullable
|
||||
public abstract PsiClass getPsiClass(@NotNull JetClassOrObject classOrObject);
|
||||
|
||||
public final class KotlinLightPackageClassInfo {
|
||||
private final Collection<JetFile> files;
|
||||
private final GlobalSearchScope scope;
|
||||
|
||||
public KotlinLightPackageClassInfo(@NotNull Collection<JetFile> files, @NotNull GlobalSearchScope scope) {
|
||||
this.files = files;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<JetFile> getFiles() {
|
||||
return files;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public GlobalSearchScope getScope() {
|
||||
return scope;
|
||||
}
|
||||
}
|
||||
@NotNull
|
||||
public abstract Collection<PsiClass> getPackageClasses(@NotNull FqName packageFqName, @NotNull GlobalSearchScope scope);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user