001 /*
002 * Copyright 2010-2013 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.jet.codegen;
018
019 import org.jetbrains.jet.lang.descriptors.*;
020 import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
021 import org.jetbrains.jet.lang.descriptors.impl.PropertyDescriptorImpl;
022 import org.jetbrains.jet.lang.descriptors.impl.PropertyGetterDescriptorImpl;
023 import org.jetbrains.jet.lang.descriptors.impl.PropertySetterDescriptorImpl;
024 import org.jetbrains.jet.lang.descriptors.impl.TypeParameterDescriptorImpl;
025 import org.jetbrains.jet.lang.resolve.DescriptorUtils;
026 import org.jetbrains.jet.lang.resolve.name.Name;
027 import org.jetbrains.jet.lang.types.JetType;
028
029 import java.util.Collections;
030
031 public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl {
032 public AccessorForPropertyDescriptor(PropertyDescriptor pd, DeclarationDescriptor containingDeclaration, int index) {
033 super(containingDeclaration, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibilities.LOCAL,
034 pd.isVar(), Name.identifier(pd.getName() + "$b$" + index),
035 Kind.DECLARATION);
036
037 boolean isStaticProperty = AsmUtil.isPropertyWithBackingFieldInOuterClass(pd)
038 && !AsmUtil.isClassObjectWithBackingFieldsInOuter(containingDeclaration);
039 JetType receiverType = !isStaticProperty ? DescriptorUtils.getReceiverParameterType(pd.getReceiverParameter()) : null;
040
041 setType(pd.getType(), Collections.<TypeParameterDescriptorImpl>emptyList(), isStaticProperty ? null : pd.getExpectedThisObject(),
042 receiverType);
043 initialize(new Getter(this), new Setter(this));
044 }
045
046 public static class Getter extends PropertyGetterDescriptorImpl {
047 public Getter(AccessorForPropertyDescriptor property) {
048 super(property, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibilities.LOCAL,
049 false,
050 false, Kind.DECLARATION);
051 initialize(property.getType());
052 }
053 }
054
055 public static class Setter extends PropertySetterDescriptorImpl {
056 public Setter(AccessorForPropertyDescriptor property) {
057 super(property, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibilities.LOCAL,
058 false,
059 false, Kind.DECLARATION);
060 initializeDefault();
061 }
062 }
063 }