Add method for getting all classifiers with given name from the scope
This commit is contained in:
+7
@@ -160,6 +160,13 @@ public abstract class DeserializedMemberScope implements JetScope {
|
||||
return getClassDescriptor(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public final Collection<ClassifierDescriptor> getClassifiers(@NotNull Name name) {
|
||||
ClassifierDescriptor classifier = getClassifier(name);
|
||||
return classifier != null ? Collections.singleton(classifier) : Collections.<ClassifierDescriptor>emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract ClassifierDescriptor getClassDescriptor(@NotNull Name name);
|
||||
|
||||
|
||||
@@ -244,6 +244,12 @@ public class LazyImportScope implements JetScope {
|
||||
return selectFirstFromImports(name, LookupMode.ONLY_CLASSES, JetScopeSelectorUtil.CLASSIFIER_DESCRIPTOR_SCOPE_SELECTOR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ClassifierDescriptor> getClassifiers(@NotNull Name name) {
|
||||
return collectFromImports(name, LookupMode.ONLY_CLASSES, JetScopeSelectorUtil.NAMED_CLASSIFIERS_SCOPE_SELECTOR);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PackageViewDescriptor getPackage(@NotNull Name name) {
|
||||
|
||||
+12
-6
@@ -46,7 +46,7 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
||||
protected final DP declarationProvider;
|
||||
protected final D thisDescriptor;
|
||||
|
||||
private final MemoizedFunctionToNotNull<Name, List<ClassDescriptor>> classDescriptors;
|
||||
private final MemoizedFunctionToNotNull<Name, List<ClassifierDescriptor>> classDescriptors;
|
||||
|
||||
private final MemoizedFunctionToNotNull<Name, Set<FunctionDescriptor>> functionDescriptors;
|
||||
private final MemoizedFunctionToNotNull<Name, Set<VariableDescriptor>> propertyDescriptors;
|
||||
@@ -63,9 +63,9 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
||||
this.thisDescriptor = thisDescriptor;
|
||||
|
||||
StorageManager storageManager = resolveSession.getStorageManager();
|
||||
this.classDescriptors = storageManager.createMemoizedFunction(new Function1<Name, List<ClassDescriptor>>() {
|
||||
this.classDescriptors = storageManager.createMemoizedFunction(new Function1<Name, List<ClassifierDescriptor>>() {
|
||||
@Override
|
||||
public List<ClassDescriptor> invoke(Name name) {
|
||||
public List<ClassifierDescriptor> invoke(Name name) {
|
||||
return resolveClassDescriptor(name);
|
||||
}
|
||||
});
|
||||
@@ -92,12 +92,12 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private List<ClassDescriptor> resolveClassDescriptor(@NotNull final Name name) {
|
||||
private List<ClassifierDescriptor> resolveClassDescriptor(@NotNull final Name name) {
|
||||
Collection<JetClassOrObject> classOrObjectDeclarations = declarationProvider.getClassOrObjectDeclarations(name);
|
||||
|
||||
return ContainerUtil.mapNotNull(classOrObjectDeclarations, new Function<JetClassOrObject, ClassDescriptor>() {
|
||||
return ContainerUtil.mapNotNull(classOrObjectDeclarations, new Function<JetClassOrObject, ClassifierDescriptor>() {
|
||||
@Override
|
||||
public ClassDescriptor fun(JetClassOrObject classOrObject) {
|
||||
public ClassifierDescriptor fun(JetClassOrObject classOrObject) {
|
||||
return new LazyClassDescriptor(resolveSession, thisDescriptor, name, JetClassInfoUtil.createClassLikeInfo(classOrObject));
|
||||
}
|
||||
});
|
||||
@@ -108,6 +108,12 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
||||
return first(classDescriptors.invoke(name));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ClassifierDescriptor> getClassifiers(@NotNull Name name) {
|
||||
return classDescriptors.invoke(name);
|
||||
}
|
||||
|
||||
private static <T> T first(@NotNull List<T> list) {
|
||||
if (list.isEmpty()) return null;
|
||||
return list.get(0);
|
||||
|
||||
@@ -55,6 +55,12 @@ public abstract class AbstractScopeAdapter implements JetScope {
|
||||
return getWorkerScope().getClassifier(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ClassifierDescriptor> getClassifiers(@NotNull Name name) {
|
||||
return getWorkerScope().getClassifiers(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
|
||||
|
||||
@@ -51,6 +51,12 @@ public class ChainedScope implements JetScope {
|
||||
return getFirstMatch(scopeChain, name, CLASSIFIER_DESCRIPTOR_SCOPE_SELECTOR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ClassifierDescriptor> getClassifiers(@NotNull Name name) {
|
||||
return getFromAllScopes(scopeChain, name, NAMED_CLASSIFIERS_SCOPE_SELECTOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackageViewDescriptor getPackage(@NotNull Name name) {
|
||||
return getFirstMatch(scopeChain, name, PACKAGE_SCOPE_SELECTOR);
|
||||
|
||||
@@ -66,6 +66,12 @@ public class FilteringScope implements JetScope {
|
||||
return filterDescriptor(workerScope.getClassifier(name));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ClassifierDescriptor> getClassifiers(@NotNull Name name) {
|
||||
return Collections2.filter(workerScope.getClassifiers(name), predicate);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
|
||||
|
||||
@@ -53,6 +53,10 @@ public interface JetScope {
|
||||
@Nullable
|
||||
ClassifierDescriptor getClassifier(@NotNull Name name);
|
||||
|
||||
@NotNull
|
||||
@ReadOnly
|
||||
Collection<ClassifierDescriptor> getClassifiers(@NotNull Name name);
|
||||
|
||||
@Nullable
|
||||
PackageViewDescriptor getPackage(@NotNull Name name);
|
||||
|
||||
|
||||
@@ -34,6 +34,12 @@ public abstract class JetScopeImpl implements JetScope {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ClassifierDescriptor> getClassifiers(@NotNull Name name) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
|
||||
|
||||
@@ -112,6 +112,15 @@ public class JetScopeSelectorUtil {
|
||||
}
|
||||
};
|
||||
|
||||
public static final ScopeByNameMultiSelector<ClassifierDescriptor> NAMED_CLASSIFIERS_SCOPE_SELECTOR =
|
||||
new ScopeByNameMultiSelector<ClassifierDescriptor>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ClassifierDescriptor> get(@NotNull JetScope scope, @NotNull Name name) {
|
||||
return scope.getClassifiers(name);
|
||||
}
|
||||
};
|
||||
|
||||
public static final ScopeDescriptorSelector<DeclarationDescriptor> ALL_DESCRIPTORS_SCOPE_SELECTOR =
|
||||
new ScopeDescriptorSelector<DeclarationDescriptor>() {
|
||||
@NotNull
|
||||
|
||||
@@ -98,6 +98,12 @@ public class SubstitutingScope implements JetScope {
|
||||
return substitute(workerScope.getClassifier(name));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ClassifierDescriptor> getClassifiers(@NotNull Name name) {
|
||||
return substitute(workerScope.getClassifiers(name));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
|
||||
|
||||
@@ -85,6 +85,12 @@ public class ErrorUtils {
|
||||
return ERROR_CLASS;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ClassifierDescriptor> getClassifiers(@NotNull Name name) {
|
||||
return ERROR_CLASSIFIER_GROUP;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<VariableDescriptor> getProperties(@NotNull Name name) {
|
||||
@@ -161,6 +167,12 @@ public class ErrorUtils {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<ClassifierDescriptor> getClassifiers(@NotNull Name name) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public PackageViewDescriptor getPackage(@NotNull Name name) {
|
||||
@@ -254,6 +266,7 @@ public class ErrorUtils {
|
||||
ERROR_PROPERTY_TYPE,
|
||||
CallableMemberDescriptor.Kind.DECLARATION);
|
||||
private static final Set<VariableDescriptor> ERROR_PROPERTY_GROUP = Collections.singleton(ERROR_PROPERTY);
|
||||
private static final Set<ClassifierDescriptor> ERROR_CLASSIFIER_GROUP = Collections.<ClassifierDescriptor>singleton(ERROR_CLASS);
|
||||
|
||||
@NotNull
|
||||
private static SimpleFunctionDescriptor createErrorFunction(@NotNull ErrorScope ownerScope) {
|
||||
|
||||
Reference in New Issue
Block a user