Remove VariableDescriptor#isObjectDeclaration and usages.
Replace with BindingContext trace slice OBJECT_DECLARATION_CLASS. Remove corresponding field from constructor. Introduce hack in JavaDescriptorResolver which creates dummy class descriptors for enum entry objects.
This commit is contained in:
@@ -29,7 +29,7 @@ import java.util.Collections;
|
||||
public class AccessorForPropertyDescriptor extends PropertyDescriptor {
|
||||
public AccessorForPropertyDescriptor(PropertyDescriptor pd, DeclarationDescriptor containingDeclaration, int index) {
|
||||
super(containingDeclaration, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibilities.PUBLIC,
|
||||
pd.isVar(), pd.isObjectDeclaration(), Name.identifier(pd.getName() + "$b$" + index),
|
||||
pd.isVar(), Name.identifier(pd.getName() + "$b$" + index),
|
||||
Kind.DECLARATION);
|
||||
|
||||
JetType receiverType = pd.getReceiverParameter().exists() ? pd.getReceiverParameter().getType() : null;
|
||||
|
||||
@@ -1107,7 +1107,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
if (descriptor instanceof PropertyDescriptor) {
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
|
||||
|
||||
if (propertyDescriptor.isObjectDeclaration()) {
|
||||
ClassDescriptor objectClassDescriptor = getBindingContext().get(BindingContext.OBJECT_DECLARATION_CLASS, propertyDescriptor);
|
||||
if (objectClassDescriptor != null) {
|
||||
boolean isEnumEntry = DescriptorUtils.isEnumClassObject(propertyDescriptor.getContainingDeclaration());
|
||||
if (isEnumEntry) {
|
||||
ClassDescriptor containing = (ClassDescriptor) propertyDescriptor.getContainingDeclaration().getContainingDeclaration();
|
||||
@@ -1117,9 +1118,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
return StackValue.onStack(type);
|
||||
}
|
||||
else {
|
||||
ClassifierDescriptor classDescriptor = propertyDescriptor.getReturnType().getConstructor().getDeclarationDescriptor();
|
||||
assert classDescriptor != null;
|
||||
Type type = typeMapper.mapType(classDescriptor.getDefaultType(), MapTypeMode.VALUE);
|
||||
Type type = typeMapper.mapType(objectClassDescriptor.getDefaultType(), MapTypeMode.VALUE);
|
||||
return StackValue.field(type, JvmClassName.byType(type), "$instance", true);
|
||||
}
|
||||
}
|
||||
|
||||
+18
-2
@@ -39,7 +39,10 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameBase;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
@@ -1185,10 +1188,23 @@ public class JavaDescriptorResolver implements DependencyClassByQualifiedNameRes
|
||||
resolveModality(anyMember.getMember(), isFinal),
|
||||
visibility,
|
||||
isVar,
|
||||
DescriptorUtils.isEnumClassObject(realOwner),
|
||||
propertyName,
|
||||
CallableMemberDescriptor.Kind.DECLARATION);
|
||||
|
||||
//TODO: this is a hack to indicate that this enum entry is an object
|
||||
// class descriptor for enum entries is not used by backends so for now this should be safe to use
|
||||
// remove this when JavaDescriptorResolver gets rewritten
|
||||
if (DescriptorUtils.isEnumClassObject(realOwner)) {
|
||||
ClassDescriptorImpl dummyClassDescriptorForEnumEntryObject =
|
||||
new ClassDescriptorImpl(realOwner, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, propertyName);
|
||||
dummyClassDescriptorForEnumEntryObject.initialize(
|
||||
true,
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
Collections.<JetType>emptyList(), JetScope.EMPTY,
|
||||
Collections.<ConstructorDescriptor>emptySet(), null);
|
||||
trace.record(BindingContext.OBJECT_DECLARATION_CLASS, propertyDescriptor, dummyClassDescriptorForEnumEntryObject);
|
||||
}
|
||||
|
||||
PropertyGetterDescriptor getterDescriptor = null;
|
||||
PropertySetterDescriptor setterDescriptor = null;
|
||||
if (members.getter != null) {
|
||||
|
||||
@@ -56,11 +56,6 @@ public class LocalVariableDescriptor extends VariableDescriptorImpl {
|
||||
return isVar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isObjectDeclaration() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Visibility getVisibility() {
|
||||
|
||||
@@ -46,7 +46,6 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
private final Modality modality;
|
||||
private Visibility visibility;
|
||||
private final boolean isVar;
|
||||
private final boolean isObject;
|
||||
private final Set<PropertyDescriptor> overriddenProperties = Sets.newLinkedHashSet(); // LinkedHashSet is essential here
|
||||
private final PropertyDescriptor original;
|
||||
private final Kind kind;
|
||||
@@ -64,12 +63,11 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
boolean isObject,
|
||||
@NotNull Name name,
|
||||
@NotNull Kind kind) {
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
super(containingDeclaration, annotations, name);
|
||||
this.isVar = isVar;
|
||||
this.isObject = isObject;
|
||||
this.modality = modality;
|
||||
this.visibility = visibility;
|
||||
this.original = original == null ? this : original.getOriginal();
|
||||
@@ -82,10 +80,10 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
boolean isObject,
|
||||
@NotNull Name name,
|
||||
@NotNull Kind kind) {
|
||||
this(null, containingDeclaration, annotations, modality, visibility, isVar, isObject, name, kind);
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
this(null, containingDeclaration, annotations, modality, visibility, isVar, name, kind);
|
||||
}
|
||||
|
||||
public PropertyDescriptor(
|
||||
@@ -94,14 +92,13 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
boolean isObject,
|
||||
@Nullable JetType receiverType,
|
||||
@NotNull ReceiverDescriptor expectedThisObject,
|
||||
@NotNull Name name,
|
||||
@NotNull JetType outType,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
this(containingDeclaration, annotations, modality, visibility, isVar, isObject, name, kind);
|
||||
) {
|
||||
this(containingDeclaration, annotations, modality, visibility, isVar, name, kind);
|
||||
setType(outType, Collections.<TypeParameterDescriptor>emptyList(), expectedThisObject, receiverType);
|
||||
}
|
||||
|
||||
@@ -159,11 +156,6 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
return isVar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isObjectDeclaration() {
|
||||
return isObject;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Modality getModality() {
|
||||
@@ -209,7 +201,7 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
private PropertyDescriptor doSubstitute(TypeSubstitutor originalSubstitutor,
|
||||
DeclarationDescriptor newOwner, Modality newModality, Visibility newVisibility, boolean preserveOriginal, boolean copyOverrides, Kind kind) {
|
||||
PropertyDescriptor substitutedDescriptor = new PropertyDescriptor(preserveOriginal ? getOriginal() : this, newOwner,
|
||||
getAnnotations(), newModality, newVisibility, isVar(), isObjectDeclaration(), getName(), kind);
|
||||
getAnnotations(), newModality, newVisibility, isVar(), getName(), kind);
|
||||
|
||||
List<TypeParameterDescriptor> substitutedTypeParameters = Lists.newArrayList();
|
||||
TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(getTypeParameters(), originalSubstitutor, substitutedDescriptor, substitutedTypeParameters);
|
||||
|
||||
@@ -92,7 +92,6 @@ public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl {
|
||||
Modality.FINAL,
|
||||
Visibilities.PUBLIC,
|
||||
false,
|
||||
false,
|
||||
Name.identifier(ScriptNameUtil.LAST_EXPRESSION_VALUE_FIELD_NAME),
|
||||
CallableMemberDescriptor.Kind.DECLARATION);
|
||||
propertyDescriptor.setType(returnType, Collections.<TypeParameterDescriptor>emptyList(), new ClassReceiver(classDescriptor), ReceiverDescriptor.NO_RECEIVER);
|
||||
@@ -181,7 +180,6 @@ public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl {
|
||||
Modality.FINAL,
|
||||
Visibilities.PUBLIC,
|
||||
false,
|
||||
false,
|
||||
parameter.getName(),
|
||||
CallableMemberDescriptor.Kind.DECLARATION);
|
||||
propertyDescriptor.setType(parameter.getType(), Collections.<TypeParameterDescriptor>emptyList(), classReceiver, ReceiverDescriptor.NO_RECEIVER);
|
||||
|
||||
-5
@@ -143,11 +143,6 @@ public class ValueParameterDescriptorImpl extends VariableDescriptorImpl impleme
|
||||
return isVar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isObjectDeclaration() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ValueParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner) {
|
||||
|
||||
@@ -36,6 +36,4 @@ public interface VariableDescriptor extends CallableDescriptor {
|
||||
VariableDescriptor substitute(TypeSubstitutor substitutor);
|
||||
|
||||
boolean isVar();
|
||||
|
||||
boolean isObjectDeclaration();
|
||||
}
|
||||
|
||||
@@ -113,6 +113,8 @@ public interface BindingContext {
|
||||
|
||||
WritableSlice<Box<DeferredType>, Boolean> DEFERRED_TYPE = Slices.createCollectiveSetSlice();
|
||||
|
||||
WritableSlice<PropertyDescriptor, ClassDescriptor> OBJECT_DECLARATION_CLASS = Slices.createSimpleSlice();
|
||||
|
||||
WritableSlice<PropertyDescriptor, Boolean> BACKING_FIELD_REQUIRED = new Slices.SetSlice<PropertyDescriptor>(DO_NOTHING) {
|
||||
@Override
|
||||
public Boolean computeValue(SlicedMap map, PropertyDescriptor propertyDescriptor, Boolean backingFieldRequired, boolean valueNotFound) {
|
||||
|
||||
@@ -609,7 +609,6 @@ public class DescriptorResolver {
|
||||
Modality.FINAL,
|
||||
Visibilities.INTERNAL,
|
||||
variable.isVar(),
|
||||
false,
|
||||
JetPsiUtil.safeName(variable.getName()),
|
||||
CallableMemberDescriptor.Kind.DECLARATION
|
||||
);
|
||||
@@ -678,13 +677,13 @@ public class DescriptorResolver {
|
||||
Modality.FINAL,
|
||||
resolveVisibilityFromModifiers(modifierList),
|
||||
false,
|
||||
true,
|
||||
JetPsiUtil.safeName(objectDeclaration.getName()),
|
||||
CallableMemberDescriptor.Kind.DECLARATION
|
||||
);
|
||||
propertyDescriptor.setType(classDescriptor.getDefaultType(), Collections.<TypeParameterDescriptor>emptyList(),
|
||||
DescriptorUtils.getExpectedThisObjectIfNeeded(containingDeclaration), ReceiverDescriptor.NO_RECEIVER);
|
||||
propertyDescriptor.initialize(createDefaultGetter(propertyDescriptor), null);
|
||||
trace.record(BindingContext.OBJECT_DECLARATION_CLASS, propertyDescriptor, classDescriptor);
|
||||
JetObjectDeclarationName nameAsDeclaration = objectDeclaration.getNameAsDeclaration();
|
||||
if (nameAsDeclaration != null) {
|
||||
trace.record(BindingContext.OBJECT_DECLARATION, nameAsDeclaration, propertyDescriptor);
|
||||
@@ -747,7 +746,6 @@ public class DescriptorResolver {
|
||||
resolveModalityFromModifiers(property.getModifierList(), defaultModality),
|
||||
resolveVisibilityFromModifiers(property.getModifierList()),
|
||||
isVar,
|
||||
false,
|
||||
JetPsiUtil.safeName(property.getName()),
|
||||
CallableMemberDescriptor.Kind.DECLARATION
|
||||
);
|
||||
@@ -1087,7 +1085,6 @@ public class DescriptorResolver {
|
||||
resolveModalityFromModifiers(parameter.getModifierList(), Modality.FINAL),
|
||||
resolveVisibilityFromModifiers(parameter.getModifierList()),
|
||||
isMutable,
|
||||
false,
|
||||
name,
|
||||
CallableMemberDescriptor.Kind.DECLARATION
|
||||
);
|
||||
|
||||
+3
-2
@@ -258,7 +258,7 @@ public class QualifiedExpressionResolver {
|
||||
|
||||
@NotNull
|
||||
private Collection<? extends DeclarationDescriptor> filterAndStoreResolutionResult(@NotNull Collection<SuccessfulLookupResult> lookupResults,
|
||||
@NotNull JetSimpleNameExpression referenceExpression, @NotNull BindingTrace trace, @NotNull JetScope scopeToCheckVisibility,
|
||||
@NotNull JetSimpleNameExpression referenceExpression, @NotNull final BindingTrace trace, @NotNull JetScope scopeToCheckVisibility,
|
||||
boolean onlyClasses, boolean storeResult) {
|
||||
|
||||
if (lookupResults.isEmpty()) {
|
||||
@@ -304,7 +304,8 @@ public class QualifiedExpressionResolver {
|
||||
public boolean apply(@Nullable DeclarationDescriptor descriptor) {
|
||||
return (descriptor instanceof NamespaceDescriptor) ||
|
||||
(descriptor instanceof ClassifierDescriptor) ||
|
||||
(descriptor instanceof VariableDescriptor && ((VariableDescriptor)descriptor).isObjectDeclaration());
|
||||
((descriptor instanceof PropertyDescriptor) &&
|
||||
(trace.get(BindingContext.OBJECT_DECLARATION_CLASS, ((PropertyDescriptor) descriptor)) != null));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -162,7 +162,6 @@ public class ErrorUtils {
|
||||
Modality.OPEN,
|
||||
Visibilities.INTERNAL,
|
||||
true,
|
||||
false,
|
||||
null,
|
||||
ReceiverDescriptor.NO_RECEIVER,
|
||||
Name.special("<ERROR PROPERTY>"),
|
||||
|
||||
@@ -176,7 +176,7 @@ public class JetStandardClasses {
|
||||
false, Variance.OUT_VARIANCE, Name.identifier("T" + (j + 1)), j);
|
||||
typeParameters.add(typeParameterDescriptor);
|
||||
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(classDescriptor, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibilities.PUBLIC, false, false, Name.identifier("_" + (j + 1)), CallableMemberDescriptor.Kind.DECLARATION);
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(classDescriptor, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibilities.PUBLIC, false, Name.identifier("_" + (j + 1)), CallableMemberDescriptor.Kind.DECLARATION);
|
||||
propertyDescriptor.setType(typeParameterDescriptor.getDefaultType(), Collections.<TypeParameterDescriptorImpl>emptyList(), classDescriptor.getImplicitReceiver(), ReceiverDescriptor.NO_RECEIVER);
|
||||
PropertyGetterDescriptor getterDescriptor = new PropertyGetterDescriptor(propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibilities.PUBLIC, false, true, CallableMemberDescriptor.Kind.DECLARATION);
|
||||
getterDescriptor.initialize(typeParameterDescriptor.getDefaultType());
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.jetbrains.k2js.translate.utils.PredefinedAnnotation;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.k2js.translate.utils.AnnotationsUtils.*;
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.isObjectDeclaration;
|
||||
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.*;
|
||||
|
||||
/**
|
||||
@@ -226,7 +227,7 @@ public final class StaticContext {
|
||||
|
||||
PropertyAccessorDescriptor accessorDescriptor = (PropertyAccessorDescriptor) descriptor;
|
||||
String propertyName = accessorDescriptor.getCorrespondingProperty().getName().getName();
|
||||
if (accessorDescriptor.getCorrespondingProperty().isObjectDeclaration()) {
|
||||
if (isObjectDeclaration(bindingContext, accessorDescriptor.getCorrespondingProperty())) {
|
||||
return declareName(descriptor, propertyName);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.k2js.translate.reference.CallParametersResolver.resolveCallParameters;
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.isObjectDeclaration;
|
||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.assignment;
|
||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.setQualifier;
|
||||
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.isConstructorDescriptor;
|
||||
@@ -267,7 +268,12 @@ public final class CallTranslator extends AbstractTranslator {
|
||||
|
||||
private boolean isDirectPropertyAccess() {
|
||||
return descriptor instanceof PropertyAccessorDescriptor &&
|
||||
(context().isEcma5() || ((PropertyAccessorDescriptor) descriptor).getCorrespondingProperty().isObjectDeclaration());
|
||||
(context().isEcma5() || isObjectAccessor((PropertyAccessorDescriptor) descriptor));
|
||||
}
|
||||
|
||||
private boolean isObjectAccessor(@NotNull PropertyAccessorDescriptor propertyAccessorDescriptor) {
|
||||
PropertyDescriptor correspondingProperty = propertyAccessorDescriptor.getCorrespondingProperty();
|
||||
return isObjectDeclaration(bindingContext(), correspondingProperty);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -298,4 +298,11 @@ public final class BindingUtils {
|
||||
@NotNull JetNamedFunction function) {
|
||||
return bindingContext.get(BindingContext.FUNCTION, function);
|
||||
}
|
||||
|
||||
public static boolean isObjectDeclaration(
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull PropertyDescriptor propertyDescriptor
|
||||
) {
|
||||
return bindingContext.get(BindingContext.OBJECT_DECLARATION_CLASS, propertyDescriptor) != null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user