Minor, refine parameter type of StringTable#getFqNameIndex

This commit is contained in:
Alexander Udalov
2015-09-18 02:53:22 +03:00
parent 5477570066
commit 68051fa3bb
2 changed files with 13 additions and 21 deletions
@@ -17,7 +17,7 @@
package org.jetbrains.kotlin.serialization;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.descriptors.ClassOrPackageFragmentDescriptor;
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
import org.jetbrains.kotlin.name.FqName;
import java.io.OutputStream;
@@ -25,7 +25,7 @@ import java.io.OutputStream;
public interface StringTable {
int getStringIndex(@NotNull String string);
int getFqNameIndex(@NotNull ClassOrPackageFragmentDescriptor descriptor);
int getFqNameIndex(@NotNull ClassDescriptor descriptor);
int getFqNameIndex(@NotNull FqName fqName);
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.serialization;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
import org.jetbrains.kotlin.descriptors.ClassOrPackageFragmentDescriptor;
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
import org.jetbrains.kotlin.name.FqName;
@@ -78,41 +77,34 @@ public class StringTableImpl implements StringTable {
}
@Override
public int getFqNameIndex(@NotNull ClassOrPackageFragmentDescriptor descriptor) {
public int getFqNameIndex(@NotNull ClassDescriptor descriptor) {
if (ErrorUtils.isError(descriptor)) {
throw new IllegalStateException("Cannot get FQ name of error class: " + descriptor);
}
QualifiedName.Builder builder = QualifiedName.newBuilder();
if (descriptor instanceof ClassDescriptor) {
builder.setKind(QualifiedName.Kind.CLASS);
}
builder.setKind(QualifiedName.Kind.CLASS);
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
int shortName;
String shortName;
if (containingDeclaration instanceof PackageFragmentDescriptor) {
shortName = getSimpleNameIndex(descriptor.getName());
PackageFragmentDescriptor fragment = (PackageFragmentDescriptor) containingDeclaration;
if (!fragment.getFqName().isRoot()) {
builder.setParentQualifiedName(getFqNameIndex(fragment.getFqName()));
shortName = descriptor.getName().asString();
FqName packageFqName = ((PackageFragmentDescriptor) containingDeclaration).getFqName();
if (!packageFqName.isRoot()) {
builder.setParentQualifiedName(getFqNameIndex(packageFqName));
}
}
else if (containingDeclaration instanceof ClassDescriptor) {
shortName = getSimpleNameIndex(descriptor.getName());
shortName = descriptor.getName().asString();
ClassDescriptor outerClass = (ClassDescriptor) containingDeclaration;
builder.setParentQualifiedName(getFqNameIndex(outerClass));
}
else {
if (descriptor instanceof ClassDescriptor) {
builder.setKind(QualifiedName.Kind.LOCAL);
shortName = getStringIndex(extension.getLocalClassName((ClassDescriptor) descriptor));
}
else {
throw new IllegalStateException("Package container should be a package: " + descriptor);
}
builder.setKind(QualifiedName.Kind.LOCAL);
shortName = extension.getLocalClassName(descriptor);
}
builder.setShortName(shortName);
builder.setShortName(getStringIndex(shortName));
return qualifiedNames.intern(new FqNameProto(builder));
}