001    /*
002     * Copyright 2010-2015 JetBrains s.r.o.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package org.jetbrains.kotlin.codegen;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.annotations.Nullable;
021    import org.jetbrains.kotlin.descriptors.*;
022    import org.jetbrains.kotlin.name.Name;
023    import org.jetbrains.kotlin.psi.JetSuperExpression;
024    import org.jetbrains.kotlin.resolve.DescriptorUtils;
025    import org.jetbrains.kotlin.resolve.annotations.AnnotationsPackage;
026    
027    public class AccessorForFunctionDescriptor extends AbstractAccessorForFunctionDescriptor implements AccessorForCallableDescriptor<FunctionDescriptor> {
028        private final FunctionDescriptor calleeDescriptor;
029        private final JetSuperExpression superCallExpression;
030    
031        public AccessorForFunctionDescriptor(
032                @NotNull FunctionDescriptor descriptor,
033                @NotNull DeclarationDescriptor containingDeclaration,
034                int index,
035                @Nullable JetSuperExpression superCallExpression
036        ) {
037            super(containingDeclaration,
038                  Name.identifier("access$" + (descriptor instanceof ConstructorDescriptor ? "init" : descriptor.getName()) + "$" + index));
039            this.calleeDescriptor = descriptor;
040            this.superCallExpression = superCallExpression;
041    
042            initialize(DescriptorUtils.getReceiverParameterType(descriptor.getExtensionReceiverParameter()),
043                       descriptor instanceof ConstructorDescriptor || AnnotationsPackage.isPlatformStaticInObjectOrClass(descriptor)
044                            ? null
045                            : descriptor.getDispatchReceiverParameter(),
046                       copyTypeParameters(descriptor),
047                       copyValueParameters(descriptor),
048                       descriptor.getReturnType(),
049                       Modality.FINAL,
050                       Visibilities.INTERNAL,
051                       descriptor.isOperator());
052        }
053    
054        @NotNull
055        @Override
056        public FunctionDescriptor getCalleeDescriptor() {
057            return calleeDescriptor;
058        }
059    
060        @Override
061        public JetSuperExpression getSuperCallExpression() {
062            return superCallExpression;
063        }
064    }