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.TypeSubstitutor;
025
026 import java.util.ArrayList;
027 import java.util.Collection;
028 import java.util.Collections;
029 import java.util.List;
030
031 public abstract class PropertyAccessorDescriptorImpl extends DeclarationDescriptorNonRootImpl implements PropertyAccessorDescriptor {
032
033 private final boolean hasBody;
034 private final boolean isDefault;
035 private final boolean isExternal;
036 private final Modality modality;
037 private final PropertyDescriptor correspondingProperty;
038 private final Kind kind;
039 private Visibility visibility;
040
041 public PropertyAccessorDescriptorImpl(
042 @NotNull Modality modality,
043 @NotNull Visibility visibility,
044 @NotNull PropertyDescriptor correspondingProperty,
045 @NotNull Annotations annotations,
046 @NotNull Name name,
047 boolean hasBody,
048 boolean isDefault,
049 boolean isExternal,
050 Kind kind,
051 @NotNull SourceElement source
052 ) {
053 super(correspondingProperty.getContainingDeclaration(), annotations, name, source);
054 this.modality = modality;
055 this.visibility = visibility;
056 this.correspondingProperty = correspondingProperty;
057 this.hasBody = hasBody;
058 this.isDefault = isDefault;
059 this.isExternal = isExternal;
060 this.kind = kind;
061 }
062
063 @Override
064 public boolean hasBody() {
065 return hasBody;
066 }
067
068 @Override
069 public boolean isDefault() {
070 return isDefault;
071 }
072
073 @NotNull
074 @Override
075 public Kind getKind() {
076 return kind;
077 }
078
079 @Override
080 public boolean isOperator() {
081 return false;
082 }
083
084 @Override
085 public boolean isInfix() {
086 return false;
087 }
088
089 @Override
090 public boolean isExternal() {
091 return isExternal;
092 }
093
094 @Override
095 public boolean isInline() {
096 return false;
097 }
098
099 @Override
100 public boolean isTailrec() {
101 return false;
102 }
103
104 @NotNull
105 @Override
106 public FunctionDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
107 throw new UnsupportedOperationException(); // TODO
108 }
109
110 @NotNull
111 @Override
112 public List<TypeParameterDescriptor> getTypeParameters() {
113 return Collections.emptyList();
114 }
115
116 @Override
117 public boolean hasStableParameterNames() {
118 return false;
119 }
120
121 @Override
122 public boolean hasSynthesizedParameterNames() {
123 return false;
124 }
125
126 @NotNull
127 @Override
128 public Modality getModality() {
129 return modality;
130 }
131
132 @NotNull
133 @Override
134 public Visibility getVisibility() {
135 return visibility;
136 }
137
138 public void setVisibility(Visibility visibility) {
139 this.visibility = visibility;
140 }
141
142 @Override
143 @NotNull
144 public PropertyDescriptor getCorrespondingProperty() {
145 return correspondingProperty;
146 }
147
148 @Nullable
149 @Override
150 public ReceiverParameterDescriptor getExtensionReceiverParameter() {
151 return getCorrespondingProperty().getExtensionReceiverParameter();
152 }
153
154 @Nullable
155 @Override
156 public ReceiverParameterDescriptor getDispatchReceiverParameter() {
157 return getCorrespondingProperty().getDispatchReceiverParameter();
158 }
159
160 @NotNull
161 @Override
162 public PropertyAccessorDescriptor copy(
163 DeclarationDescriptor newOwner,
164 Modality modality,
165 Visibility visibility,
166 Kind kind,
167 boolean copyOverrides
168 ) {
169 throw new UnsupportedOperationException("Accessors must be copied by the corresponding property");
170 }
171
172 @NotNull
173 protected Collection<PropertyAccessorDescriptor> getOverriddenDescriptors(boolean isGetter) {
174 Collection<PropertyAccessorDescriptor> result = new ArrayList<PropertyAccessorDescriptor>(0);
175 for (PropertyDescriptor overriddenProperty : getCorrespondingProperty().getOverriddenDescriptors()) {
176 PropertyAccessorDescriptor accessorDescriptor = isGetter ? overriddenProperty.getGetter() : overriddenProperty.getSetter();
177 if (accessorDescriptor != null) {
178 result.add(accessorDescriptor);
179 }
180 }
181 return result;
182 }
183
184 @Override
185 public void addOverriddenDescriptor(@NotNull CallableMemberDescriptor overridden) {
186 throw new IllegalStateException();
187 }
188
189 @NotNull
190 @Override
191 public abstract PropertyAccessorDescriptor getOriginal();
192 }