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 com.google.common.collect.Sets; 020import org.jetbrains.annotations.NotNull; 021import org.jetbrains.annotations.Nullable; 022import org.jetbrains.jet.lang.descriptors.*; 023import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; 024import org.jetbrains.jet.lang.resolve.name.Name; 025import org.jetbrains.jet.lang.types.TypeSubstitutor; 026 027import java.util.Collections; 028import java.util.List; 029import java.util.Set; 030 031public 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 List<AnnotationDescriptor> 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 @NotNull 087 @Override 088 public Modality getModality() { 089 return modality; 090 } 091 092 @NotNull 093 @Override 094 public Visibility getVisibility() { 095 return visibility; 096 } 097 098 public void setVisibility(Visibility visibility) { 099 this.visibility = visibility; 100 } 101 102 @Override 103 @NotNull 104 public PropertyDescriptor getCorrespondingProperty() { 105 return correspondingProperty; 106 } 107 108 @Nullable 109 @Override 110 public ReceiverParameterDescriptor getReceiverParameter() { 111 return getCorrespondingProperty().getReceiverParameter(); 112 } 113 114 @Nullable 115 @Override 116 public ReceiverParameterDescriptor getExpectedThisObject() { 117 return getCorrespondingProperty().getExpectedThisObject(); 118 } 119 120 @NotNull 121 @Override 122 public PropertyAccessorDescriptor copy( 123 DeclarationDescriptor newOwner, 124 Modality modality, 125 Visibility visibility, 126 Kind kind, 127 boolean copyOverrides 128 ) { 129 throw new UnsupportedOperationException("Accessors must be copied by the corresponding property"); 130 } 131 132 protected Set<PropertyAccessorDescriptor> getOverriddenDescriptors(boolean isGetter) { 133 Set<? extends PropertyDescriptor> overriddenProperties = getCorrespondingProperty().getOverriddenDescriptors(); 134 Set<PropertyAccessorDescriptor> overriddenAccessors = Sets.newHashSet(); 135 for (PropertyDescriptor overriddenProperty : overriddenProperties) { 136 PropertyAccessorDescriptor accessorDescriptor = isGetter ? overriddenProperty.getGetter() : overriddenProperty.getSetter(); 137 if (accessorDescriptor != null) { 138 overriddenAccessors.add(accessorDescriptor); 139 } 140 } 141 return overriddenAccessors; 142 } 143 144 @Override 145 public void addOverriddenDescriptor(@NotNull CallableMemberDescriptor overridden) { 146 throw new IllegalStateException(); 147 } 148 149 @NotNull 150 @Override 151 public abstract PropertyAccessorDescriptor getOriginal(); 152}