Minor, refine parameter type of StringTable#getFqNameIndex
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.serialization;
|
package org.jetbrains.kotlin.serialization;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.descriptors.ClassOrPackageFragmentDescriptor;
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@@ -25,7 +25,7 @@ import java.io.OutputStream;
|
|||||||
public interface StringTable {
|
public interface StringTable {
|
||||||
int getStringIndex(@NotNull String string);
|
int getStringIndex(@NotNull String string);
|
||||||
|
|
||||||
int getFqNameIndex(@NotNull ClassOrPackageFragmentDescriptor descriptor);
|
int getFqNameIndex(@NotNull ClassDescriptor descriptor);
|
||||||
|
|
||||||
int getFqNameIndex(@NotNull FqName fqName);
|
int getFqNameIndex(@NotNull FqName fqName);
|
||||||
|
|
||||||
|
|||||||
+11
-19
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.serialization;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.ClassOrPackageFragmentDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
@@ -78,41 +77,34 @@ public class StringTableImpl implements StringTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getFqNameIndex(@NotNull ClassOrPackageFragmentDescriptor descriptor) {
|
public int getFqNameIndex(@NotNull ClassDescriptor descriptor) {
|
||||||
if (ErrorUtils.isError(descriptor)) {
|
if (ErrorUtils.isError(descriptor)) {
|
||||||
throw new IllegalStateException("Cannot get FQ name of error class: " + descriptor);
|
throw new IllegalStateException("Cannot get FQ name of error class: " + descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
QualifiedName.Builder builder = QualifiedName.newBuilder();
|
QualifiedName.Builder builder = QualifiedName.newBuilder();
|
||||||
if (descriptor instanceof ClassDescriptor) {
|
builder.setKind(QualifiedName.Kind.CLASS);
|
||||||
builder.setKind(QualifiedName.Kind.CLASS);
|
|
||||||
}
|
|
||||||
|
|
||||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||||
int shortName;
|
String shortName;
|
||||||
if (containingDeclaration instanceof PackageFragmentDescriptor) {
|
if (containingDeclaration instanceof PackageFragmentDescriptor) {
|
||||||
shortName = getSimpleNameIndex(descriptor.getName());
|
shortName = descriptor.getName().asString();
|
||||||
PackageFragmentDescriptor fragment = (PackageFragmentDescriptor) containingDeclaration;
|
FqName packageFqName = ((PackageFragmentDescriptor) containingDeclaration).getFqName();
|
||||||
if (!fragment.getFqName().isRoot()) {
|
if (!packageFqName.isRoot()) {
|
||||||
builder.setParentQualifiedName(getFqNameIndex(fragment.getFqName()));
|
builder.setParentQualifiedName(getFqNameIndex(packageFqName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (containingDeclaration instanceof ClassDescriptor) {
|
else if (containingDeclaration instanceof ClassDescriptor) {
|
||||||
shortName = getSimpleNameIndex(descriptor.getName());
|
shortName = descriptor.getName().asString();
|
||||||
ClassDescriptor outerClass = (ClassDescriptor) containingDeclaration;
|
ClassDescriptor outerClass = (ClassDescriptor) containingDeclaration;
|
||||||
builder.setParentQualifiedName(getFqNameIndex(outerClass));
|
builder.setParentQualifiedName(getFqNameIndex(outerClass));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (descriptor instanceof ClassDescriptor) {
|
builder.setKind(QualifiedName.Kind.LOCAL);
|
||||||
builder.setKind(QualifiedName.Kind.LOCAL);
|
shortName = extension.getLocalClassName(descriptor);
|
||||||
shortName = getStringIndex(extension.getLocalClassName((ClassDescriptor) descriptor));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IllegalStateException("Package container should be a package: " + descriptor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.setShortName(shortName);
|
builder.setShortName(getStringIndex(shortName));
|
||||||
|
|
||||||
return qualifiedNames.intern(new FqNameProto(builder));
|
return qualifiedNames.intern(new FqNameProto(builder));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user