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 org.jetbrains.annotations.NotNull; 020import org.jetbrains.annotations.Nullable; 021import org.jetbrains.jet.lang.descriptors.*; 022import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; 023import org.jetbrains.jet.lang.resolve.name.Name; 024import org.jetbrains.jet.lang.types.JetType; 025import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; 026 027import java.util.Collections; 028import java.util.List; 029import java.util.Set; 030 031public class PropertySetterDescriptorImpl extends PropertyAccessorDescriptorImpl implements PropertySetterDescriptor { 032 033 private ValueParameterDescriptor parameter; 034 @NotNull 035 private final PropertySetterDescriptor original; 036 037 public PropertySetterDescriptorImpl( 038 @NotNull PropertyDescriptor correspondingProperty, 039 @NotNull List<AnnotationDescriptor> annotations, 040 @NotNull Modality modality, 041 @NotNull Visibility visibility, 042 boolean hasBody, 043 boolean isDefault, 044 @NotNull Kind kind 045 ) { 046 this(correspondingProperty, annotations, modality, visibility, hasBody, isDefault, kind, null); 047 } 048 049 public PropertySetterDescriptorImpl( 050 @NotNull PropertyDescriptor correspondingProperty, 051 @NotNull List<AnnotationDescriptor> annotations, 052 @NotNull Modality modality, 053 @NotNull Visibility visibility, 054 boolean hasBody, 055 boolean isDefault, 056 @NotNull Kind kind, 057 @Nullable PropertySetterDescriptor original 058 ) { 059 super(modality, visibility, correspondingProperty, annotations, Name.special("<set-" + correspondingProperty.getName() + ">"), hasBody, isDefault, kind); 060 this.original = original != null ? original : this; 061 } 062 063 public void initialize(@NotNull ValueParameterDescriptor parameter) { 064 assert this.parameter == null; 065 this.parameter = parameter; 066 } 067 068 public void initializeDefault() { 069 assert parameter == null; 070 parameter = new ValueParameterDescriptorImpl(this, 0, Collections.<AnnotationDescriptor>emptyList(), Name.special("<set-?>"), getCorrespondingProperty().getReturnType(), false, null); 071 } 072 073 @NotNull 074 @Override 075 public Set<? extends PropertyAccessorDescriptor> getOverriddenDescriptors() { 076 return super.getOverriddenDescriptors(false); 077 } 078 079 @NotNull 080 @Override 081 public List<ValueParameterDescriptor> getValueParameters() { 082 if (parameter == null) { 083 throw new IllegalStateException(); 084 } 085 return Collections.singletonList(parameter); 086 } 087 088 @NotNull 089 @Override 090 public JetType getReturnType() { 091 return KotlinBuiltIns.getInstance().getUnitType(); 092 } 093 094 @Override 095 public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) { 096 return visitor.visitPropertySetterDescriptor(this, data); 097 } 098 099 @NotNull 100 @Override 101 public PropertySetterDescriptor getOriginal() { 102 return this.original; 103 } 104}