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