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.lang.descriptors.impl;
018
019 import com.google.common.collect.Sets;
020 import org.jetbrains.annotations.NotNull;
021 import org.jetbrains.annotations.Nullable;
022 import org.jetbrains.jet.lang.descriptors.*;
023 import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
024 import org.jetbrains.jet.lang.resolve.name.Name;
025 import org.jetbrains.jet.lang.types.TypeSubstitutor;
026
027 import java.util.Collections;
028 import java.util.List;
029 import java.util.Set;
030
031 public abstract class PropertyAccessorDescriptorImpl extends DeclarationDescriptorNonRootImpl implements PropertyAccessorDescriptor {
032
033 private final boolean hasBody;
034 private final boolean isDefault;
035 private final Modality modality;
036 private final PropertyDescriptor correspondingProperty;
037 private final Kind kind;
038 private Visibility visibility;
039
040 public PropertyAccessorDescriptorImpl(
041 @NotNull Modality modality,
042 @NotNull Visibility visibility,
043 @NotNull PropertyDescriptor correspondingProperty,
044 @NotNull Annotations annotations,
045 @NotNull Name name,
046 boolean hasBody,
047 boolean isDefault,
048 Kind kind
049 ) {
050 super(correspondingProperty.getContainingDeclaration(), annotations, name);
051 this.modality = modality;
052 this.visibility = visibility;
053 this.correspondingProperty = correspondingProperty;
054 this.hasBody = hasBody;
055 this.isDefault = isDefault;
056 this.kind = kind;
057 }
058
059 @Override
060 public boolean hasBody() {
061 return hasBody;
062 }
063
064 @Override
065 public boolean isDefault() {
066 return isDefault;
067 }
068
069 @Override
070 public Kind getKind() {
071 return kind;
072 }
073
074 @NotNull
075 @Override
076 public FunctionDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
077 throw new UnsupportedOperationException(); // TODO
078 }
079
080 @NotNull
081 @Override
082 public List<TypeParameterDescriptor> getTypeParameters() {
083 return Collections.emptyList();
084 }
085
086 @Override
087 public boolean hasStableParameterNames() {
088 return false;
089 }
090
091 @NotNull
092 @Override
093 public Modality getModality() {
094 return modality;
095 }
096
097 @NotNull
098 @Override
099 public Visibility getVisibility() {
100 return visibility;
101 }
102
103 public void setVisibility(Visibility visibility) {
104 this.visibility = visibility;
105 }
106
107 @Override
108 @NotNull
109 public PropertyDescriptor getCorrespondingProperty() {
110 return correspondingProperty;
111 }
112
113 @Nullable
114 @Override
115 public ReceiverParameterDescriptor getReceiverParameter() {
116 return getCorrespondingProperty().getReceiverParameter();
117 }
118
119 @Nullable
120 @Override
121 public ReceiverParameterDescriptor getExpectedThisObject() {
122 return getCorrespondingProperty().getExpectedThisObject();
123 }
124
125 @NotNull
126 @Override
127 public PropertyAccessorDescriptor copy(
128 DeclarationDescriptor newOwner,
129 Modality modality,
130 Visibility visibility,
131 Kind kind,
132 boolean copyOverrides
133 ) {
134 throw new UnsupportedOperationException("Accessors must be copied by the corresponding property");
135 }
136
137 @NotNull
138 protected Set<PropertyAccessorDescriptor> getOverriddenDescriptors(boolean isGetter) {
139 Set<? extends PropertyDescriptor> overriddenProperties = getCorrespondingProperty().getOverriddenDescriptors();
140 Set<PropertyAccessorDescriptor> overriddenAccessors = Sets.newLinkedHashSet(); // LinkedHashSet for determinism
141 for (PropertyDescriptor overriddenProperty : overriddenProperties) {
142 PropertyAccessorDescriptor accessorDescriptor = isGetter ? overriddenProperty.getGetter() : overriddenProperty.getSetter();
143 if (accessorDescriptor != null) {
144 overriddenAccessors.add(accessorDescriptor);
145 }
146 }
147 return overriddenAccessors;
148 }
149
150 @Override
151 public void addOverriddenDescriptor(@NotNull CallableMemberDescriptor overridden) {
152 throw new IllegalStateException();
153 }
154
155 @NotNull
156 @Override
157 public abstract PropertyAccessorDescriptor getOriginal();
158 }