[Linker][IdSignature] Rename classFqn property

classFqn is incorrect since this property represents
FqName of any declaration, including properties, functions and
type aliases.
This commit is contained in:
Sergey Bogolepov
2020-02-21 12:55:43 +07:00
committed by Sergey Bogolepov
parent 221d24c597
commit 71cc288a14
8 changed files with 84 additions and 85 deletions
@@ -364,13 +364,13 @@ class DeclarationStubGenerator(
private fun findDescriptorForAccessorSignature(signature: IdSignature.AccessorSignature): DeclarationDescriptor? {
val propertyDescriptor = findDescriptorBySignature(signature.propertySignature) as? PropertyDescriptor ?: return null
return propertyDescriptor.accessors.singleOrNull {
it.name == signature.accessorSignature.classFqn.shortName()
it.name == signature.accessorSignature.declarationFqn.shortName()
}
}
private fun findDescriptorForPublicSignature(signature: IdSignature.PublicSignature): DeclarationDescriptor? {
val packageDescriptor = moduleDescriptor.getPackage(signature.packageFqName())
val pathSegments = signature.classFqn.pathSegments()
val pathSegments = signature.declarationFqn.pathSegments()
val toplevelDescriptors = packageDescriptor.memberScope.getContributedDescriptors { name -> name == pathSegments.first() }
.filter { it.name == pathSegments.first() }
val candidates = pathSegments.drop(1).fold(toplevelDescriptors) { acc, current ->
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.ir.util
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
import org.jetbrains.kotlin.name.FqName
sealed class IdSignature {
@@ -47,7 +46,7 @@ sealed class IdSignature {
return "${if (isPublic) "public" else "private"} ${render()}"
}
data class PublicSignature(val packageFqn: FqName, val classFqn: FqName, val id: Long?, val mask: Long) : IdSignature() {
data class PublicSignature(val packageFqn: FqName, val declarationFqn: FqName, val id: Long?, val mask: Long) : IdSignature() {
override val isPublic = true
override fun packageFqName() = packageFqn
@@ -60,26 +59,26 @@ sealed class IdSignature {
}
override fun topLevelSignature(): IdSignature {
if (classFqn.isRoot) {
if (declarationFqn.isRoot) {
assert(id == null)
// package signature
return this
}
val pathSegments = classFqn.pathSegments()
val pathSegments = declarationFqn.pathSegments()
if (pathSegments.size == 1) return this
return PublicSignature(packageFqn, FqName(pathSegments.first().asString()), null, adaptMask(mask))
}
override fun isPackageSignature(): Boolean = id == null && classFqn.isRoot
override fun isPackageSignature(): Boolean = id == null && declarationFqn.isRoot
override fun nearestPublicSig(): PublicSignature = this
override fun flags(): Long = mask
override fun render(): String = "${packageFqn.asString()}/${classFqn.asString()}|$id[${mask.toString(2)}]"
override fun render(): String = "${packageFqn.asString()}/${declarationFqn.asString()}|$id[${mask.toString(2)}]"
override fun toString() = super.toString()
@@ -117,7 +116,7 @@ sealed class IdSignature {
override fun topLevelSignature(): IdSignature {
val topLevelContainer = container.topLevelSignature()
if (topLevelContainer === container) {
if (topLevelContainer is PublicSignature && topLevelContainer.classFqn.isRoot) {
if (topLevelContainer is PublicSignature && topLevelContainer.declarationFqn.isRoot) {
// private top level
return this
}
@@ -25,7 +25,7 @@ message IrFile {
message PublicIdSignature {
repeated int32 package_fq_name = 1 [packed=true];
repeated int32 class_fq_name = 2 [packed=true];
repeated int32 declaration_fq_name = 2 [packed = true];
optional int64 member_uniq_id = 3;
optional int64 flags = 4 [default = 0];
}
@@ -201,7 +201,7 @@ abstract class IrFileDeserializer(val logger: LoggingContext, val builtIns: IrBu
private fun deserializePublicIdSignature(proto: ProtoPublicIdSignature): IdSignature.PublicSignature {
val pkg = deserializeFqName(proto.packageFqNameList)
val cls = deserializeFqName(proto.classFqNameList)
val cls = deserializeFqName(proto.declarationFqNameList)
val memberId = if (proto.hasMemberUniqId()) proto.memberUniqId else null
return IdSignature.PublicSignature(pkg, cls, memberId, proto.flags)
@@ -215,7 +215,7 @@ abstract class IrFileDeserializer(val logger: LoggingContext, val builtIns: IrBu
val mask = proto.flags
val accessorSignature = with(propertySignature) {
IdSignature.PublicSignature(packageFqn, classFqn.child(Name.special(name)), hash, mask)
IdSignature.PublicSignature(packageFqn, declarationFqn.child(Name.special(name)), hash, mask)
}
return IdSignature.AccessorSignature(propertySignature, accessorSignature)
@@ -184,7 +184,7 @@ open class IrFileSerializer(
private fun serializePublicSignature(signature: IdSignature.PublicSignature): ProtoPublicIdSignature {
val proto = ProtoPublicIdSignature.newBuilder()
proto.addAllPackageFqName(serializeFqName(signature.packageFqn))
proto.addAllClassFqName(serializeFqName(signature.classFqn))
proto.addAllDeclarationFqName(serializeFqName(signature.declarationFqn))
signature.id?.let { proto.memberUniqId = it }
if (signature.mask != 0L) {
@@ -199,7 +199,7 @@ open class IrFileSerializer(
proto.propertySignature = protoIdSignature(signature.propertySignature)
with(signature.accessorSignature) {
proto.name = serializeString(classFqn.shortName().asString())
proto.name = serializeString(declarationFqn.shortName().asString())
proto.accessorHashId = id ?: error("Expected hash Id")
if (mask != 0L) {
proto.flags = mask
@@ -568,11 +568,11 @@ abstract class KotlinIrLinker(
if (publicSig.packageFqn !in functionalPackages) return false
val classFqn = publicSig.classFqn
val declarationFqn = publicSig.declarationFqn
if (classFqn.isRoot) return false
if (declarationFqn.isRoot) return false
val fqnParts = classFqn.pathSegments()
val fqnParts = declarationFqn.pathSegments()
val className = fqnParts.first()
@@ -583,7 +583,7 @@ abstract class KotlinIrLinker(
if (isSpecialFunctionDescriptor(idSig)) {
val publicSig = idSig.asPublic() ?: error("$idSig has to be public")
val fqnParts = publicSig.classFqn.pathSegments()
val fqnParts = publicSig.declarationFqn.pathSegments()
val className = fqnParts.first()
val classDescriptor = builtIns.builtIns.getBuiltInClassByFqName(publicSig.packageFqn.child(className))
@@ -76,21 +76,21 @@ public final class PublicIdSignature extends
}
case 16: {
if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) {
classFqName_ = new java.util.ArrayList<java.lang.Integer>();
declarationFqName_ = new java.util.ArrayList<java.lang.Integer>();
mutable_bitField0_ |= 0x00000002;
}
classFqName_.add(input.readInt32());
declarationFqName_.add(input.readInt32());
break;
}
case 18: {
int length = input.readRawVarint32();
int limit = input.pushLimit(length);
if (!((mutable_bitField0_ & 0x00000002) == 0x00000002) && input.getBytesUntilLimit() > 0) {
classFqName_ = new java.util.ArrayList<java.lang.Integer>();
declarationFqName_ = new java.util.ArrayList<java.lang.Integer>();
mutable_bitField0_ |= 0x00000002;
}
while (input.getBytesUntilLimit() > 0) {
classFqName_.add(input.readInt32());
declarationFqName_.add(input.readInt32());
}
input.popLimit(limit);
break;
@@ -117,7 +117,7 @@ public final class PublicIdSignature extends
packageFqName_ = java.util.Collections.unmodifiableList(packageFqName_);
}
if (((mutable_bitField0_ & 0x00000002) == 0x00000002)) {
classFqName_ = java.util.Collections.unmodifiableList(classFqName_);
declarationFqName_ = java.util.Collections.unmodifiableList(declarationFqName_);
}
try {
unknownFieldsCodedOutput.flush();
@@ -168,28 +168,28 @@ public final class PublicIdSignature extends
}
private int packageFqNameMemoizedSerializedSize = -1;
public static final int CLASS_FQ_NAME_FIELD_NUMBER = 2;
private java.util.List<java.lang.Integer> classFqName_;
public static final int DECLARATION_FQ_NAME_FIELD_NUMBER = 2;
private java.util.List<java.lang.Integer> declarationFqName_;
/**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code>
* <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/
public java.util.List<java.lang.Integer>
getClassFqNameList() {
return classFqName_;
getDeclarationFqNameList() {
return declarationFqName_;
}
/**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code>
* <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/
public int getClassFqNameCount() {
return classFqName_.size();
public int getDeclarationFqNameCount() {
return declarationFqName_.size();
}
/**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code>
* <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/
public int getClassFqName(int index) {
return classFqName_.get(index);
public int getDeclarationFqName(int index) {
return declarationFqName_.get(index);
}
private int classFqNameMemoizedSerializedSize = -1;
private int declarationFqNameMemoizedSerializedSize = -1;
public static final int MEMBER_UNIQ_ID_FIELD_NUMBER = 3;
private long memberUniqId_;
@@ -223,7 +223,7 @@ public final class PublicIdSignature extends
private void initFields() {
packageFqName_ = java.util.Collections.emptyList();
classFqName_ = java.util.Collections.emptyList();
declarationFqName_ = java.util.Collections.emptyList();
memberUniqId_ = 0L;
flags_ = 0L;
}
@@ -247,12 +247,12 @@ public final class PublicIdSignature extends
for (int i = 0; i < packageFqName_.size(); i++) {
output.writeInt32NoTag(packageFqName_.get(i));
}
if (getClassFqNameList().size() > 0) {
if (getDeclarationFqNameList().size() > 0) {
output.writeRawVarint32(18);
output.writeRawVarint32(classFqNameMemoizedSerializedSize);
output.writeRawVarint32(declarationFqNameMemoizedSerializedSize);
}
for (int i = 0; i < classFqName_.size(); i++) {
output.writeInt32NoTag(classFqName_.get(i));
for (int i = 0; i < declarationFqName_.size(); i++) {
output.writeInt32NoTag(declarationFqName_.get(i));
}
if (((bitField0_ & 0x00000001) == 0x00000001)) {
output.writeInt64(3, memberUniqId_);
@@ -285,17 +285,17 @@ public final class PublicIdSignature extends
}
{
int dataSize = 0;
for (int i = 0; i < classFqName_.size(); i++) {
for (int i = 0; i < declarationFqName_.size(); i++) {
dataSize += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeInt32SizeNoTag(classFqName_.get(i));
.computeInt32SizeNoTag(declarationFqName_.get(i));
}
size += dataSize;
if (!getClassFqNameList().isEmpty()) {
if (!getDeclarationFqNameList().isEmpty()) {
size += 1;
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
.computeInt32SizeNoTag(dataSize);
}
classFqNameMemoizedSerializedSize = dataSize;
declarationFqNameMemoizedSerializedSize = dataSize;
}
if (((bitField0_ & 0x00000001) == 0x00000001)) {
size += org.jetbrains.kotlin.protobuf.CodedOutputStream
@@ -401,7 +401,7 @@ public final class PublicIdSignature extends
super.clear();
packageFqName_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000001);
classFqName_ = java.util.Collections.emptyList();
declarationFqName_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000002);
memberUniqId_ = 0L;
bitField0_ = (bitField0_ & ~0x00000004);
@@ -436,10 +436,10 @@ public final class PublicIdSignature extends
}
result.packageFqName_ = packageFqName_;
if (((bitField0_ & 0x00000002) == 0x00000002)) {
classFqName_ = java.util.Collections.unmodifiableList(classFqName_);
declarationFqName_ = java.util.Collections.unmodifiableList(declarationFqName_);
bitField0_ = (bitField0_ & ~0x00000002);
}
result.classFqName_ = classFqName_;
result.declarationFqName_ = declarationFqName_;
if (((from_bitField0_ & 0x00000004) == 0x00000004)) {
to_bitField0_ |= 0x00000001;
}
@@ -464,13 +464,13 @@ public final class PublicIdSignature extends
}
}
if (!other.classFqName_.isEmpty()) {
if (classFqName_.isEmpty()) {
classFqName_ = other.classFqName_;
if (!other.declarationFqName_.isEmpty()) {
if (declarationFqName_.isEmpty()) {
declarationFqName_ = other.declarationFqName_;
bitField0_ = (bitField0_ & ~0x00000002);
} else {
ensureClassFqNameIsMutable();
classFqName_.addAll(other.classFqName_);
ensureDeclarationFqNameIsMutable();
declarationFqName_.addAll(other.declarationFqName_);
}
}
@@ -574,67 +574,67 @@ public final class PublicIdSignature extends
return this;
}
private java.util.List<java.lang.Integer> classFqName_ = java.util.Collections.emptyList();
private void ensureClassFqNameIsMutable() {
private java.util.List<java.lang.Integer> declarationFqName_ = java.util.Collections.emptyList();
private void ensureDeclarationFqNameIsMutable() {
if (!((bitField0_ & 0x00000002) == 0x00000002)) {
classFqName_ = new java.util.ArrayList<java.lang.Integer>(classFqName_);
declarationFqName_ = new java.util.ArrayList<java.lang.Integer>(declarationFqName_);
bitField0_ |= 0x00000002;
}
}
/**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code>
* <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/
public java.util.List<java.lang.Integer>
getClassFqNameList() {
return java.util.Collections.unmodifiableList(classFqName_);
getDeclarationFqNameList() {
return java.util.Collections.unmodifiableList(declarationFqName_);
}
/**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code>
* <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/
public int getClassFqNameCount() {
return classFqName_.size();
public int getDeclarationFqNameCount() {
return declarationFqName_.size();
}
/**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code>
* <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/
public int getClassFqName(int index) {
return classFqName_.get(index);
public int getDeclarationFqName(int index) {
return declarationFqName_.get(index);
}
/**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code>
* <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/
public Builder setClassFqName(
public Builder setDeclarationFqName(
int index, int value) {
ensureClassFqNameIsMutable();
classFqName_.set(index, value);
ensureDeclarationFqNameIsMutable();
declarationFqName_.set(index, value);
return this;
}
/**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code>
* <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/
public Builder addClassFqName(int value) {
ensureClassFqNameIsMutable();
classFqName_.add(value);
public Builder addDeclarationFqName(int value) {
ensureDeclarationFqNameIsMutable();
declarationFqName_.add(value);
return this;
}
/**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code>
* <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/
public Builder addAllClassFqName(
public Builder addAllDeclarationFqName(
java.lang.Iterable<? extends java.lang.Integer> values) {
ensureClassFqNameIsMutable();
ensureDeclarationFqNameIsMutable();
org.jetbrains.kotlin.protobuf.AbstractMessageLite.Builder.addAll(
values, classFqName_);
values, declarationFqName_);
return this;
}
/**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code>
* <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/
public Builder clearClassFqName() {
classFqName_ = java.util.Collections.emptyList();
public Builder clearDeclarationFqName() {
declarationFqName_ = java.util.Collections.emptyList();
bitField0_ = (bitField0_ & ~0x00000002);
return this;
@@ -21,17 +21,17 @@ public interface PublicIdSignatureOrBuilder extends
int getPackageFqName(int index);
/**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code>
* <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/
java.util.List<java.lang.Integer> getClassFqNameList();
java.util.List<java.lang.Integer> getDeclarationFqNameList();
/**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code>
* <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/
int getClassFqNameCount();
int getDeclarationFqNameCount();
/**
* <code>repeated int32 class_fq_name = 2 [packed = true];</code>
* <code>repeated int32 declaration_fq_name = 2 [packed = true];</code>
*/
int getClassFqName(int index);
int getDeclarationFqName(int index);
/**
* <code>optional int64 member_uniq_id = 3;</code>