Delete OBJECT_PROPERTY kind from binary format

We never create properties for objects anymore, except enum entries of Java
enums. Delete PropertyDescriptorForObjectImpl and its usages
This commit is contained in:
Alexander Udalov
2013-11-01 19:16:21 +04:00
parent 42839fa061
commit cb6c98d4d6
153 changed files with 70 additions and 163 deletions
@@ -156,12 +156,11 @@ message Callable {
}
enum CallableKind {
// 3 bits
// 2 bits
FUN = 0;
VAL = 1;
VAR = 2;
CONSTRUCTOR = 3;
OBJECT_PROPERTY = 4;
}
/*
@@ -1,34 +1,30 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.descriptors.serialization;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.ClassOrNamespaceDescriptor;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.List;
public final class ClassId {
private final FqName packageFqName;
private final FqNameUnsafe relativeClassName;
@NotNull
public static ClassId fromFqNameAndContainingDeclaration(
@NotNull FqNameUnsafe fqName,
@NotNull ClassOrNamespaceDescriptor containingDeclaration
) {
NamespaceDescriptor containingNamespace = DescriptorUtils.getParentOfType(containingDeclaration, NamespaceDescriptor.class, false);
assert containingNamespace != null;
List<Name> fullNameSegments = fqName.pathSegments();
FqName namespaceFqName = DescriptorUtils.getFQName(containingNamespace).toSafe();
List<Name> namespaceNameSegments = namespaceFqName.pathSegments();
assert fullNameSegments.subList(0, namespaceNameSegments.size()).equals(namespaceNameSegments);
List<Name> relativeNameSegments = fullNameSegments.subList(namespaceNameSegments.size(), fullNameSegments.size());
return new ClassId(namespaceFqName, FqNameUnsafe.fromSegments(relativeNameSegments));
}
public ClassId(@NotNull FqName packageFqName, @NotNull FqNameUnsafe relativeClassName) {
this.packageFqName = packageFqName;
assert !relativeClassName.isRoot() : "Class name must not be root. " + packageFqName;
@@ -26,10 +26,7 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.descriptors.impl.*;
import org.jetbrains.jet.lang.resolve.DescriptorFactory;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.Variance;
import org.jetbrains.jet.lang.types.error.ErrorClassDescriptor;
import org.jetbrains.jet.storage.StorageManager;
import java.util.ArrayList;
@@ -128,7 +125,6 @@ public class DescriptorDeserializer {
return loadFunction(proto);
case VAL:
case VAR:
case OBJECT_PROPERTY:
return loadProperty(proto);
case CONSTRUCTOR:
return loadConstructor(proto);
@@ -138,7 +134,17 @@ public class DescriptorDeserializer {
@NotNull
private PropertyDescriptor loadProperty(@NotNull Callable proto) {
PropertyDescriptorImpl property = createPropertyDescriptor(proto);
int flags = proto.getFlags();
PropertyDescriptorImpl property = new PropertyDescriptorImpl(
containingDeclaration,
getAnnotations(proto, flags, AnnotatedCallableKind.PROPERTY),
modality(Flags.MODALITY.get(flags)),
visibility(Flags.VISIBILITY.get(flags)),
Flags.CALLABLE_KIND.get(flags) == Callable.CallableKind.VAR,
nameResolver.getName(proto.getName()),
memberKind(Flags.MEMBER_KIND.get(flags))
);
List<TypeParameterDescriptor> typeParameters = new ArrayList<TypeParameterDescriptor>(proto.getTypeParameterCount());
DescriptorDeserializer local = createChildDeserializer(property, proto.getTypeParameterList(), typeParameters);
@@ -152,7 +158,7 @@ public class DescriptorDeserializer {
PropertyGetterDescriptorImpl getter = null;
PropertySetterDescriptorImpl setter = null;
if (Flags.HAS_GETTER.get(proto.getFlags())) {
if (Flags.HAS_GETTER.get(flags)) {
int getterFlags = proto.getGetterFlags();
boolean isNotDefault = proto.hasGetterFlags() && Flags.IS_NOT_DEFAULT.get(getterFlags);
if (isNotDefault) {
@@ -168,7 +174,7 @@ public class DescriptorDeserializer {
getter.initialize(property.getReturnType());
}
if (Flags.HAS_SETTER.get(proto.getFlags())) {
if (Flags.HAS_SETTER.get(flags)) {
int setterFlags = proto.getSetterFlags();
boolean isNotDefault = proto.hasSetterFlags() && Flags.IS_NOT_DEFAULT.get(setterFlags);
if (isNotDefault) {
@@ -193,37 +199,6 @@ public class DescriptorDeserializer {
return property;
}
@NotNull
private PropertyDescriptorImpl createPropertyDescriptor(@NotNull Callable proto) {
int flags = proto.getFlags();
Name name = nameResolver.getName(proto.getName());
List<AnnotationDescriptor> annotations = getAnnotations(proto, flags, AnnotatedCallableKind.PROPERTY);
Visibility visibility = visibility(Flags.VISIBILITY.get(flags));
Callable.CallableKind callableKind = Flags.CALLABLE_KIND.get(flags);
if (callableKind == Callable.CallableKind.OBJECT_PROPERTY) {
FqNameUnsafe fqName = DescriptorUtils.getFQName(containingDeclaration).child(name);
ClassId objectId = ClassId.fromFqNameAndContainingDeclaration(fqName, (ClassOrNamespaceDescriptor) containingDeclaration);
ClassDescriptor objectClass = typeDeserializer.getDescriptorFinder().findClass(objectId);
if (objectClass == null) {
// if we are not able to find the class for object property
// then something bad has happened since they should be in the same jar
objectClass = new ErrorClassDescriptor(objectId.asSingleFqName().asString());
}
return new PropertyDescriptorForObjectImpl(containingDeclaration, annotations, visibility, name, objectClass);
}
return new PropertyDescriptorImpl(
containingDeclaration,
annotations,
modality(Flags.MODALITY.get(flags)),
visibility,
callableKind == Callable.CallableKind.VAR,
name,
memberKind(Flags.MEMBER_KIND.get(flags))
);
}
@NotNull
private CallableMemberDescriptor loadFunction(@NotNull Callable proto) {
int flags = proto.getFlags();
@@ -272,13 +272,10 @@ public class DescriptorSerializer {
);
}
private static ProtoBuf.Callable.CallableKind callableKind(CallableMemberDescriptor descriptor) {
if (descriptor instanceof VariableDescriptorForObject) {
return ProtoBuf.Callable.CallableKind.OBJECT_PROPERTY;
}
else if (descriptor instanceof PropertyDescriptor) {
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
return propertyDescriptor.isVar() ? ProtoBuf.Callable.CallableKind.VAR : ProtoBuf.Callable.CallableKind.VAL;
@NotNull
private static ProtoBuf.Callable.CallableKind callableKind(@NotNull CallableMemberDescriptor descriptor) {
if (descriptor instanceof PropertyDescriptor) {
return ((PropertyDescriptor) descriptor).isVar() ? ProtoBuf.Callable.CallableKind.VAR : ProtoBuf.Callable.CallableKind.VAL;
}
if (descriptor instanceof ConstructorDescriptor) {
return ProtoBuf.Callable.CallableKind.CONSTRUCTOR;
@@ -8380,7 +8380,7 @@ public final class ProtoBuf {
* <code>FUN = 0;</code>
*
* <pre>
* 3 bits
* 2 bits
* </pre>
*/
FUN(0, 0),
@@ -8396,17 +8396,13 @@ public final class ProtoBuf {
* <code>CONSTRUCTOR = 3;</code>
*/
CONSTRUCTOR(3, 3),
/**
* <code>OBJECT_PROPERTY = 4;</code>
*/
OBJECT_PROPERTY(4, 4),
;
/**
* <code>FUN = 0;</code>
*
* <pre>
* 3 bits
* 2 bits
* </pre>
*/
public static final int FUN_VALUE = 0;
@@ -8422,10 +8418,6 @@ public final class ProtoBuf {
* <code>CONSTRUCTOR = 3;</code>
*/
public static final int CONSTRUCTOR_VALUE = 3;
/**
* <code>OBJECT_PROPERTY = 4;</code>
*/
public static final int OBJECT_PROPERTY_VALUE = 4;
public final int getNumber() { return value; }
@@ -8436,7 +8428,6 @@ public final class ProtoBuf {
case 1: return VAL;
case 2: return VAR;
case 3: return CONSTRUCTOR;
case 4: return OBJECT_PROPERTY;
default: return null;
}
}
@@ -46,8 +46,7 @@ public abstract class DeserializedMemberScope implements JetScope {
@Override
public boolean accept(ProtoBuf.Callable.CallableKind value) {
return value == ProtoBuf.Callable.CallableKind.VAL ||
value == ProtoBuf.Callable.CallableKind.VAR ||
value == ProtoBuf.Callable.CallableKind.OBJECT_PROPERTY;
value == ProtoBuf.Callable.CallableKind.VAR;
}
};