Make PropertyAccessorDescriptor#hasBody a front-end utility
This commit is contained in:
committed by
Alexander Udalov
parent
ae14d185eb
commit
4553afbd0c
+3
-7
@@ -33,7 +33,7 @@ import java.util.Collections;
|
||||
public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implements AccessorForCallableDescriptor<PropertyDescriptor> {
|
||||
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<PropertyGetterDescriptor> {
|
||||
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<PropertySetterDescriptor>{
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
+1
-3
@@ -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<PropertyDescriptorImpl>.substitute(originalSubstitutor) as MyPropertyDescriptor
|
||||
val descriptor = super.substitute(originalSubstitutor) as MyPropertyDescriptor
|
||||
if (descriptor == this) return descriptor
|
||||
|
||||
val classTypeParameters = (getMethod.containingDeclaration as ClassDescriptor).typeConstructor.parameters
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user