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.KtSuperExpression;
024    import org.jetbrains.kotlin.resolve.DescriptorUtils;
025    import org.jetbrains.kotlin.resolve.annotations.AnnotationUtilKt;
026    
027    public class AccessorForFunctionDescriptor extends AbstractAccessorForFunctionDescriptor implements AccessorForCallableDescriptor<FunctionDescriptor> {
028        private final FunctionDescriptor calleeDescriptor;
029        private final KtSuperExpression superCallExpression;
030    
031        public AccessorForFunctionDescriptor(
032                @NotNull FunctionDescriptor descriptor,
033                @NotNull DeclarationDescriptor containingDeclaration,
034                @Nullable KtSuperExpression superCallExpression,
035                @NotNull String nameSuffix
036        ) {
037            super(containingDeclaration,
038                  Name.identifier("access$" + nameSuffix));
039            this.calleeDescriptor = descriptor;
040            this.superCallExpression = superCallExpression;
041    
042            initialize(DescriptorUtils.getReceiverParameterType(descriptor.getExtensionReceiverParameter()),
043                       descriptor instanceof ConstructorDescriptor || AnnotationUtilKt.isPlatformStaticInObjectOrClass(descriptor)
044                            ? null
045                            : descriptor.getDispatchReceiverParameter(),
046                       copyTypeParameters(descriptor),
047                       copyValueParameters(descriptor),
048                       descriptor.getReturnType(),
049                       Modality.FINAL,
050                       Visibilities.LOCAL);
051        }
052    
053        @NotNull
054        @Override
055        public FunctionDescriptor getCalleeDescriptor() {
056            return calleeDescriptor;
057        }
058    
059        @Override
060        public KtSuperExpression getSuperCallExpression() {
061            return superCallExpression;
062        }
063    }