Delete JetScope.getObjectDescriptors()

This commit is contained in:
Alexander Udalov
2013-11-15 20:51:43 +04:00
parent 31c84951dc
commit 550df37056
20 changed files with 30 additions and 145 deletions
@@ -126,11 +126,6 @@ public class DescriptorSerializer {
}
}
for (ClassDescriptor descriptor : sort(classDescriptor.getUnsubstitutedInnerClassesScope().getObjectDescriptors())) {
int nameIndex = nameTable.getSimpleNameIndex(descriptor.getName());
builder.addNestedObjectName(nameIndex);
}
ClassDescriptor classObject = classDescriptor.getClassObjectDescriptor();
if (classObject != null) {
builder.setClassObject(classObjectProto(classObject));
@@ -179,12 +179,6 @@ public abstract class DeserializedMemberScope implements JetScope {
@NotNull
protected abstract Collection<ClassDescriptor> computeAllObjectDescriptors();
@NotNull
@Override
public Collection<ClassDescriptor> getObjectDescriptors() {
return objectDescriptors.invoke();
}
@Nullable
@Override
public NamespaceDescriptor getNamespace(@NotNull Name name) {
@@ -1,3 +1,19 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.descriptors.serialization.descriptors;
import org.jetbrains.annotations.NotNull;
@@ -10,8 +26,8 @@ import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.storage.StorageManager;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
public class DeserializedPackageMemberScope extends DeserializedMemberScope {
private final DescriptorFinder descriptorFinder;
@@ -47,45 +63,35 @@ public class DeserializedPackageMemberScope extends DeserializedMemberScope {
@Nullable
@Override
protected ClassifierDescriptor getClassDescriptor(@NotNull Name name) {
return findClassDescriptor(name, false);
return findClassDescriptor(name);
}
@Nullable
@Override
public ClassDescriptor getObjectDescriptor(@NotNull Name name) {
return findClassDescriptor(name, true);
return null;
}
@Nullable
private ClassDescriptor findClassDescriptor(Name name, boolean object) {
ClassDescriptor classDescriptor = descriptorFinder.findClass(new ClassId(packageFqName, FqNameUnsafe.topLevel(name)));
if (classDescriptor == null) {
return null;
}
return classDescriptor.getKind().isSingleton() == object ? classDescriptor : null;
private ClassDescriptor findClassDescriptor(Name name) {
return descriptorFinder.findClass(new ClassId(packageFqName, FqNameUnsafe.topLevel(name)));
}
@Override
protected void addAllClassDescriptors(@NotNull Collection<DeclarationDescriptor> result) {
findClassifiers(result, false);
for (Name className : descriptorFinder.getClassNames(packageFqName)) {
ClassDescriptor classDescriptor = findClassDescriptor(className);
if (classDescriptor != null) {
result.add(classDescriptor);
}
}
}
@NotNull
@Override
protected Collection<ClassDescriptor> computeAllObjectDescriptors() {
return findClassifiers(new ArrayList<ClassDescriptor>(), true);
}
private <T extends Collection<? super ClassDescriptor>> T findClassifiers(T result, boolean object) {
for (Name className : descriptorFinder.getClassNames(packageFqName)) {
ClassDescriptor classDescriptor = findClassDescriptor(className, object);
if (classDescriptor != null) {
assert classDescriptor.getKind().isSingleton() == object;
result.add(classDescriptor);
}
}
return result;
return Collections.emptySet();
}
@Override
@@ -250,12 +250,6 @@ public class LazyImportScope implements JetScope {
return selectFirstFromImports(name, LookupMode.ONLY_CLASSES, JetScopeSelectorUtil.NAMED_OBJECT_SCOPE_SELECTOR);
}
@NotNull
@Override
public Collection<ClassDescriptor> getObjectDescriptors() {
return collectFromImports(LookupMode.ONLY_CLASSES, JetScopeSelectorUtil.OBJECTS_SCOPE_SELECTOR);
}
@Nullable
@Override
public NamespaceDescriptor getNamespace(@NotNull Name name) {
@@ -183,12 +183,6 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
protected abstract void getNonDeclaredProperties(@NotNull Name name, @NotNull Set<VariableDescriptor> result);
@NotNull
@Override
public Collection<ClassDescriptor> getObjectDescriptors() {
return Collections.emptySet();
}
@Override
public VariableDescriptor getLocalVariable(@NotNull Name name) {
return null;
@@ -111,15 +111,6 @@ public class JetScopeSelectorUtil {
}
};
public static final ScopeDescriptorSelector<ClassDescriptor> OBJECTS_SCOPE_SELECTOR =
new ScopeDescriptorSelector<ClassDescriptor>() {
@NotNull
@Override
public Collection<ClassDescriptor> get(@NotNull JetScope scope) {
return scope.getObjectDescriptors();
}
};
public static final ScopeDescriptorSelector<DeclarationDescriptor> ALL_DESCRIPTORS_SCOPE_SELECTOR =
new ScopeDescriptorSelector<DeclarationDescriptor>() {
@NotNull
@@ -139,18 +139,6 @@ public class WriteThroughScope extends WritableScopeWithImports {
return super.getObjectDescriptor(name); // Imports
}
@NotNull
@Override
public Set<ClassDescriptor> getObjectDescriptors() {
checkMayRead();
Set<ClassDescriptor> objectDescriptors = Sets.newHashSet();
objectDescriptors.addAll(super.getObjectDescriptors());
objectDescriptors.addAll(getWorkerScope().getObjectDescriptors());
objectDescriptors.addAll(writableWorker.getObjectDescriptors());
return objectDescriptors;
}
@Override
public void addLabeledDeclaration(@NotNull DeclarationDescriptor descriptor) {
checkMayWrite();
@@ -130,9 +130,6 @@ public abstract class AbstractDescriptorSerializationTest extends KotlinTestWith
classes.add((ClassDescriptor) descriptor);
}
}
for (ClassDescriptor descriptor : scope.getObjectDescriptors()) {
classes.add(descriptor);
}
return classes;
}
@@ -42,8 +42,6 @@ public class ClassSerializationUtil {
serializeClasses(classDescriptor.getUnsubstitutedInnerClassesScope().getAllDescriptors(), serializer, sink);
serializeClasses(classDescriptor.getUnsubstitutedInnerClassesScope().getObjectDescriptors(), serializer, sink);
ClassDescriptor classObjectDescriptor = classDescriptor.getClassObjectDescriptor();
if (classObjectDescriptor != null) {
serializeClass(classObjectDescriptor, serializer, sink);
@@ -153,7 +153,6 @@ public class NamespaceComparator {
List<DeclarationDescriptor> subDescriptors = Lists.newArrayList();
subDescriptors.addAll(memberScope.getAllDescriptors());
subDescriptors.addAll(memberScope.getObjectDescriptors());
subDescriptors.addAll(extraSubDescriptors);
Collections.sort(subDescriptors, MemberComparator.INSTANCE);
@@ -100,7 +100,6 @@ public class RecursiveDescriptorProcessor {
&& visitChildren(descriptor.getConstructors(), data)
&& visitChildren(descriptor.getTypeConstructor().getParameters(), data)
&& visitChildren(descriptor.getClassObjectDescriptor(), data)
&& visitChildren(descriptor.getDefaultType().getMemberScope().getObjectDescriptors(), data)
&& visitChildren(descriptor.getDefaultType().getMemberScope().getAllDescriptors(), data);
}
@@ -127,12 +127,6 @@ public abstract class JavaBaseScope extends JetScopeImpl {
return result;
}
@NotNull
@Override
public Set<ClassDescriptor> getObjectDescriptors() {
return Collections.emptySet();
}
@NotNull
protected abstract Collection<ClassDescriptor> computeInnerClasses();
@@ -60,12 +60,6 @@ public abstract class AbstractScopeAdapter implements JetScope {
return getWorkerScope().getObjectDescriptor(name);
}
@NotNull
@Override
public Collection<ClassDescriptor> getObjectDescriptors() {
return getWorkerScope().getObjectDescriptors();
}
@NotNull
@Override
public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
@@ -66,16 +66,6 @@ public class ChainedScope implements JetScope {
return null;
}
@NotNull
@Override
public Set<ClassDescriptor> getObjectDescriptors() {
Set<ClassDescriptor> objectDescriptors = Sets.newHashSet();
for (JetScope scope : scopeChain) {
objectDescriptors.addAll(scope.getObjectDescriptors());
}
return objectDescriptors;
}
@Override
public NamespaceDescriptor getNamespace(@NotNull Name name) {
for (JetScope jetScope : scopeChain) {
@@ -70,12 +70,6 @@ public class FilteringScope implements JetScope {
return filterDescriptor(workerScope.getObjectDescriptor(name));
}
@NotNull
@Override
public Collection<ClassDescriptor> getObjectDescriptors() {
return Collections2.filter(workerScope.getObjectDescriptors(), predicate);
}
@NotNull
@Override
public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
@@ -56,10 +56,6 @@ public interface JetScope {
@Nullable
ClassDescriptor getObjectDescriptor(@NotNull Name name);
@NotNull
@ReadOnly
Collection<ClassDescriptor> getObjectDescriptors();
@Nullable
NamespaceDescriptor getNamespace(@NotNull Name name);
@@ -26,7 +26,6 @@ import org.jetbrains.jet.utils.Printer;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
public abstract class JetScopeImpl implements JetScope {
@Override
@@ -39,12 +38,6 @@ public abstract class JetScopeImpl implements JetScope {
return null;
}
@NotNull
@Override
public Set<ClassDescriptor> getObjectDescriptors() {
return Collections.emptySet();
}
@NotNull
@Override
public Collection<VariableDescriptor> getProperties(@NotNull Name name) {
@@ -95,4 +88,4 @@ public abstract class JetScopeImpl implements JetScope {
@TestOnly
@Override
public abstract void printScopeStructure(@NotNull Printer p);
}
}
@@ -103,12 +103,6 @@ public class SubstitutingScope implements JetScope {
return substitute(workerScope.getObjectDescriptor(name));
}
@NotNull
@Override
public Collection<ClassDescriptor> getObjectDescriptors() {
return substitute(workerScope.getObjectDescriptors());
}
@NotNull
@Override
public Collection<FunctionDescriptor> getFunctions(@NotNull Name name) {
@@ -395,19 +395,6 @@ public class WritableScopeImpl extends WritableScopeWithImports {
return super.getObjectDescriptor(name);
}
@NotNull
@Override
public Set<ClassDescriptor> getObjectDescriptors() {
if (allObjectDescriptors == null) {
allObjectDescriptors = Sets.newHashSet(getObjectDescriptorsMap().values());
allObjectDescriptors.addAll(getWorkerScope().getObjectDescriptors());
for (JetScope imported : getImports()) {
allObjectDescriptors.addAll(imported.getObjectDescriptors());
}
}
return allObjectDescriptors;
}
@Override
public void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
checkMayWrite();
@@ -93,12 +93,6 @@ public class ErrorUtils {
return ERROR_CLASS;
}
@NotNull
@Override
public Set<ClassDescriptor> getObjectDescriptors() {
return Collections.emptySet();
}
@NotNull
@Override
public Set<VariableDescriptor> getProperties(@NotNull Name name) {
@@ -181,12 +175,6 @@ public class ErrorUtils {
throw new IllegalStateException();
}
@NotNull
@Override
public Collection<ClassDescriptor> getObjectDescriptors() {
throw new IllegalStateException();
}
@Nullable
@Override
public NamespaceDescriptor getNamespace(@NotNull Name name) {