Using indexes for getClassNames()
This commit is contained in:
+20
@@ -24,12 +24,14 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.PsiSearchScopeUtil;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.asJava.LightClassConstructionContext;
|
||||
import org.jetbrains.jet.asJava.LightClassGenerationSupport;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
@@ -39,6 +41,7 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class solves the problem of interdependency between analyzing Kotlin code and generating JetLightClasses
|
||||
@@ -112,4 +115,21 @@ public class CliLightClassGenerationSupport extends LightClassGenerationSupport
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetClassOrObject> findClassOrObjectDeclarationsInPackage(
|
||||
@NotNull FqName packageFqName, @NotNull GlobalSearchScope searchScope
|
||||
) {
|
||||
Collection<JetFile> files = findFilesForPackage(packageFqName, searchScope);
|
||||
List<JetClassOrObject> result = new SmartList<JetClassOrObject>();
|
||||
for (JetFile file : files) {
|
||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||
if (declaration instanceof JetClassOrObject) {
|
||||
result.add((JetClassOrObject) declaration);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.asJava;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.*;
|
||||
@@ -176,19 +177,20 @@ public class JavaElementFinder extends PsiElementFinder implements JavaPsiFacade
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<String> getClassNames(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
|
||||
Set<String> answer = new HashSet<String>();
|
||||
|
||||
FqName packageFQN = new FqName(psiPackage.getQualifiedName());
|
||||
for (JetFile psiFile : collectProjectJetFiles(project, GlobalSearchScope.allScope(project))) {
|
||||
if (packageFQN.equals(JetPsiUtil.getFQName(psiFile))) {
|
||||
answer.add(JvmAbi.PACKAGE_CLASS);
|
||||
for (JetDeclaration declaration : psiFile.getDeclarations()) {
|
||||
if (declaration instanceof JetClassOrObject) {
|
||||
answer.add(getLocalName(declaration));
|
||||
}
|
||||
}
|
||||
|
||||
Collection<JetClassOrObject> declarations = lightClassGenerationSupport.findClassOrObjectDeclarationsInPackage(packageFQN, scope);
|
||||
|
||||
Set<String> answer = Sets.newHashSet();
|
||||
answer.add(JvmAbi.PACKAGE_CLASS);
|
||||
|
||||
for (JetClassOrObject declaration : declarations) {
|
||||
String name = declaration.getName();
|
||||
if (name != null) {
|
||||
answer.add(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,26 +239,18 @@ public class JavaElementFinder extends PsiElementFinder implements JavaPsiFacade
|
||||
@Override
|
||||
public PsiClass[] getClasses(@NotNull PsiPackage psiPackage, @NotNull GlobalSearchScope scope) {
|
||||
List<PsiClass> answer = new SmartList<PsiClass>();
|
||||
final Collection<JetFile> filesInScope = collectProjectJetFiles(project, scope);
|
||||
FqName packageFQN = new FqName(psiPackage.getQualifiedName());
|
||||
for (JetFile file : filesInScope) {
|
||||
if (packageFQN.equals(JetPsiUtil.getFQName(file))) {
|
||||
JetLightClass lightClass = JetLightClass
|
||||
.create(psiManager, file, QualifiedNamesUtil.combine(packageFQN, Name.identifier(JvmAbi.PACKAGE_CLASS)));
|
||||
if (lightClass != null) {
|
||||
answer.add(lightClass);
|
||||
}
|
||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||
if (declaration instanceof JetClassOrObject) {
|
||||
String localName = getLocalName(declaration);
|
||||
if (localName != null) {
|
||||
JetLightClass aClass = JetLightClass.create(psiManager, file,
|
||||
QualifiedNamesUtil.combine(packageFQN, Name.identifier(localName)));
|
||||
if (aClass != null) {
|
||||
answer.add(aClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
findPackageClass(packageFQN, scope, answer);
|
||||
|
||||
Collection<JetClassOrObject> declarations = lightClassGenerationSupport.findClassOrObjectDeclarationsInPackage(packageFQN, scope);
|
||||
for (JetClassOrObject declaration : declarations) {
|
||||
String localName = getLocalName(declaration);
|
||||
if (localName != null) {
|
||||
JetLightClass aClass = JetLightClass.create(psiManager, (JetFile) declaration.getContainingFile(),
|
||||
QualifiedNamesUtil.combine(packageFQN, Name.identifier(localName)));
|
||||
if (aClass != null) {
|
||||
answer.add(aClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,4 +44,11 @@ public abstract class LightClassGenerationSupport {
|
||||
*/
|
||||
@NotNull
|
||||
public abstract Collection<JetFile> findFilesForPackage(@NotNull FqName fqName, @NotNull GlobalSearchScope searchScope);
|
||||
|
||||
// Returns only immediately declared classes/objects, package classes are not included (they have no declarations)
|
||||
@NotNull
|
||||
public abstract Collection<JetClassOrObject> findClassOrObjectDeclarationsInPackage(
|
||||
@NotNull FqName packageFqName,
|
||||
@NotNull GlobalSearchScope searchScope
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.jet.asJava.LightClassGenerationSupport;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetClassByPackageIndex;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetFullClassNameIndex;
|
||||
import org.jetbrains.jet.plugin.stubindex.JetPackageDeclarationIndex;
|
||||
|
||||
@@ -56,4 +57,12 @@ public class IDELightClassGenerationSupport extends LightClassGenerationSupport
|
||||
public Collection<JetFile> findFilesForPackage(@NotNull FqName fqName, @NotNull GlobalSearchScope searchScope) {
|
||||
return JetPackageDeclarationIndex.getInstance().get(fqName.getFqName(), project, searchScope);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetClassOrObject> findClassOrObjectDeclarationsInPackage(
|
||||
@NotNull FqName packageFqName, @NotNull GlobalSearchScope searchScope
|
||||
) {
|
||||
return JetClassByPackageIndex.getInstance().get(packageFqName.getFqName(), project, searchScope);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user