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
017package org.jetbrains.jet.lang.descriptors.impl;
018
019import org.jetbrains.annotations.NotNull;
020import org.jetbrains.annotations.Nullable;
021import org.jetbrains.jet.lang.descriptors.*;
022import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
023import org.jetbrains.jet.lang.resolve.name.Name;
024import org.jetbrains.jet.lang.types.JetType;
025
026import java.util.Collections;
027import java.util.List;
028import java.util.Set;
029
030public class PropertyGetterDescriptorImpl extends PropertyAccessorDescriptorImpl implements PropertyGetterDescriptor {
031    private JetType returnType;
032
033    @NotNull
034    private final PropertyGetterDescriptor original;
035
036    public PropertyGetterDescriptorImpl(
037            @NotNull PropertyDescriptor correspondingProperty,
038            @NotNull List<AnnotationDescriptor> annotations,
039            @NotNull Modality modality,
040            @NotNull Visibility visibility,
041            boolean hasBody,
042            boolean isDefault,
043            @NotNull Kind kind
044    ) {
045        this(correspondingProperty, annotations, modality, visibility, hasBody, isDefault, kind, null);
046    }
047
048    public PropertyGetterDescriptorImpl(
049            @NotNull PropertyDescriptor correspondingProperty,
050            @NotNull List<AnnotationDescriptor> annotations,
051            @NotNull Modality modality,
052            @NotNull Visibility visibility,
053            boolean hasBody,
054            boolean isDefault,
055            @NotNull Kind kind,
056            @Nullable PropertyGetterDescriptor original
057    )
058    {
059        super(modality, visibility, correspondingProperty, annotations, Name.special("<get-" + correspondingProperty.getName() + ">"), hasBody, isDefault, kind);
060        this.original = original != null ? original : this;
061    }
062    
063    public void initialize(JetType returnType) {
064        this.returnType = returnType == null ? getCorrespondingProperty().getType() : returnType;
065    }
066
067    @NotNull
068    @Override
069    public Set<? extends PropertyAccessorDescriptor> getOverriddenDescriptors() {
070        return super.getOverriddenDescriptors(true);
071    }
072
073    @NotNull
074    @Override
075    public List<ValueParameterDescriptor> getValueParameters() {
076        return Collections.emptyList();
077    }
078
079    @Override
080    public JetType getReturnType() {
081        return returnType;
082    }
083
084    @Override
085    public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
086        return visitor.visitPropertyGetterDescriptor(this, data);
087    }
088
089    @NotNull
090    @Override
091    public PropertyGetterDescriptor getOriginal() {
092        return this.original;
093    }
094}