Change synthetic accessor method names to "access$..."

As per discussion in https://youtrack.jetbrains.com/issue/KT-6870
This commit is contained in:
Alexander Udalov
2015-02-27 16:18:03 +03:00
parent ac9e6cd9ca
commit 2c0830b017
11 changed files with 124 additions and 35 deletions
@@ -41,7 +41,7 @@ public class AccessorForFunctionDescriptor extends SimpleFunctionDescriptorImpl
int index
) {
super(containingDeclaration, null, Annotations.EMPTY,
Name.identifier((descriptor instanceof ConstructorDescriptor ? "$init" : descriptor.getName()) + "$b$" + index),
Name.identifier("access$" + (descriptor instanceof ConstructorDescriptor ? "init" : descriptor.getName()) + "$" + index),
Kind.DECLARATION, SourceElement.NO_SOURCE);
this.calleeDescriptor = descriptor;
@@ -32,6 +32,7 @@ import java.util.Collections;
public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implements AccessorForCallableDescriptor<PropertyDescriptor> {
private final PropertyDescriptor calleeDescriptor;
private final int accessorIndex;
public AccessorForPropertyDescriptor(@NotNull PropertyDescriptor pd, @NotNull DeclarationDescriptor containingDeclaration, int index) {
this(pd, pd.getType(), DescriptorUtils.getReceiverParameterType(pd.getExtensionReceiverParameter()), pd.getDispatchReceiverParameter(), containingDeclaration, index);
@@ -46,10 +47,11 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implem
int index
) {
super(containingDeclaration, null, Annotations.EMPTY, Modality.FINAL, Visibilities.LOCAL,
original.isVar(), Name.identifier(original.getName() + "$b$" + index),
original.isVar(), Name.identifier("access$" + getIndexedAccessorSuffix(original, index)),
Kind.DECLARATION, SourceElement.NO_SOURCE);
this.calleeDescriptor = original;
this.accessorIndex = index;
setType(propertyType, Collections.<TypeParameterDescriptorImpl>emptyList(), dispatchReceiverParameter, receiverType);
initialize(new Getter(this), new Setter(this));
}
@@ -89,4 +91,14 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implem
public PropertyDescriptor getCalleeDescriptor() {
return calleeDescriptor;
}
@NotNull
public String getIndexedAccessorSuffix() {
return getIndexedAccessorSuffix(calleeDescriptor, accessorIndex);
}
@NotNull
private static String getIndexedAccessorSuffix(@NotNull PropertyDescriptor original, int index) {
return original.getName() + "$" + index;
}
}
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils;
import org.jetbrains.kotlin.load.kotlin.nativeDeclarations.NativeDeclarationsPackage;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.FqNameUnsafe;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.name.SpecialNames;
import org.jetbrains.kotlin.psi.JetExpression;
import org.jetbrains.kotlin.psi.JetFile;
@@ -590,12 +591,16 @@ public class JetTypeMapper {
return property.getName().asString();
}
if (descriptor instanceof PropertyGetterDescriptor) {
return PropertyCodegen.getterName(property.getName());
}
else {
return PropertyCodegen.setterName(property.getName());
}
boolean isAccessor = property instanceof AccessorForPropertyDescriptor;
Name propertyName = isAccessor
? Name.identifier(((AccessorForPropertyDescriptor) property).getIndexedAccessorSuffix())
: property.getName();
String accessorName = descriptor instanceof PropertyGetterDescriptor
? PropertyCodegen.getterName(propertyName)
: PropertyCodegen.setterName(propertyName);
return isAccessor ? "access$" + accessorName : accessorName;
}
else if (isLocalNamedFun(descriptor)) {
return "invoke";