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