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