diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForPropertyDescriptor.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForPropertyDescriptor.java index a033117fe91..fc268590774 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForPropertyDescriptor.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AccessorForPropertyDescriptor.java @@ -33,7 +33,7 @@ import java.util.Collections; public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implements AccessorForCallableDescriptor { private final PropertyDescriptor calleeDescriptor; private final ClassDescriptor superCallTarget; - @NotNull private final String nameSuffix; + private final String nameSuffix; private final boolean withSyntheticGetterAccessor; private final boolean withSyntheticSetterAccessor; @@ -95,9 +95,7 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implem public static class Getter extends PropertyGetterDescriptorImpl implements AccessorForCallableDescriptor { public Getter(AccessorForPropertyDescriptor property) { super(property, Annotations.Companion.getEMPTY(), Modality.FINAL, Visibilities.LOCAL, - false, false, - /* isExternal = */ false, - Kind.DECLARATION, null, SourceElement.NO_SOURCE); + /* isDefault = */ false, /* isExternal = */ false, Kind.DECLARATION, null, SourceElement.NO_SOURCE); initialize(property.getType()); } @@ -119,9 +117,7 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implem public static class Setter extends PropertySetterDescriptorImpl implements AccessorForCallableDescriptor{ public Setter(AccessorForPropertyDescriptor property) { super(property, Annotations.Companion.getEMPTY(), Modality.FINAL, Visibilities.LOCAL, - false, false, - /* isExternal = */ false, - Kind.DECLARATION, null, SourceElement.NO_SOURCE); + /* isDefault = */ false, /* isExternal = */ false, Kind.DECLARATION, null, SourceElement.NO_SOURCE); initializeDefault(); } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java index 46b05c47904..b2a4f14d1ca 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/JvmCodegenUtil.java @@ -161,7 +161,7 @@ public class JvmCodegenUtil { if (accessor == null) return true; // If the accessor is non-default (i.e. it has some code) we should call that accessor and not use direct access - if (accessor.hasBody()) return false; + if (DescriptorPsiUtilsKt.hasBody(accessor)) return false; // If the accessor is private or final, it can't be overridden in the subclass and thus we can use direct access return Visibilities.isPrivate(property.getVisibility()) || accessor.getModality() == FINAL; diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt index cf7b4bee7fe..dca7ad22178 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticPropertiesScope.kt @@ -315,7 +315,6 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l Modality.FINAL, visibility, false, - false, getMethod.isExternal, CallableMemberDescriptor.Kind.SYNTHESIZED, null, @@ -328,7 +327,6 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l Modality.FINAL, syntheticExtensionVisibility(setMethod), false, - false, setMethod.isExternal, CallableMemberDescriptor.Kind.SYNTHESIZED, null, @@ -351,7 +349,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l } override fun substitute(originalSubstitutor: TypeSubstitutor): PropertyDescriptor? { - val descriptor = super.substitute(originalSubstitutor) as MyPropertyDescriptor + val descriptor = super.substitute(originalSubstitutor) as MyPropertyDescriptor if (descriptor == this) return descriptor val classTypeParameters = (getMethod.containingDeclaration as ClassDescriptor).typeConstructor.parameters diff --git a/compiler/frontend/src/org/jetbrains/kotlin/descriptors/descriptorPsiUtils.kt b/compiler/frontend/src/org/jetbrains/kotlin/descriptors/descriptorPsiUtils.kt new file mode 100644 index 00000000000..bf2a6f7ff38 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/kotlin/descriptors/descriptorPsiUtils.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2010-2016 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.kotlin.descriptors + +import org.jetbrains.kotlin.psi.KtPropertyAccessor +import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils + +fun PropertyAccessorDescriptor.hasBody(): Boolean { + val ktAccessor = DescriptorToSourceUtils.getSourceFromDescriptor(this) as? KtPropertyAccessor + return ktAccessor != null && ktAccessor.hasBody() +} diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java index 2bfc9118a6c..2bae103886b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java @@ -183,8 +183,8 @@ public interface BindingContext { if (getter == null) return true; if (propertyDescriptor.isVar() && setter == null) return true; - if (setter != null && !setter.hasBody() && setter.getModality() != Modality.ABSTRACT) return true; - if (!getter.hasBody() && getter.getModality() != Modality.ABSTRACT) return true; + if (setter != null && !DescriptorPsiUtilsKt.hasBody(setter) && setter.getModality() != Modality.ABSTRACT) return true; + if (!DescriptorPsiUtilsKt.hasBody(getter) && getter.getModality() != Modality.ABSTRACT) return true; return backingFieldRequired; } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java index 64349e6e6d0..679ad30d990 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DescriptorResolver.java @@ -816,12 +816,13 @@ public class DescriptorResolver { annotationResolver.resolveAnnotationsWithoutArguments(scopeWithTypeParameters, setter.getModifierList(), trace))); KtParameter parameter = setter.getParameter(); - setterDescriptor = new PropertySetterDescriptorImpl(propertyDescriptor, annotations, - resolveModalityFromModifiers(setter, propertyDescriptor.getModality()), - resolveVisibilityFromModifiers(setter, propertyDescriptor.getVisibility()), - setter.hasBody(), false, setter.hasModifier(EXTERNAL_KEYWORD), - CallableMemberDescriptor.Kind.DECLARATION, null, KotlinSourceElementKt - .toSourceElement(setter)); + setterDescriptor = new PropertySetterDescriptorImpl( + propertyDescriptor, annotations, + resolveModalityFromModifiers(setter, propertyDescriptor.getModality()), + resolveVisibilityFromModifiers(setter, propertyDescriptor.getVisibility()), + /* isDefault = */ false, setter.hasModifier(EXTERNAL_KEYWORD), + CallableMemberDescriptor.Kind.DECLARATION, null, KotlinSourceElementKt.toSourceElement(setter) + ); KtTypeReference returnTypeReference = setter.getReturnTypeReference(); if (returnTypeReference != null) { KotlinType returnType = typeResolver.resolveType(scopeWithTypeParameters, returnTypeReference, trace, true); @@ -905,12 +906,13 @@ public class DescriptorResolver { } } - getterDescriptor = new PropertyGetterDescriptorImpl(propertyDescriptor, getterAnnotations, - resolveModalityFromModifiers(getter, propertyDescriptor.getModality()), - resolveVisibilityFromModifiers(getter, propertyDescriptor.getVisibility()), - getter.hasBody(), false, getter.hasModifier(EXTERNAL_KEYWORD), - CallableMemberDescriptor.Kind.DECLARATION, null, KotlinSourceElementKt - .toSourceElement(getter)); + getterDescriptor = new PropertyGetterDescriptorImpl( + propertyDescriptor, getterAnnotations, + resolveModalityFromModifiers(getter, propertyDescriptor.getModality()), + resolveVisibilityFromModifiers(getter, propertyDescriptor.getVisibility()), + /* isDefault = */ false, getter.hasModifier(EXTERNAL_KEYWORD), + CallableMemberDescriptor.Kind.DECLARATION, null, KotlinSourceElementKt.toSourceElement(getter) + ); if (returnType.isError() && !getter.hasBlockBody() && getter.hasBody()) { returnType = inferReturnTypeFromExpressionBody(storageManager, expressionTypingServices, trace, scopeWithTypeParameters, DataFlowInfoFactory.EMPTY, getter, getterDescriptor); diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaPropertyDescriptor.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaPropertyDescriptor.java index 3fdbefffb4b..1b8b0f04323 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaPropertyDescriptor.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/JavaPropertyDescriptor.java @@ -112,7 +112,8 @@ public class JavaPropertyDescriptor extends PropertyDescriptorImpl implements Ja if (getter != null) { newGetter = new PropertyGetterDescriptorImpl( enhanced, getter.getAnnotations(), getter.getModality(), getter.getVisibility(), - getter.hasBody(), getter.isDefault(), getter.isExternal(), getKind(), getter, getter.getSource()); + getter.isDefault(), getter.isExternal(), getKind(), getter, getter.getSource() + ); newGetter.setInitialSignatureDescriptor(getter.getInitialSignatureDescriptor()); newGetter.initialize(enhancedReturnType); } @@ -122,7 +123,8 @@ public class JavaPropertyDescriptor extends PropertyDescriptorImpl implements Ja if (setter != null) { newSetter = new PropertySetterDescriptorImpl( enhanced, setter.getAnnotations(), setter.getModality(), setter.getVisibility(), - setter.hasBody(), setter.isDefault(), setter.isExternal(), getKind(), setter, setter.getSource()); + setter.isDefault(), setter.isExternal(), getKind(), setter, setter.getSource() + ); newSetter.setInitialSignatureDescriptor(newSetter.getInitialSignatureDescriptor()); newSetter.initialize(setter.getValueParameters().get(0)); } diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/PropertyAccessorDescriptor.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/PropertyAccessorDescriptor.java index 9b1d223eb43..ce40675b707 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/PropertyAccessorDescriptor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/PropertyAccessorDescriptor.java @@ -21,8 +21,6 @@ import org.jetbrains.annotations.NotNull; import java.util.Collection; public interface PropertyAccessorDescriptor extends FunctionDescriptor { - boolean hasBody(); - boolean isDefault(); @NotNull @@ -45,6 +43,4 @@ public interface PropertyAccessorDescriptor extends FunctionDescriptor { Kind kind, boolean copyOverrides ); - - boolean isExternal(); } diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyAccessorDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyAccessorDescriptorImpl.java index 997536be067..34d2f60e57e 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyAccessorDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyAccessorDescriptorImpl.java @@ -29,8 +29,6 @@ import java.util.Collections; import java.util.List; public abstract class PropertyAccessorDescriptorImpl extends DeclarationDescriptorNonRootImpl implements PropertyAccessorDescriptor { - - private final boolean hasBody; private final boolean isDefault; private final boolean isExternal; private final Modality modality; @@ -46,7 +44,6 @@ public abstract class PropertyAccessorDescriptorImpl extends DeclarationDescript @NotNull PropertyDescriptor correspondingProperty, @NotNull Annotations annotations, @NotNull Name name, - boolean hasBody, boolean isDefault, boolean isExternal, Kind kind, @@ -56,17 +53,11 @@ public abstract class PropertyAccessorDescriptorImpl extends DeclarationDescript this.modality = modality; this.visibility = visibility; this.correspondingProperty = correspondingProperty; - this.hasBody = hasBody; this.isDefault = isDefault; this.isExternal = isExternal; this.kind = kind; } - @Override - public boolean hasBody() { - return hasBody; - } - @Override public boolean isDefault() { return isDefault; diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java index da70fab8022..46f2935be8e 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyDescriptorImpl.java @@ -260,7 +260,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp PropertyGetterDescriptorImpl newGetter = getter == null ? null : new PropertyGetterDescriptorImpl( substitutedDescriptor, getter.getAnnotations(), newModality, getter.getVisibility(), - getter.hasBody(), getter.isDefault(), getter.isExternal(), kind, original == null ? null : original.getGetter(), + getter.isDefault(), getter.isExternal(), kind, original == null ? null : original.getGetter(), SourceElement.NO_SOURCE ); if (newGetter != null) { @@ -270,7 +270,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp } PropertySetterDescriptorImpl newSetter = setter == null ? null : new PropertySetterDescriptorImpl( substitutedDescriptor, setter.getAnnotations(), newModality, setter.getVisibility(), - setter.hasBody(), setter.isDefault(), setter.isExternal(), kind, original == null ? null : original.getSetter(), + setter.isDefault(), setter.isExternal(), kind, original == null ? null : original.getSetter(), SourceElement.NO_SOURCE ); if (newSetter != null) { diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyGetterDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyGetterDescriptorImpl.java index bb7bf7d5064..fadc34ae159 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyGetterDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertyGetterDescriptorImpl.java @@ -38,16 +38,14 @@ public class PropertyGetterDescriptorImpl extends PropertyAccessorDescriptorImpl @NotNull Annotations annotations, @NotNull Modality modality, @NotNull Visibility visibility, - boolean hasBody, boolean isDefault, boolean isExternal, @NotNull Kind kind, @Nullable PropertyGetterDescriptor original, @NotNull SourceElement source - ) - { + ) { super(modality, visibility, correspondingProperty, annotations, Name.special(""), - hasBody, isDefault, isExternal, kind, source); + isDefault, isExternal, kind, source); this.original = original != null ? original : this; } diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertySetterDescriptorImpl.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertySetterDescriptorImpl.java index c1d71488bcb..6bcc5863500 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertySetterDescriptorImpl.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/PropertySetterDescriptorImpl.java @@ -30,8 +30,8 @@ import java.util.List; import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.getBuiltIns; public class PropertySetterDescriptorImpl extends PropertyAccessorDescriptorImpl implements PropertySetterDescriptor { - private ValueParameterDescriptor parameter; + @NotNull private final PropertySetterDescriptor original; @@ -40,7 +40,6 @@ public class PropertySetterDescriptorImpl extends PropertyAccessorDescriptorImpl @NotNull Annotations annotations, @NotNull Modality modality, @NotNull Visibility visibility, - boolean hasBody, boolean isDefault, boolean isExternal, @NotNull Kind kind, @@ -48,7 +47,7 @@ public class PropertySetterDescriptorImpl extends PropertyAccessorDescriptorImpl @NotNull SourceElement source ) { super(modality, visibility, correspondingProperty, annotations, Name.special(""), - hasBody, isDefault, isExternal, kind, source); + isDefault, isExternal, kind, source); this.original = original != null ? original : this; } diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorFactory.java b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorFactory.java index 2cb610a3f76..ee6bb1a370d 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorFactory.java +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/DescriptorFactory.java @@ -71,10 +71,10 @@ public class DescriptorFactory { @NotNull Visibility visibility, @NotNull SourceElement sourceElement ) { - PropertySetterDescriptorImpl setterDescriptor = - new PropertySetterDescriptorImpl(propertyDescriptor, annotations, propertyDescriptor.getModality(), - visibility, !isDefault, isDefault, isExternal, - CallableMemberDescriptor.Kind.DECLARATION, null, sourceElement); + PropertySetterDescriptorImpl setterDescriptor = new PropertySetterDescriptorImpl( + propertyDescriptor, annotations, propertyDescriptor.getModality(), visibility, isDefault, isExternal, + CallableMemberDescriptor.Kind.DECLARATION, null, sourceElement + ); setterDescriptor.initializeDefault(); return setterDescriptor; } @@ -103,10 +103,12 @@ public class DescriptorFactory { @NotNull Annotations annotations, boolean isDefault, boolean isExternal, - @NotNull SourceElement sourceElement) { - return new PropertyGetterDescriptorImpl(propertyDescriptor, annotations, propertyDescriptor.getModality(), - propertyDescriptor.getVisibility(), !isDefault, isDefault, isExternal, - CallableMemberDescriptor.Kind.DECLARATION, null, sourceElement); + @NotNull SourceElement sourceElement + ) { + return new PropertyGetterDescriptorImpl( + propertyDescriptor, annotations, propertyDescriptor.getModality(), propertyDescriptor.getVisibility(), + isDefault, isExternal, CallableMemberDescriptor.Kind.DECLARATION, null, sourceElement + ); } @NotNull diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt index 787fc815303..7af87f5bbd2 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt @@ -40,7 +40,7 @@ class MemberDeserializer(private val c: DeserializationContext) { Deserialization.modality(Flags.MODALITY.get(flags)), Deserialization.visibility(Flags.VISIBILITY.get(flags)), Flags.IS_VAR.get(flags), - c.nameResolver.getName(proto.getName()), + c.nameResolver.getName(proto.name), Deserialization.memberKind(Flags.MEMBER_KIND.get(flags)), Flags.IS_LATEINIT.get(flags), Flags.IS_CONST.get(flags), @@ -75,16 +75,15 @@ class MemberDeserializer(private val c: DeserializationContext) { getAnnotations(proto, getterFlags, AnnotatedCallableKind.PROPERTY_GETTER), Deserialization.modality(Flags.MODALITY.get(getterFlags)), Deserialization.visibility(Flags.VISIBILITY.get(getterFlags)), - /* hasBody = */ isNotDefault, /* isDefault = */ !isNotDefault, /* isExternal = */ isExternal, - property.getKind(), null, SourceElement.NO_SOURCE + property.kind, null, SourceElement.NO_SOURCE ) } else { DescriptorFactory.createDefaultGetter(property, Annotations.EMPTY) } - getter.initialize(property.getReturnType()) + getter.initialize(property.returnType) getter } else { @@ -101,10 +100,9 @@ class MemberDeserializer(private val c: DeserializationContext) { getAnnotations(proto, setterFlags, AnnotatedCallableKind.PROPERTY_SETTER), Deserialization.modality(Flags.MODALITY.get(setterFlags)), Deserialization.visibility(Flags.VISIBILITY.get(setterFlags)), - /* hasBody = */ isNotDefault, /* isDefault = */ !isNotDefault, /* isExternal = */ isExternal, - property.getKind(), null, SourceElement.NO_SOURCE + property.kind, null, SourceElement.NO_SOURCE ) val setterLocal = local.childContext(setter, listOf()) val valueParameters = setterLocal.memberDeserializer.valueParameters( diff --git a/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/android/synthetic/res/syntheticDescriptorGeneration.kt b/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/android/synthetic/res/syntheticDescriptorGeneration.kt index 6d4586e3b6e..1b794e17919 100644 --- a/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/android/synthetic/res/syntheticDescriptorGeneration.kt +++ b/plugins/android-compiler-plugin/src/org/jetbrains/kotlin/android/synthetic/res/syntheticDescriptorGeneration.kt @@ -122,10 +122,10 @@ private fun genProperty( Visibilities.PUBLIC, false, false, - false, CallableMemberDescriptor.Kind.SYNTHESIZED, null, - SourceElement.NO_SOURCE) + SourceElement.NO_SOURCE + ) getter.initialize(null)