Minor refactoring in ResolveSessionUtils
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.lang.resolve.lazy;
|
package org.jetbrains.jet.lang.resolve.lazy;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.intellij.util.containers.Predicate;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
@@ -41,19 +42,33 @@ public class ResolveSessionUtils {
|
|||||||
// The name contains a GUID to avoid clashes, if a clash happens, it's not a big deal: the code does not compile anyway
|
// The name contains a GUID to avoid clashes, if a clash happens, it's not a big deal: the code does not compile anyway
|
||||||
public static final Name NO_NAME_FOR_LAZY_RESOLVE = Name.identifier("no_name_in_PSI_for_lazy_resolve_3d19d79d_1ba9_4cd0_b7f5_b46aa3cd5d40");
|
public static final Name NO_NAME_FOR_LAZY_RESOLVE = Name.identifier("no_name_in_PSI_for_lazy_resolve_3d19d79d_1ba9_4cd0_b7f5_b46aa3cd5d40");
|
||||||
|
|
||||||
|
public static final Predicate<ClassDescriptor> NON_SINGLETON_FILTER = new Predicate<ClassDescriptor>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(ClassDescriptor descriptor) {
|
||||||
|
return !descriptor.getKind().isSingleton();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final Predicate<ClassDescriptor> SINGLETON_FILTER = new Predicate<ClassDescriptor>() {
|
||||||
|
@Override
|
||||||
|
public boolean apply(ClassDescriptor descriptor) {
|
||||||
|
return descriptor.getKind().isSingleton();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private ResolveSessionUtils() {
|
private ResolveSessionUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Collection<ClassDescriptor> getClassDescriptorsByFqName(@NotNull KotlinCodeAnalyzer analyzer, @NotNull FqName fqName) {
|
public static Collection<ClassDescriptor> getClassDescriptorsByFqName(@NotNull KotlinCodeAnalyzer analyzer, @NotNull FqName fqName) {
|
||||||
return getClassOrObjectDescriptorsByFqName(analyzer, fqName, false);
|
return getClassOrObjectDescriptorsByFqName(analyzer, fqName, NON_SINGLETON_FILTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Collection<ClassDescriptor> getClassOrObjectDescriptorsByFqName(
|
public static Collection<ClassDescriptor> getClassOrObjectDescriptorsByFqName(
|
||||||
@NotNull KotlinCodeAnalyzer analyzer,
|
@NotNull KotlinCodeAnalyzer analyzer,
|
||||||
@NotNull FqName fqName,
|
@NotNull FqName fqName,
|
||||||
boolean includeObjectDeclarations
|
@NotNull Predicate<ClassDescriptor> filter
|
||||||
) {
|
) {
|
||||||
if (fqName.isRoot()) {
|
if (fqName.isRoot()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
@@ -66,8 +81,7 @@ public class ResolveSessionUtils {
|
|||||||
PackageViewDescriptor packageDescriptor = analyzer.getModuleDescriptor().getPackage(packageFqName);
|
PackageViewDescriptor packageDescriptor = analyzer.getModuleDescriptor().getPackage(packageFqName);
|
||||||
if (packageDescriptor != null) {
|
if (packageDescriptor != null) {
|
||||||
FqName classInPackagePath = new FqName(QualifiedNamesUtil.tail(packageFqName, fqName));
|
FqName classInPackagePath = new FqName(QualifiedNamesUtil.tail(packageFqName, fqName));
|
||||||
Collection<ClassDescriptor> descriptors = getClassOrObjectDescriptorsByFqName(packageDescriptor, classInPackagePath,
|
Collection<ClassDescriptor> descriptors = getClassOrObjectDescriptorsByFqName(packageDescriptor, classInPackagePath, filter);
|
||||||
includeObjectDeclarations);
|
|
||||||
classDescriptors.addAll(descriptors);
|
classDescriptors.addAll(descriptors);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +100,7 @@ public class ResolveSessionUtils {
|
|||||||
private static Collection<ClassDescriptor> getClassOrObjectDescriptorsByFqName(
|
private static Collection<ClassDescriptor> getClassOrObjectDescriptorsByFqName(
|
||||||
@NotNull PackageViewDescriptor packageDescriptor,
|
@NotNull PackageViewDescriptor packageDescriptor,
|
||||||
@NotNull FqName path,
|
@NotNull FqName path,
|
||||||
boolean includeObjectDeclarations
|
@NotNull Predicate<ClassDescriptor> filter
|
||||||
) {
|
) {
|
||||||
if (path.isRoot()) {
|
if (path.isRoot()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
@@ -112,8 +126,7 @@ public class ResolveSessionUtils {
|
|||||||
Collection<ClassDescriptor> resultClassifierDescriptors = Lists.newArrayList();
|
Collection<ClassDescriptor> resultClassifierDescriptors = Lists.newArrayList();
|
||||||
for (JetScope scope : scopes) {
|
for (JetScope scope : scopes) {
|
||||||
ClassifierDescriptor classifier = scope.getClassifier(shortName);
|
ClassifierDescriptor classifier = scope.getClassifier(shortName);
|
||||||
if (classifier instanceof ClassDescriptor &&
|
if (classifier instanceof ClassDescriptor && filter.apply((ClassDescriptor) classifier)) {
|
||||||
includeObjectDeclarations == ((ClassDescriptor) classifier).getKind().isSingleton()) {
|
|
||||||
resultClassifierDescriptors.add((ClassDescriptor) classifier);
|
resultClassifierDescriptors.add((ClassDescriptor) classifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ public class JetShortNamesCache extends PsiShortNamesCache {
|
|||||||
for (JetObjectDeclaration objectDeclaration : topObjects) {
|
for (JetObjectDeclaration objectDeclaration : topObjects) {
|
||||||
FqName fqName = JetPsiUtil.getFQName(objectDeclaration);
|
FqName fqName = JetPsiUtil.getFQName(objectDeclaration);
|
||||||
assert fqName != null : "Local object declaration in JetTopLevelShortObjectNameIndex:" + objectDeclaration.getText();
|
assert fqName != null : "Local object declaration in JetTopLevelShortObjectNameIndex:" + objectDeclaration.getText();
|
||||||
result.addAll(ResolveSessionUtils.getClassOrObjectDescriptorsByFqName(resolveSession, fqName, true));
|
result.addAll(ResolveSessionUtils.getClassOrObjectDescriptorsByFqName(resolveSession, fqName, ResolveSessionUtils.SINGLETON_FILTER));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (PsiClass psiClass : JetFromJavaDescriptorHelper
|
for (PsiClass psiClass : JetFromJavaDescriptorHelper
|
||||||
@@ -205,7 +205,7 @@ public class JetShortNamesCache extends PsiShortNamesCache {
|
|||||||
String qualifiedName = psiClass.getQualifiedName();
|
String qualifiedName = psiClass.getQualifiedName();
|
||||||
if (qualifiedName != null) {
|
if (qualifiedName != null) {
|
||||||
FqName fqName = new FqName(qualifiedName);
|
FqName fqName = new FqName(qualifiedName);
|
||||||
result.addAll(ResolveSessionUtils.getClassOrObjectDescriptorsByFqName(resolveSession, fqName, true));
|
result.addAll(ResolveSessionUtils.getClassOrObjectDescriptorsByFqName(resolveSession, fqName, ResolveSessionUtils.SINGLETON_FILTER));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user