Stable accessors names
This commit is contained in:
committed by
Max Kammerer
parent
7851abd535
commit
01864801f3
+3
-3
@@ -31,11 +31,11 @@ public class AccessorForFunctionDescriptor extends AbstractAccessorForFunctionDe
|
||||
public AccessorForFunctionDescriptor(
|
||||
@NotNull FunctionDescriptor descriptor,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
int index,
|
||||
@Nullable JetSuperExpression superCallExpression
|
||||
@Nullable JetSuperExpression superCallExpression,
|
||||
@NotNull String nameSuffix
|
||||
) {
|
||||
super(containingDeclaration,
|
||||
Name.identifier("access$" + (descriptor instanceof ConstructorDescriptor ? "init" : descriptor.getName()) + "$" + index));
|
||||
Name.identifier("access$" + nameSuffix));
|
||||
this.calleeDescriptor = descriptor;
|
||||
this.superCallExpression = superCallExpression;
|
||||
|
||||
|
||||
+3
-3
@@ -26,9 +26,9 @@ public class AccessorForPropertyBackingFieldInOuterClass extends AccessorForProp
|
||||
public AccessorForPropertyBackingFieldInOuterClass(
|
||||
@NotNull PropertyDescriptor property,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
int index,
|
||||
@Nullable JetType delegationType
|
||||
@Nullable JetType delegationType,
|
||||
@NotNull String nameSuffix
|
||||
) {
|
||||
super(property, delegationType != null ? delegationType : property.getType(), null, null, containingDeclaration, index, null);
|
||||
super(property, delegationType != null ? delegationType : property.getType(), null, null, containingDeclaration, null, nameSuffix);
|
||||
}
|
||||
}
|
||||
|
||||
+11
-15
@@ -33,17 +33,17 @@ import java.util.Collections;
|
||||
|
||||
public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implements AccessorForCallableDescriptor<PropertyDescriptor> {
|
||||
private final PropertyDescriptor calleeDescriptor;
|
||||
private final int accessorIndex;
|
||||
private final JetSuperExpression superCallExpression;
|
||||
@NotNull private final String nameSuffix;
|
||||
|
||||
public AccessorForPropertyDescriptor(
|
||||
@NotNull PropertyDescriptor property,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
int index,
|
||||
@Nullable JetSuperExpression superCallExpression
|
||||
@Nullable JetSuperExpression superCallExpression,
|
||||
@NotNull String nameSuffix
|
||||
) {
|
||||
this(property, property.getType(), DescriptorUtils.getReceiverParameterType(property.getExtensionReceiverParameter()),
|
||||
property.getDispatchReceiverParameter(), containingDeclaration, index, superCallExpression);
|
||||
property.getDispatchReceiverParameter(), containingDeclaration, superCallExpression, nameSuffix);
|
||||
}
|
||||
|
||||
protected AccessorForPropertyDescriptor(
|
||||
@@ -52,16 +52,16 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implem
|
||||
@Nullable JetType receiverType,
|
||||
@Nullable ReceiverParameterDescriptor dispatchReceiverParameter,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
int index,
|
||||
@Nullable JetSuperExpression superCallExpression
|
||||
@Nullable JetSuperExpression superCallExpression,
|
||||
@NotNull String nameSuffix
|
||||
) {
|
||||
super(containingDeclaration, null, Annotations.Companion.getEMPTY(), Modality.FINAL, Visibilities.LOCAL,
|
||||
original.isVar(), Name.identifier("access$" + getIndexedAccessorSuffix(original, index)),
|
||||
original.isVar(), Name.identifier("access$" + nameSuffix),
|
||||
Kind.DECLARATION, SourceElement.NO_SOURCE, /* lateInit = */ false, /* isConst = */ false);
|
||||
|
||||
this.calleeDescriptor = original;
|
||||
this.accessorIndex = index;
|
||||
this.superCallExpression = superCallExpression;
|
||||
this.nameSuffix = nameSuffix;
|
||||
setType(propertyType, Collections.<TypeParameterDescriptorImpl>emptyList(), dispatchReceiverParameter, receiverType);
|
||||
initialize(new Getter(this), new Setter(this));
|
||||
}
|
||||
@@ -85,6 +85,7 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implem
|
||||
public JetSuperExpression getSuperCallExpression() {
|
||||
return ((AccessorForPropertyDescriptor) getCorrespondingProperty()).getSuperCallExpression();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Setter extends PropertySetterDescriptorImpl implements AccessorForCallableDescriptor<PropertySetterDescriptor>{
|
||||
@@ -120,12 +121,7 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implem
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getIndexedAccessorSuffix() {
|
||||
return getIndexedAccessorSuffix(calleeDescriptor, accessorIndex);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getIndexedAccessorSuffix(@NotNull PropertyDescriptor original, int index) {
|
||||
return original.getName() + "$" + index;
|
||||
public String getAccessorSuffix() {
|
||||
return nameSuffix;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,11 +303,10 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
accessor instanceof AccessorForPropertyBackingFieldInOuterClass : "There is already exists accessor with isForBackingFieldInOuterClass = false in this context";
|
||||
return (D) accessor;
|
||||
}
|
||||
|
||||
int accessorIndex = accessors.size();
|
||||
String nameSuffix = SyntheticAccessorUtilKt.getAccessorNameSuffix(descriptor, key.superCallLabelTarget, isForBackingFieldInOuterClass);
|
||||
if (descriptor instanceof SimpleFunctionDescriptor) {
|
||||
accessor = new AccessorForFunctionDescriptor(
|
||||
(FunctionDescriptor) descriptor, contextDescriptor, accessorIndex, superCallExpression
|
||||
(FunctionDescriptor) descriptor, contextDescriptor, superCallExpression, nameSuffix
|
||||
);
|
||||
}
|
||||
else if (descriptor instanceof ConstructorDescriptor) {
|
||||
@@ -316,11 +315,11 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
||||
else if (descriptor instanceof PropertyDescriptor) {
|
||||
if (isForBackingFieldInOuterClass) {
|
||||
accessor = new AccessorForPropertyBackingFieldInOuterClass((PropertyDescriptor) descriptor, contextDescriptor,
|
||||
accessorIndex, delegateType);
|
||||
delegateType, nameSuffix);
|
||||
}
|
||||
else {
|
||||
accessor = new AccessorForPropertyDescriptor((PropertyDescriptor) descriptor, contextDescriptor,
|
||||
accessorIndex, superCallExpression);
|
||||
superCallExpression, nameSuffix);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -858,7 +858,7 @@ public class JetTypeMapper {
|
||||
|
||||
boolean isAccessor = property instanceof AccessorForPropertyDescriptor;
|
||||
String propertyName = isAccessor
|
||||
? ((AccessorForPropertyDescriptor) property).getIndexedAccessorSuffix()
|
||||
? ((AccessorForPropertyDescriptor) property).getAccessorSuffix()
|
||||
: property.getName().asString();
|
||||
|
||||
String accessorName = descriptor instanceof PropertyGetterDescriptor
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.codegen
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
|
||||
fun getAccessorNameSuffix(descriptor: CallableMemberDescriptor, superCallDescriptor: ClassDescriptor?, isForBackingFieldInOuterClass: Boolean): String {
|
||||
val suffix = when (descriptor) {
|
||||
is ConstructorDescriptor ->
|
||||
return "will be ignored"
|
||||
is SimpleFunctionDescriptor ->
|
||||
descriptor.name.asString()
|
||||
is PropertyDescriptor ->
|
||||
descriptor.name.asString() + "$" + (if (isForBackingFieldInOuterClass) "cp" else "p")
|
||||
else ->
|
||||
throw UnsupportedOperationException("Do not know how to create accessor for descriptor " + descriptor)
|
||||
}
|
||||
|
||||
return if (superCallDescriptor == null) suffix else "$suffix\$s${superCallDescriptor.name.asString().hashCode()}"
|
||||
}
|
||||
Reference in New Issue
Block a user