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