All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.jetbrains.kotlin.codegen.AccessorForPropertyDescriptor Maven / Gradle / Ivy
/*
* Copyright 2010-2015 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.kotlin.codegen;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl;
import org.jetbrains.kotlin.descriptors.impl.PropertyGetterDescriptorImpl;
import org.jetbrains.kotlin.descriptors.impl.PropertySetterDescriptorImpl;
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.JetSuperExpression;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.types.JetType;
import java.util.Collections;
public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl implements AccessorForCallableDescriptor {
private final PropertyDescriptor calleeDescriptor;
private final int accessorIndex;
private final JetSuperExpression superCallExpression;
public AccessorForPropertyDescriptor(
@NotNull PropertyDescriptor property,
@NotNull DeclarationDescriptor containingDeclaration,
int index,
@Nullable JetSuperExpression superCallExpression
) {
this(property, property.getType(), DescriptorUtils.getReceiverParameterType(property.getExtensionReceiverParameter()),
property.getDispatchReceiverParameter(), containingDeclaration, index, superCallExpression);
}
protected AccessorForPropertyDescriptor(
@NotNull PropertyDescriptor original,
@NotNull JetType propertyType,
@Nullable JetType receiverType,
@Nullable ReceiverParameterDescriptor dispatchReceiverParameter,
@NotNull DeclarationDescriptor containingDeclaration,
int index,
@Nullable JetSuperExpression superCallExpression
) {
super(containingDeclaration, null, Annotations.EMPTY, Modality.FINAL, Visibilities.LOCAL,
original.isVar(), Name.identifier("access$" + getIndexedAccessorSuffix(original, index)),
Kind.DECLARATION, SourceElement.NO_SOURCE, /* lateInit = */ false, /* isConst = */ false);
this.calleeDescriptor = original;
this.accessorIndex = index;
this.superCallExpression = superCallExpression;
setType(propertyType, Collections.emptyList(), dispatchReceiverParameter, receiverType);
initialize(new Getter(this), new Setter(this));
}
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();
}
@Nullable
@Override
public JetSuperExpression getSuperCallExpression() {
return ((AccessorForPropertyDescriptor) getCorrespondingProperty()).getSuperCallExpression();
}
}
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();
}
@Nullable
@Override
public JetSuperExpression getSuperCallExpression() {
return ((AccessorForPropertyDescriptor) getCorrespondingProperty()).getSuperCallExpression();
}
}
@NotNull
@Override
public PropertyDescriptor getCalleeDescriptor() {
return calleeDescriptor;
}
@Override
public JetSuperExpression getSuperCallExpression() {
return superCallExpression;
}
@NotNull
public String getIndexedAccessorSuffix() {
return getIndexedAccessorSuffix(calleeDescriptor, accessorIndex);
}
@NotNull
private static String getIndexedAccessorSuffix(@NotNull PropertyDescriptor original, int index) {
return original.getName() + "$" + index;
}
}