diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForCallableDescriptor.java b/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForCallableDescriptor.java new file mode 100644 index 00000000000..92f9e4e1fc6 --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForCallableDescriptor.java @@ -0,0 +1,27 @@ +/* + * Copyright 2010-2014 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.jet.codegen; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.descriptors.CallableDescriptor; +import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor; + +public interface AccessorForCallableDescriptor { + + @NotNull + T getCalleeDescriptor(); +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForFunctionDescriptor.java b/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForFunctionDescriptor.java index 8aa7c37fa83..41fdd6c8a7d 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForFunctionDescriptor.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForFunctionDescriptor.java @@ -30,7 +30,10 @@ import java.util.List; import static org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER; -public class AccessorForFunctionDescriptor extends SimpleFunctionDescriptorImpl { +public class AccessorForFunctionDescriptor extends SimpleFunctionDescriptorImpl implements AccessorForCallableDescriptor { + + private final FunctionDescriptor calleeDescriptor; + public AccessorForFunctionDescriptor( @NotNull FunctionDescriptor descriptor, @NotNull DeclarationDescriptor containingDeclaration, @@ -39,6 +42,7 @@ public class AccessorForFunctionDescriptor extends SimpleFunctionDescriptorImpl super(containingDeclaration, null, Annotations.EMPTY, Name.identifier((descriptor instanceof ConstructorDescriptor ? "$init" : descriptor.getName()) + "$b$" + index), Kind.DECLARATION, SourceElement.NO_SOURCE); + this.calleeDescriptor = descriptor; initialize(DescriptorUtils.getReceiverParameterType(descriptor.getReceiverParameter()), descriptor instanceof ConstructorDescriptor ? NO_RECEIVER_PARAMETER : descriptor.getExpectedThisObject(), @@ -76,4 +80,10 @@ public class AccessorForFunctionDescriptor extends SimpleFunctionDescriptorImpl } return result; } + + @NotNull + @Override + public FunctionDescriptor getCalleeDescriptor() { + return calleeDescriptor; + } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForPropertyDescriptor.java b/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForPropertyDescriptor.java index 8330a4412c1..09bcec2260f 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForPropertyDescriptor.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForPropertyDescriptor.java @@ -30,7 +30,9 @@ import org.jetbrains.jet.lang.types.JetType; import java.util.Collections; -public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl { +public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implements AccessorForCallableDescriptor { + private final PropertyDescriptor calleeDescriptor; + public AccessorForPropertyDescriptor(@NotNull PropertyDescriptor pd, @NotNull DeclarationDescriptor containingDeclaration, int index) { this(pd, pd.getType(), DescriptorUtils.getReceiverParameterType(pd.getReceiverParameter()), pd.getExpectedThisObject(), containingDeclaration, index); } @@ -47,23 +49,44 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl { original.isVar(), Name.identifier(original.getName() + "$b$" + index), Kind.DECLARATION, SourceElement.NO_SOURCE); + this.calleeDescriptor = original; setType(propertyType, Collections.emptyList(), expectedThisObject, receiverType); initialize(new Getter(this), new Setter(this)); } - public static class Getter extends PropertyGetterDescriptorImpl { + public static class Getter extends PropertyGetterDescriptorImpl implements AccessorForCallableDescriptor { public Getter(AccessorForPropertyDescriptor property) { super(property, Annotations.EMPTY, Modality.FINAL, Visibilities.LOCAL, false, false, Kind.DECLARATION, null, SourceElement.NO_SOURCE); initialize(property.getType()); } + + @NotNull + @Override + public PropertyGetterDescriptor getCalleeDescriptor() { + //noinspection ConstantConditions + return ((AccessorForPropertyDescriptor) getCorrespondingProperty()).getCalleeDescriptor().getGetter(); + } } - public static class Setter extends PropertySetterDescriptorImpl { + public static class Setter extends PropertySetterDescriptorImpl implements AccessorForCallableDescriptor{ public Setter(AccessorForPropertyDescriptor property) { super(property, Annotations.EMPTY, Modality.FINAL, Visibilities.LOCAL, false, false, Kind.DECLARATION, null, SourceElement.NO_SOURCE); initializeDefault(); } + + @NotNull + @Override + public PropertySetterDescriptor getCalleeDescriptor() { + //noinspection ConstantConditions + return ((AccessorForPropertyDescriptor) getCorrespondingProperty()).getCalleeDescriptor().getSetter(); + } + } + + @NotNull + @Override + public PropertyDescriptor getCalleeDescriptor() { + return calleeDescriptor; } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java index 3768d157fd4..c248f85e819 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java @@ -500,10 +500,7 @@ public class JetTypeMapper { } public static boolean isAccessor(@NotNull CallableMemberDescriptor descriptor) { - return descriptor instanceof AccessorForFunctionDescriptor || - descriptor instanceof AccessorForPropertyDescriptor || - descriptor instanceof AccessorForPropertyDescriptor.Getter || - descriptor instanceof AccessorForPropertyDescriptor.Setter; + return descriptor instanceof AccessorForCallableDescriptor; } @NotNull