Simplify class object naming madness

- get rid of DescriptorNamer, always use descriptor.getName() instead
- delete AbstractClassResolver.getClassObjectName(), always use
  "<class-object-for-...>", except for the case of built-ins serialization
  (class object names should be replaced by "object" when writing files with
  serialized data for built-ins)
- delete NestedClassResolver.resolveClassObject(), always use the other method
  of this class instead
This commit is contained in:
Alexander Udalov
2013-07-01 19:26:38 +04:00
parent 5db2ecd1fc
commit f9ad6827d4
190 changed files with 103 additions and 215 deletions
@@ -45,12 +45,6 @@ public abstract class AbstractClassResolver implements ClassResolver {
public ClassDescriptor resolveNestedClass(@NotNull ClassDescriptor outerClass, @NotNull Name name) {
return findClass(getClassId(outerClass).createNestedClassId(name));
}
@Nullable
@Override
public ClassDescriptor resolveClassObject(@NotNull ClassDescriptor outerClass) {
return findClass(getClassId(outerClass).createNestedClassId(getClassObjectName(outerClass)));
}
};
this.findClass = storageManager.createMemoizedFunctionWithNullableValues(new Function<ClassId, ClassDescriptor>() {
@@ -109,8 +103,5 @@ public abstract class AbstractClassResolver implements ClassResolver {
return null;
}
@NotNull
protected abstract Name getClassObjectName(@NotNull ClassDescriptor outerClass);
protected abstract void classDescriptorCreated(@NotNull ClassDescriptor classDescriptor);
}
@@ -43,7 +43,7 @@ public class ClassSerializationUtil {
@NotNull
@Override
public DescriptorSerializer getSerializerFor(@NotNull ClassDescriptor classDescriptor) {
return new DescriptorSerializer(DescriptorNamer.DEFAULT);
return new DescriptorSerializer();
}
};
@@ -100,24 +100,23 @@ public class ClassSerializationUtil {
}
@NotNull
public static ClassId getClassId(@NotNull ClassDescriptor classDescriptor, @NotNull DescriptorNamer namer) {
public static ClassId getClassId(@NotNull ClassDescriptor classDescriptor) {
DeclarationDescriptor containingDeclaration = classDescriptor.getContainingDeclaration();
if (containingDeclaration instanceof NamespaceDescriptor) {
NamespaceDescriptor namespaceDescriptor = (NamespaceDescriptor) containingDeclaration;
return new ClassId(getPackageFqName(namespaceDescriptor, namer), FqNameUnsafe.topLevel(namer.getClassName(classDescriptor)));
return new ClassId(getPackageFqName(namespaceDescriptor), FqNameUnsafe.topLevel(classDescriptor.getName()));
}
// it must be a nested class
ClassDescriptor outer = (ClassDescriptor) containingDeclaration;
ClassId outerId = getClassId(outer, namer);
return outerId.createNestedClassId(namer.getClassName(classDescriptor));
ClassId outerId = getClassId(outer);
return outerId.createNestedClassId(classDescriptor.getName());
}
@NotNull
public static FqName getPackageFqName(@NotNull NamespaceDescriptor namespaceDescriptor, @NotNull DescriptorNamer namer) {
public static FqName getPackageFqName(@NotNull NamespaceDescriptor namespaceDescriptor) {
if (DescriptorUtils.isRootNamespace(namespaceDescriptor)) return FqName.ROOT;
NamespaceDescriptor parent = (NamespaceDescriptor) namespaceDescriptor.getContainingDeclaration();
return getPackageFqName(parent, namer)
.child(namer.getPackageName(namespaceDescriptor));
return getPackageFqName(parent).child(namespaceDescriptor.getName());
}
}
@@ -1,44 +0,0 @@
/*
* 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;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
import org.jetbrains.jet.lang.resolve.name.Name;
public interface DescriptorNamer {
DescriptorNamer DEFAULT = new DescriptorNamer() {
@NotNull
@Override
public Name getClassName(@NotNull ClassDescriptor classDescriptor) {
return classDescriptor.getName();
}
@NotNull
@Override
public Name getPackageName(@NotNull NamespaceDescriptor namespaceDescriptor) {
return namespaceDescriptor.getName();
}
};
@NotNull
Name getClassName(@NotNull ClassDescriptor classDescriptor);
@NotNull
Name getPackageName(@NotNull NamespaceDescriptor namespaceDescriptor);
}
@@ -49,12 +49,12 @@ public class DescriptorSerializer {
private final Interner<TypeParameterDescriptor> typeParameters;
private final Predicate<ClassDescriptor> isSpecial;
public DescriptorSerializer(@NotNull DescriptorNamer namer) {
this(namer, Predicates.<ClassDescriptor>alwaysFalse());
public DescriptorSerializer() {
this(Predicates.<ClassDescriptor>alwaysFalse());
}
public DescriptorSerializer(@NotNull DescriptorNamer namer, @NotNull Predicate<ClassDescriptor> isSpecial) {
this(new NameTable(namer), new Interner<TypeParameterDescriptor>(), isSpecial);
public DescriptorSerializer(@NotNull Predicate<ClassDescriptor> isSpecial) {
this(new NameTable(), new Interner<TypeParameterDescriptor>(), isSpecial);
}
private DescriptorSerializer(NameTable nameTable, Interner<TypeParameterDescriptor> typeParameters, Predicate<ClassDescriptor> isSpecial) {
@@ -51,13 +51,10 @@ public class NameTable {
}
};
private final DescriptorNamer namer;
private final Interner<String> simpleNames = new Interner<String>();
private final Interner<QualifiedName.Builder> qualifiedNames = new Interner<QualifiedName.Builder>(QUALIFIED_NAME_BUILDER_HASHING);
public NameTable(@NotNull DescriptorNamer namer) {
this.namer = namer;
public NameTable() {
}
@NotNull
@@ -77,7 +74,7 @@ public class NameTable {
public int getFqNameIndex(@NotNull ClassDescriptor classDescriptor) {
QualifiedName.Builder builder = QualifiedName.newBuilder();
builder.setKind(QualifiedName.Kind.CLASS);
builder.setShortName(getSimpleNameIndex(namer.getClassName(classDescriptor)));
builder.setShortName(getSimpleNameIndex(classDescriptor.getName()));
DeclarationDescriptor containingDeclaration = classDescriptor.getContainingDeclaration();
if (containingDeclaration instanceof NamespaceDescriptor) {
@@ -103,7 +100,7 @@ public class NameTable {
public int getFqNameIndex(@NotNull NamespaceDescriptor namespaceDescriptor) {
QualifiedName.Builder builder = QualifiedName.newBuilder();
//default: builder.setKind(QualifiedNameTable.QualifiedName.Kind.PACKAGE);
builder.setShortName(getSimpleNameIndex(namer.getPackageName(namespaceDescriptor)));
builder.setShortName(getSimpleNameIndex(namespaceDescriptor.getName()));
NamespaceDescriptorParent containingDeclaration = namespaceDescriptor.getContainingDeclaration();
if (containingDeclaration instanceof NamespaceDescriptor) {
@@ -8,7 +8,4 @@ import org.jetbrains.jet.lang.resolve.name.Name;
public interface NestedClassResolver {
@Nullable
ClassDescriptor resolveNestedClass(@NotNull ClassDescriptor outerClass, @NotNull Name name);
@Nullable
ClassDescriptor resolveClassObject(@NotNull ClassDescriptor outerClass);
}
@@ -268,7 +268,7 @@ public class DeserializedClassDescriptor extends ClassDescriptorBase implements
return classObject;
}
return nestedClassResolver.resolveClassObject(this);
return nestedClassResolver.resolveNestedClass(this, getClassObjectName(getName()));
}
@NotNull