Drop Callable and primary/secondary constructor proto messages
This commit is contained in:
-141
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotated;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorFactory;
|
||||
import org.jetbrains.kotlin.resolve.MemberComparator;
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
||||
import org.jetbrains.kotlin.resolve.constants.NullValue;
|
||||
@@ -38,7 +37,6 @@ import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry;
|
||||
import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getSecondaryConstructors;
|
||||
|
||||
public class DescriptorSerializer {
|
||||
|
||||
@@ -117,31 +115,14 @@ public class DescriptorSerializer {
|
||||
}
|
||||
}
|
||||
|
||||
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
||||
if (primaryConstructor != null) {
|
||||
if (DescriptorFactory.isDefaultPrimaryConstructor(primaryConstructor)) {
|
||||
builder.setPrimaryConstructor(ProtoBuf.Class.PrimaryConstructor.getDefaultInstance());
|
||||
}
|
||||
else {
|
||||
ProtoBuf.Class.PrimaryConstructor.Builder constructorBuilder = ProtoBuf.Class.PrimaryConstructor.newBuilder();
|
||||
constructorBuilder.setData(callableProto(primaryConstructor));
|
||||
builder.setPrimaryConstructor(constructorBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
for (ConstructorDescriptor descriptor : classDescriptor.getConstructors()) {
|
||||
builder.addConstructor(constructorProto(descriptor));
|
||||
}
|
||||
|
||||
for (ConstructorDescriptor constructorDescriptor : getSecondaryConstructors(classDescriptor)) {
|
||||
builder.addSecondaryConstructor(callableProto(constructorDescriptor));
|
||||
}
|
||||
|
||||
for (DeclarationDescriptor descriptor : sort(classDescriptor.getDefaultType().getMemberScope().getAllDescriptors())) {
|
||||
if (descriptor instanceof CallableMemberDescriptor) {
|
||||
CallableMemberDescriptor member = (CallableMemberDescriptor) descriptor;
|
||||
if (member.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) continue;
|
||||
builder.addMember(callableProto(member));
|
||||
|
||||
if (descriptor instanceof PropertyDescriptor) {
|
||||
builder.addProperty(propertyProto((PropertyDescriptor) descriptor));
|
||||
@@ -309,108 +290,6 @@ public class DescriptorSerializer {
|
||||
return builder;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ProtoBuf.Callable.Builder callableProto(@NotNull CallableMemberDescriptor descriptor) {
|
||||
ProtoBuf.Callable.Builder builder = ProtoBuf.Callable.newBuilder();
|
||||
|
||||
DescriptorSerializer local = createChildSerializer();
|
||||
|
||||
boolean hasGetter = false;
|
||||
boolean hasSetter = false;
|
||||
boolean hasConstant = false;
|
||||
boolean lateInit = false;
|
||||
boolean isConst = false;
|
||||
boolean isOperator = false;
|
||||
boolean isInfix = false;
|
||||
|
||||
if (descriptor instanceof FunctionDescriptor) {
|
||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
|
||||
isOperator = functionDescriptor.isOperator();
|
||||
isInfix = functionDescriptor.isInfix();
|
||||
}
|
||||
|
||||
if (descriptor instanceof PropertyDescriptor) {
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
|
||||
lateInit = propertyDescriptor.isLateInit();
|
||||
isConst = propertyDescriptor.isConst();
|
||||
|
||||
int propertyFlags = Flags.getAccessorFlags(
|
||||
hasAnnotations(propertyDescriptor),
|
||||
propertyDescriptor.getVisibility(),
|
||||
propertyDescriptor.getModality(),
|
||||
false
|
||||
);
|
||||
|
||||
PropertyGetterDescriptor getter = propertyDescriptor.getGetter();
|
||||
if (getter != null) {
|
||||
hasGetter = true;
|
||||
int accessorFlags = getAccessorFlags(getter);
|
||||
if (accessorFlags != propertyFlags) {
|
||||
builder.setGetterFlags(accessorFlags);
|
||||
}
|
||||
}
|
||||
|
||||
PropertySetterDescriptor setter = propertyDescriptor.getSetter();
|
||||
if (setter != null) {
|
||||
hasSetter = true;
|
||||
int accessorFlags = getAccessorFlags(setter);
|
||||
if (accessorFlags != propertyFlags) {
|
||||
builder.setSetterFlags(accessorFlags);
|
||||
}
|
||||
|
||||
if (!setter.isDefault()) {
|
||||
for (ValueParameterDescriptor valueParameterDescriptor : setter.getValueParameters()) {
|
||||
builder.addValueParameter(local.valueParameter(valueParameterDescriptor));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConstantValue<?> compileTimeConstant = propertyDescriptor.getCompileTimeInitializer();
|
||||
hasConstant = !(compileTimeConstant == null || compileTimeConstant instanceof NullValue);
|
||||
}
|
||||
|
||||
boolean hasAnnotations = (descriptor instanceof PropertyDescriptor)
|
||||
? !descriptor.getAnnotations().getAllAnnotations().isEmpty()
|
||||
: hasAnnotations(descriptor);
|
||||
|
||||
builder.setFlags(Flags.getCallableFlags(
|
||||
hasAnnotations,
|
||||
descriptor.getVisibility(),
|
||||
descriptor.getModality(),
|
||||
descriptor.getKind(),
|
||||
callableKind(descriptor),
|
||||
hasGetter,
|
||||
hasSetter,
|
||||
hasConstant,
|
||||
lateInit,
|
||||
isConst,
|
||||
isOperator,
|
||||
isInfix
|
||||
));
|
||||
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : descriptor.getTypeParameters()) {
|
||||
builder.addTypeParameter(local.typeParameter(typeParameterDescriptor));
|
||||
}
|
||||
|
||||
ReceiverParameterDescriptor receiverParameter = descriptor.getExtensionReceiverParameter();
|
||||
if (receiverParameter != null) {
|
||||
builder.setReceiverType(local.type(receiverParameter.getType()));
|
||||
}
|
||||
|
||||
builder.setName(getSimpleNameIndex(descriptor.getName()));
|
||||
|
||||
for (ValueParameterDescriptor valueParameterDescriptor : descriptor.getValueParameters()) {
|
||||
builder.addValueParameter(local.valueParameter(valueParameterDescriptor));
|
||||
}
|
||||
|
||||
//noinspection ConstantConditions
|
||||
builder.setReturnType(local.type(descriptor.getReturnType()));
|
||||
|
||||
extension.serializeCallable(descriptor, builder);
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
private static int getAccessorFlags(@NotNull PropertyAccessorDescriptor accessor) {
|
||||
return Flags.getAccessorFlags(
|
||||
hasAnnotations(accessor),
|
||||
@@ -420,18 +299,6 @@ public class DescriptorSerializer {
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ProtoBuf.CallableKind callableKind(@NotNull CallableMemberDescriptor descriptor) {
|
||||
if (descriptor instanceof PropertyDescriptor) {
|
||||
return ((PropertyDescriptor) descriptor).isVar() ? ProtoBuf.CallableKind.VAR : ProtoBuf.CallableKind.VAL;
|
||||
}
|
||||
if (descriptor instanceof ConstructorDescriptor) {
|
||||
return ProtoBuf.CallableKind.CONSTRUCTOR;
|
||||
}
|
||||
assert descriptor instanceof FunctionDescriptor : "Unknown descriptor class: " + descriptor.getClass();
|
||||
return ProtoBuf.CallableKind.FUN;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ProtoBuf.ValueParameter.Builder valueParameter(@NotNull ValueParameterDescriptor descriptor) {
|
||||
ProtoBuf.ValueParameter.Builder builder = ProtoBuf.ValueParameter.newBuilder();
|
||||
@@ -577,10 +444,6 @@ public class DescriptorSerializer {
|
||||
for (DeclarationDescriptor declaration : sort(members)) {
|
||||
if (skip != null && skip.invoke(declaration)) continue;
|
||||
|
||||
if (declaration instanceof PropertyDescriptor || declaration instanceof FunctionDescriptor) {
|
||||
builder.addMember(callableProto((CallableMemberDescriptor) declaration));
|
||||
}
|
||||
|
||||
if (declaration instanceof PropertyDescriptor) {
|
||||
builder.addProperty(propertyProto((PropertyDescriptor) declaration));
|
||||
}
|
||||
@@ -599,10 +462,6 @@ public class DescriptorSerializer {
|
||||
ProtoBuf.Package.Builder builder = ProtoBuf.Package.newBuilder();
|
||||
|
||||
for (DeclarationDescriptor declaration : sort(members)) {
|
||||
if (declaration instanceof PropertyDescriptor || declaration instanceof FunctionDescriptor) {
|
||||
builder.addMember(callableProto((CallableMemberDescriptor) declaration));
|
||||
}
|
||||
|
||||
if (declaration instanceof PropertyDescriptor) {
|
||||
builder.addProperty(propertyProto((PropertyDescriptor) declaration));
|
||||
}
|
||||
|
||||
@@ -41,9 +41,6 @@ public abstract class SerializerExtension {
|
||||
public void serializeProperty(@NotNull PropertyDescriptor descriptor, @NotNull ProtoBuf.Property.Builder proto) {
|
||||
}
|
||||
|
||||
public void serializeCallable(@NotNull CallableMemberDescriptor callable, @NotNull ProtoBuf.Callable.Builder proto) {
|
||||
}
|
||||
|
||||
public void serializeValueParameter(@NotNull ValueParameterDescriptor descriptor, @NotNull ProtoBuf.ValueParameter.Builder proto) {
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user