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.annotations.NotNull;
020    import org.jetbrains.annotations.Nullable;
021    import org.jetbrains.jet.lang.descriptors.*;
022    import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
023    import org.jetbrains.jet.lang.descriptors.impl.PropertyDescriptorImpl;
024    import org.jetbrains.jet.lang.descriptors.impl.PropertyGetterDescriptorImpl;
025    import org.jetbrains.jet.lang.descriptors.impl.PropertySetterDescriptorImpl;
026    import org.jetbrains.jet.lang.descriptors.impl.TypeParameterDescriptorImpl;
027    import org.jetbrains.jet.lang.resolve.DescriptorUtils;
028    import org.jetbrains.jet.lang.resolve.name.Name;
029    import org.jetbrains.jet.lang.types.JetType;
030    
031    import java.util.Collections;
032    
033    public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl {
034        public AccessorForPropertyDescriptor(@NotNull PropertyDescriptor pd, @NotNull DeclarationDescriptor containingDeclaration, int index) {
035            this(pd, pd.getType(), DescriptorUtils.getReceiverParameterType(pd.getReceiverParameter()), pd.getExpectedThisObject(), containingDeclaration, index);
036        }
037    
038        protected AccessorForPropertyDescriptor(
039                @NotNull PropertyDescriptor original,
040                @NotNull JetType propertyType,
041                @Nullable JetType receiverType,
042                @Nullable ReceiverParameterDescriptor expectedThisObject,
043                @NotNull DeclarationDescriptor containingDeclaration,
044                int index
045        ) {
046            super(containingDeclaration, null, Annotations.EMPTY, Modality.FINAL, Visibilities.LOCAL,
047                  original.isVar(), Name.identifier(original.getName() + "$b$" + index),
048                  Kind.DECLARATION, SourceElement.NO_SOURCE);
049    
050            setType(propertyType, Collections.<TypeParameterDescriptorImpl>emptyList(), expectedThisObject, receiverType);
051            initialize(new Getter(this), new Setter(this));
052        }
053    
054        public static class Getter extends PropertyGetterDescriptorImpl {
055            public Getter(AccessorForPropertyDescriptor property) {
056                super(property, Annotations.EMPTY, Modality.FINAL, Visibilities.LOCAL,
057                      false, false, Kind.DECLARATION, null, SourceElement.NO_SOURCE);
058                initialize(property.getType());
059            }
060        }
061    
062        public static class Setter extends PropertySetterDescriptorImpl {
063            public Setter(AccessorForPropertyDescriptor property) {
064                super(property, Annotations.EMPTY, Modality.FINAL, Visibilities.LOCAL,
065                      false, false, Kind.DECLARATION, null, SourceElement.NO_SOURCE);
066                initializeDefault();
067            }
068        }
069    }