DescriptorFinder now can find class names in a package
This helps to get rid of "repeated class_name" field in Package protobuf message. DescriptorFinder in resolve.java uses PSI to find all classes in a package, and the finder for built-ins just reads .kotlin_class_names file
This commit is contained in:
@@ -130,8 +130,6 @@ message Class {
|
||||
|
||||
message Package {
|
||||
repeated Callable member = 1;
|
||||
|
||||
repeated int32 class_name = 2;
|
||||
}
|
||||
|
||||
message Callable {
|
||||
@@ -214,4 +212,4 @@ enum Visibility {
|
||||
PROTECTED = 0x02;
|
||||
PUBLIC = 0x03;
|
||||
EXTRA = 0x04; // there's an extra field for the actual visibility
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -21,6 +21,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public interface DescriptorFinder {
|
||||
DescriptorFinder EMPTY = new DescriptorFinder() {
|
||||
@@ -35,6 +39,12 @@ public interface DescriptorFinder {
|
||||
public NamespaceDescriptor findPackage(@NotNull FqName name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<Name> getClassNames(@NotNull FqName packageName) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
@@ -42,4 +52,7 @@ public interface DescriptorFinder {
|
||||
|
||||
@Nullable
|
||||
NamespaceDescriptor findPackage(@NotNull FqName name);
|
||||
|
||||
@NotNull
|
||||
Collection<Name> getClassNames(@NotNull FqName packageName);
|
||||
}
|
||||
|
||||
-108
@@ -4780,11 +4780,6 @@ public final class ProtoBuf {
|
||||
getMemberList();
|
||||
org.jetbrains.jet.descriptors.serialization.ProtoBuf.Callable getMember(int index);
|
||||
int getMemberCount();
|
||||
|
||||
// repeated int32 class_name = 2;
|
||||
java.util.List<java.lang.Integer> getClassNameList();
|
||||
int getClassNameCount();
|
||||
int getClassName(int index);
|
||||
}
|
||||
public static final class Package extends
|
||||
com.google.protobuf.GeneratedMessageLite
|
||||
@@ -4825,23 +4820,8 @@ public final class ProtoBuf {
|
||||
return member_.get(index);
|
||||
}
|
||||
|
||||
// repeated int32 class_name = 2;
|
||||
public static final int CLASS_NAME_FIELD_NUMBER = 2;
|
||||
private java.util.List<java.lang.Integer> className_;
|
||||
public java.util.List<java.lang.Integer>
|
||||
getClassNameList() {
|
||||
return className_;
|
||||
}
|
||||
public int getClassNameCount() {
|
||||
return className_.size();
|
||||
}
|
||||
public int getClassName(int index) {
|
||||
return className_.get(index);
|
||||
}
|
||||
|
||||
private void initFields() {
|
||||
member_ = java.util.Collections.emptyList();
|
||||
className_ = java.util.Collections.emptyList();;
|
||||
}
|
||||
private byte memoizedIsInitialized = -1;
|
||||
public final boolean isInitialized() {
|
||||
@@ -4864,9 +4844,6 @@ public final class ProtoBuf {
|
||||
for (int i = 0; i < member_.size(); i++) {
|
||||
output.writeMessage(1, member_.get(i));
|
||||
}
|
||||
for (int i = 0; i < className_.size(); i++) {
|
||||
output.writeInt32(2, className_.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
private int memoizedSerializedSize = -1;
|
||||
@@ -4879,15 +4856,6 @@ public final class ProtoBuf {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeMessageSize(1, member_.get(i));
|
||||
}
|
||||
{
|
||||
int dataSize = 0;
|
||||
for (int i = 0; i < className_.size(); i++) {
|
||||
dataSize += com.google.protobuf.CodedOutputStream
|
||||
.computeInt32SizeNoTag(className_.get(i));
|
||||
}
|
||||
size += dataSize;
|
||||
size += 1 * getClassNameList().size();
|
||||
}
|
||||
memoizedSerializedSize = size;
|
||||
return size;
|
||||
}
|
||||
@@ -4992,8 +4960,6 @@ public final class ProtoBuf {
|
||||
super.clear();
|
||||
member_ = java.util.Collections.emptyList();
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
className_ = java.util.Collections.emptyList();;
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -5031,11 +4997,6 @@ public final class ProtoBuf {
|
||||
bitField0_ = (bitField0_ & ~0x00000001);
|
||||
}
|
||||
result.member_ = member_;
|
||||
if (((bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
className_ = java.util.Collections.unmodifiableList(className_);
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
}
|
||||
result.className_ = className_;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -5050,16 +5011,6 @@ public final class ProtoBuf {
|
||||
member_.addAll(other.member_);
|
||||
}
|
||||
|
||||
}
|
||||
if (!other.className_.isEmpty()) {
|
||||
if (className_.isEmpty()) {
|
||||
className_ = other.className_;
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
} else {
|
||||
ensureClassNameIsMutable();
|
||||
className_.addAll(other.className_);
|
||||
}
|
||||
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@@ -5097,20 +5048,6 @@ public final class ProtoBuf {
|
||||
addMember(subBuilder.buildPartial());
|
||||
break;
|
||||
}
|
||||
case 16: {
|
||||
ensureClassNameIsMutable();
|
||||
className_.add(input.readInt32());
|
||||
break;
|
||||
}
|
||||
case 18: {
|
||||
int length = input.readRawVarint32();
|
||||
int limit = input.pushLimit(length);
|
||||
while (input.getBytesUntilLimit() > 0) {
|
||||
addClassName(input.readInt32());
|
||||
}
|
||||
input.popLimit(limit);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5206,51 +5143,6 @@ public final class ProtoBuf {
|
||||
return this;
|
||||
}
|
||||
|
||||
// repeated int32 class_name = 2;
|
||||
private java.util.List<java.lang.Integer> className_ = java.util.Collections.emptyList();;
|
||||
private void ensureClassNameIsMutable() {
|
||||
if (!((bitField0_ & 0x00000002) == 0x00000002)) {
|
||||
className_ = new java.util.ArrayList<java.lang.Integer>(className_);
|
||||
bitField0_ |= 0x00000002;
|
||||
}
|
||||
}
|
||||
public java.util.List<java.lang.Integer>
|
||||
getClassNameList() {
|
||||
return java.util.Collections.unmodifiableList(className_);
|
||||
}
|
||||
public int getClassNameCount() {
|
||||
return className_.size();
|
||||
}
|
||||
public int getClassName(int index) {
|
||||
return className_.get(index);
|
||||
}
|
||||
public Builder setClassName(
|
||||
int index, int value) {
|
||||
ensureClassNameIsMutable();
|
||||
className_.set(index, value);
|
||||
|
||||
return this;
|
||||
}
|
||||
public Builder addClassName(int value) {
|
||||
ensureClassNameIsMutable();
|
||||
className_.add(value);
|
||||
|
||||
return this;
|
||||
}
|
||||
public Builder addAllClassName(
|
||||
java.lang.Iterable<? extends java.lang.Integer> values) {
|
||||
ensureClassNameIsMutable();
|
||||
super.addAll(values, className_);
|
||||
|
||||
return this;
|
||||
}
|
||||
public Builder clearClassName() {
|
||||
className_ = java.util.Collections.emptyList();;
|
||||
bitField0_ = (bitField0_ & ~0x00000002);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(builder_scope:org.jetbrains.jet.descriptors.serialization.Package)
|
||||
}
|
||||
|
||||
|
||||
+3
-18
@@ -20,14 +20,13 @@ public abstract class DeserializedPackageMemberScope extends DeserializedMemberS
|
||||
@NotNull
|
||||
public static DeserializedPackageMemberScope createScopeFromPackageData(
|
||||
@NotNull NamespaceDescriptor packageDescriptor,
|
||||
@NotNull final PackageData packageData,
|
||||
@NotNull PackageData packageData,
|
||||
@NotNull DescriptorFinder descriptorFinder,
|
||||
@NotNull AnnotationDeserializer deserializer,
|
||||
@NotNull LockBasedStorageManager storageManager
|
||||
) {
|
||||
final NameResolver nameResolver = packageData.getNameResolver();
|
||||
DescriptorDeserializer descriptorDeserializer = DescriptorDeserializer
|
||||
.create(storageManager, packageDescriptor, nameResolver, descriptorFinder, deserializer);
|
||||
.create(storageManager, packageDescriptor, packageData.getNameResolver(), descriptorFinder, deserializer);
|
||||
List<ProtoBuf.Callable> memberList = packageData.getPackageProto().getMemberList();
|
||||
return new DeserializedPackageMemberScope(storageManager, packageDescriptor, descriptorDeserializer, memberList, descriptorFinder) {
|
||||
@Nullable
|
||||
@@ -35,17 +34,6 @@ public abstract class DeserializedPackageMemberScope extends DeserializedMemberS
|
||||
protected ReceiverParameterDescriptor getImplicitReceiver() {
|
||||
return ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Collection<Name> getClassNames() {
|
||||
Collection<Integer> nameIds = packageData.getPackageProto().getClassNameList();
|
||||
List<Name> result = new ArrayList<Name>(nameIds.size());
|
||||
for (Integer nameId : nameIds) {
|
||||
result.add(nameResolver.getName(nameId));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -98,7 +86,7 @@ public abstract class DeserializedPackageMemberScope extends DeserializedMemberS
|
||||
}
|
||||
|
||||
private <T extends Collection<? super ClassDescriptor>> T findClassifiers(T result, boolean object) {
|
||||
for (Name className : getClassNames()) {
|
||||
for (Name className : descriptorFinder.getClassNames(packageFqName)) {
|
||||
ClassDescriptor classDescriptor = findClassDescriptor(className, object);
|
||||
|
||||
if (classDescriptor != null) {
|
||||
@@ -109,9 +97,6 @@ public abstract class DeserializedPackageMemberScope extends DeserializedMemberS
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract Collection<Name> getClassNames();
|
||||
|
||||
@Override
|
||||
protected void addNonDeclaredDescriptors(@NotNull Collection<DeclarationDescriptor> result) {
|
||||
// Do nothing
|
||||
|
||||
Reference in New Issue
Block a user