Extract interface: PropertySetterDescriptor

This commit is contained in:
Andrey Breslav
2013-02-05 11:59:50 +04:00
parent d8258ef9fb
commit 2ae3dad92f
6 changed files with 116 additions and 89 deletions
@@ -44,7 +44,7 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl {
}
}
public static class Setter extends PropertySetterDescriptor {
public static class Setter extends PropertySetterDescriptorImpl {
public Setter(AccessorForPropertyDescriptor property) {
super(property, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibilities.PUBLIC,
false,
@@ -207,7 +207,7 @@ public final class JavaPropertyResolver {
}
PropertyGetterDescriptorImpl getterDescriptor = resolveGetter(visibility, kind, getter, propertyDescriptor);
PropertySetterDescriptor setterDescriptor = resolveSetter(psiData, kind, propertyDescriptor);
PropertySetterDescriptorImpl setterDescriptor = resolveSetter(psiData, kind, propertyDescriptor);
propertyDescriptor.initialize(getterDescriptor, setterDescriptor);
@@ -269,7 +269,7 @@ public final class JavaPropertyResolver {
private static void initializeSetterAndGetter(
PropertyDescriptor propertyDescriptor,
PropertyGetterDescriptorImpl getterDescriptor,
PropertySetterDescriptor setterDescriptor,
PropertySetterDescriptorImpl setterDescriptor,
JetType propertyType
) {
if (getterDescriptor != null) {
@@ -327,7 +327,7 @@ public final class JavaPropertyResolver {
}
@Nullable
private PropertySetterDescriptor resolveSetter(
private PropertySetterDescriptorImpl resolveSetter(
PropertyPsiData psiData,
CallableMemberDescriptor.Kind kind,
PropertyDescriptor propertyDescriptor
@@ -343,7 +343,7 @@ public final class JavaPropertyResolver {
((PsiMethodWrapper) setter.getMember())
.getJetMethodAnnotation());
}
return new PropertySetterDescriptor(
return new PropertySetterDescriptorImpl(
propertyDescriptor,
annotationResolver.resolveAnnotations(setter.getMember().getPsiMember()),
Modality.OPEN,
@@ -246,7 +246,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr
JetType returnType = getter.getReturnType();
newGetter.initialize(returnType != null ? substitutor.substitute(returnType, Variance.OUT_VARIANCE) : null);
}
PropertySetterDescriptor newSetter = setter == null ? null : new PropertySetterDescriptor(
PropertySetterDescriptorImpl newSetter = setter == null ? null : new PropertySetterDescriptorImpl(
substitutedDescriptor, Lists.newArrayList(setter.getAnnotations()), DescriptorUtils.convertModality(setter.getModality(), false),
convertVisibility(setter.getVisibility(), newVisibility), setter.hasBody(), setter.isDefault(), kind, setter.getOriginal());
if (newSetter != null) {
@@ -17,85 +17,9 @@
package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import java.util.Collections;
import java.util.List;
import java.util.Set;
public class PropertySetterDescriptor extends PropertyAccessorDescriptorImpl {
private ValueParameterDescriptor parameter;
@NotNull
private final PropertySetterDescriptor original;
public PropertySetterDescriptor(
@NotNull PropertyDescriptor correspondingProperty,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull Modality modality,
@NotNull Visibility visibility,
boolean hasBody,
boolean isDefault,
@NotNull Kind kind) {
this(correspondingProperty, annotations, modality, visibility, hasBody, isDefault, kind, null);
}
public PropertySetterDescriptor(
@NotNull PropertyDescriptor correspondingProperty,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull Modality modality,
@NotNull Visibility visibility,
boolean hasBody,
boolean isDefault,
@NotNull Kind kind,
@Nullable PropertySetterDescriptor original) {
super(modality, visibility, correspondingProperty, annotations, Name.special("<set-" + correspondingProperty.getName() + ">"), hasBody, isDefault, kind);
this.original = original != null ? original : this;
}
public void initialize(@NotNull ValueParameterDescriptor parameter) {
assert this.parameter == null;
this.parameter = parameter;
}
public void initializeDefault() {
assert parameter == null;
parameter = new ValueParameterDescriptorImpl(this, 0, Collections.<AnnotationDescriptor>emptyList(), Name.special("<set-?>"), false, getCorrespondingProperty().getReturnType(), false, null);
}
public interface PropertySetterDescriptor extends PropertyAccessorDescriptor {
@NotNull
@Override
public Set<? extends PropertyAccessorDescriptor> getOverriddenDescriptors() {
return super.getOverriddenDescriptors(false);
}
@NotNull
@Override
public List<ValueParameterDescriptor> getValueParameters() {
if (parameter == null) {
throw new IllegalStateException();
}
return Collections.singletonList(parameter);
}
@NotNull
@Override
public JetType getReturnType() {
return KotlinBuiltIns.getInstance().getUnitType();
}
@Override
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
return visitor.visitPropertySetterDescriptor(this, data);
}
@NotNull
@Override
public PropertySetterDescriptor getOriginal() {
return this.original;
}
PropertySetterDescriptor getOriginal();
}
@@ -0,0 +1,103 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import java.util.Collections;
import java.util.List;
import java.util.Set;
public class PropertySetterDescriptorImpl extends PropertyAccessorDescriptorImpl implements PropertySetterDescriptor {
private ValueParameterDescriptor parameter;
@NotNull
private final PropertySetterDescriptor original;
public PropertySetterDescriptorImpl(
@NotNull PropertyDescriptor correspondingProperty,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull Modality modality,
@NotNull Visibility visibility,
boolean hasBody,
boolean isDefault,
@NotNull Kind kind
) {
this(correspondingProperty, annotations, modality, visibility, hasBody, isDefault, kind, null);
}
public PropertySetterDescriptorImpl(
@NotNull PropertyDescriptor correspondingProperty,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull Modality modality,
@NotNull Visibility visibility,
boolean hasBody,
boolean isDefault,
@NotNull Kind kind,
@Nullable PropertySetterDescriptor original
) {
super(modality, visibility, correspondingProperty, annotations, Name.special("<set-" + correspondingProperty.getName() + ">"), hasBody, isDefault, kind);
this.original = original != null ? original : this;
}
public void initialize(@NotNull ValueParameterDescriptor parameter) {
assert this.parameter == null;
this.parameter = parameter;
}
public void initializeDefault() {
assert parameter == null;
parameter = new ValueParameterDescriptorImpl(this, 0, Collections.<AnnotationDescriptor>emptyList(), Name.special("<set-?>"), false, getCorrespondingProperty().getReturnType(), false, null);
}
@NotNull
@Override
public Set<? extends PropertyAccessorDescriptor> getOverriddenDescriptors() {
return super.getOverriddenDescriptors(false);
}
@NotNull
@Override
public List<ValueParameterDescriptor> getValueParameters() {
if (parameter == null) {
throw new IllegalStateException();
}
return Collections.singletonList(parameter);
}
@NotNull
@Override
public JetType getReturnType() {
return KotlinBuiltIns.getInstance().getUnitType();
}
@Override
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
return visitor.visitPropertySetterDescriptor(this, data);
}
@NotNull
@Override
public PropertySetterDescriptor getOriginal() {
return this.original;
}
}
@@ -1017,12 +1017,12 @@ public class DescriptorResolver {
BindingTrace trace
) {
JetPropertyAccessor setter = property.getSetter();
PropertySetterDescriptor setterDescriptor = null;
PropertySetterDescriptorImpl setterDescriptor = null;
if (setter != null) {
List<AnnotationDescriptor> annotations = annotationResolver.resolveAnnotations(scope, setter.getModifierList(), trace);
JetParameter parameter = setter.getParameter();
setterDescriptor = new PropertySetterDescriptor(
setterDescriptor = new PropertySetterDescriptorImpl(
propertyDescriptor, annotations,
resolveModalityFromModifiers(setter, propertyDescriptor.getModality()),
resolveVisibilityFromModifiers(setter, propertyDescriptor.getVisibility()),
@@ -1076,9 +1076,9 @@ public class DescriptorResolver {
return setterDescriptor;
}
public static PropertySetterDescriptor createDefaultSetter(PropertyDescriptor propertyDescriptor) {
PropertySetterDescriptor setterDescriptor;
setterDescriptor = new PropertySetterDescriptor(
public static PropertySetterDescriptorImpl createDefaultSetter(PropertyDescriptor propertyDescriptor) {
PropertySetterDescriptorImpl setterDescriptor;
setterDescriptor = new PropertySetterDescriptorImpl(
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
propertyDescriptor.getVisibility(),
false, true, CallableMemberDescriptor.Kind.DECLARATION);