Namer added to abstract over naming conventions on different platforms
This commit is contained in:
committed by
Alexander Udalov
parent
347e2c27aa
commit
b90522b223
+2
-4
@@ -27,13 +27,11 @@ import java.util.Collection;
|
||||
|
||||
public class DescriptorSerializer {
|
||||
|
||||
// TODO: flags
|
||||
|
||||
private final NameTable nameTable;
|
||||
private final Interner<TypeParameterDescriptor> typeParameters;
|
||||
|
||||
public DescriptorSerializer() {
|
||||
this(new NameTable(), new Interner<TypeParameterDescriptor>());
|
||||
public DescriptorSerializer(@NotNull NameTable.Namer namer) {
|
||||
this(new NameTable(namer), new Interner<TypeParameterDescriptor>());
|
||||
}
|
||||
|
||||
private DescriptorSerializer(NameTable nameTable, Interner<TypeParameterDescriptor> typeParameters) {
|
||||
|
||||
+16
-4
@@ -51,9 +51,23 @@ public class NameTable {
|
||||
}
|
||||
};
|
||||
|
||||
public interface Namer {
|
||||
@NotNull
|
||||
Name getClassName(@NotNull ClassDescriptor classDescriptor);
|
||||
|
||||
@NotNull
|
||||
Name getPackageName(@NotNull NamespaceDescriptor namespaceDescriptor);
|
||||
}
|
||||
|
||||
private final Namer 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 Namer namer) {
|
||||
this.namer = namer;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> getSimpleNames() {
|
||||
return simpleNames.getAllInternedObjects();
|
||||
@@ -71,7 +85,7 @@ public class NameTable {
|
||||
public int getFqNameIndex(@NotNull ClassDescriptor classDescriptor) {
|
||||
QualifiedName.Builder builder = QualifiedName.newBuilder();
|
||||
builder.setKind(QualifiedName.Kind.CLASS);
|
||||
builder.setShortName(getSimpleNameIndex(classDescriptor.getName()));
|
||||
builder.setShortName(getSimpleNameIndex(namer.getClassName(classDescriptor)));
|
||||
|
||||
DeclarationDescriptor containingDeclaration = classDescriptor.getContainingDeclaration();
|
||||
if (containingDeclaration instanceof NamespaceDescriptor) {
|
||||
@@ -89,7 +103,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(namespaceDescriptor.getName()));
|
||||
builder.setShortName(getSimpleNameIndex(namer.getPackageName(namespaceDescriptor)));
|
||||
|
||||
NamespaceDescriptorParent containingDeclaration = namespaceDescriptor.getContainingDeclaration();
|
||||
if (containingDeclaration instanceof NamespaceDescriptor) {
|
||||
@@ -105,6 +119,4 @@ public class NameTable {
|
||||
return qualifiedNames.intern(builder);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user