From d8258ef9fb75634934cfd592e577146f7acffb2b Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Tue, 5 Feb 2013 11:58:08 +0400 Subject: [PATCH] Extract interface: PropertyGetterDescriptor --- .../AccessorForPropertyDescriptor.java | 2 +- .../java/resolver/JavaPropertyResolver.java | 8 +- .../descriptors/PropertyDescriptorImpl.java | 8 +- .../descriptors/PropertyGetterDescriptor.java | 68 +------------- .../PropertyGetterDescriptorImpl.java | 93 +++++++++++++++++++ .../lang/descriptors/ScriptDescriptor.java | 2 +- .../jet/lang/resolve/DescriptorResolver.java | 16 ++-- 7 files changed, 113 insertions(+), 84 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyGetterDescriptorImpl.java diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForPropertyDescriptor.java b/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForPropertyDescriptor.java index 32a6823e973..e55d3ab998c 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForPropertyDescriptor.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/AccessorForPropertyDescriptor.java @@ -35,7 +35,7 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl { initialize(new Getter(this), new Setter(this)); } - public static class Getter extends PropertyGetterDescriptor { + public static class Getter extends PropertyGetterDescriptorImpl { public Getter(AccessorForPropertyDescriptor property) { super(property, Collections.emptyList(), Modality.FINAL, Visibilities.PUBLIC, false, diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaPropertyResolver.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaPropertyResolver.java index 85146ef6c4f..d82f820c39e 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaPropertyResolver.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaPropertyResolver.java @@ -206,7 +206,7 @@ public final class JavaPropertyResolver { trace.record(BindingContext.OBJECT_DECLARATION_CLASS, propertyDescriptor, dummyClassDescriptorForEnumEntryObject); } - PropertyGetterDescriptor getterDescriptor = resolveGetter(visibility, kind, getter, propertyDescriptor); + PropertyGetterDescriptorImpl getterDescriptor = resolveGetter(visibility, kind, getter, propertyDescriptor); PropertySetterDescriptor setterDescriptor = resolveSetter(psiData, kind, propertyDescriptor); propertyDescriptor.initialize(getterDescriptor, setterDescriptor); @@ -268,7 +268,7 @@ public final class JavaPropertyResolver { private static void initializeSetterAndGetter( PropertyDescriptor propertyDescriptor, - PropertyGetterDescriptor getterDescriptor, + PropertyGetterDescriptorImpl getterDescriptor, PropertySetterDescriptor setterDescriptor, JetType propertyType ) { @@ -307,7 +307,7 @@ public final class JavaPropertyResolver { } @Nullable - private PropertyGetterDescriptor resolveGetter( + private PropertyGetterDescriptorImpl resolveGetter( Visibility visibility, CallableMemberDescriptor.Kind kind, PropertyPsiDataElement getter, @@ -316,7 +316,7 @@ public final class JavaPropertyResolver { if (getter == null) { return null; } - return new PropertyGetterDescriptor( + return new PropertyGetterDescriptorImpl( propertyDescriptor, annotationResolver.resolveAnnotations(getter.getMember().getPsiMember()), Modality.OPEN, diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptorImpl.java index 08262972433..263f36a59c2 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyDescriptorImpl.java @@ -46,7 +46,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr private ReceiverParameterDescriptor expectedThisObject; private ReceiverParameterDescriptor receiverParameter; private List typeParameters; - private PropertyGetterDescriptor getter; + private PropertyGetterDescriptorImpl getter; private PropertySetterDescriptor setter; private PropertyDescriptorImpl( @@ -119,7 +119,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr this.expectedThisObject = expectedThisObject; } - public void initialize(@Nullable PropertyGetterDescriptor getter, @Nullable PropertySetterDescriptor setter) { + public void initialize(@Nullable PropertyGetterDescriptorImpl getter, @Nullable PropertySetterDescriptor setter) { this.getter = getter; this.setter = setter; } @@ -171,7 +171,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr @Override @Nullable - public PropertyGetterDescriptor getGetter() { + public PropertyGetterDescriptorImpl getGetter() { return getter; } @@ -238,7 +238,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr substitutedDescriptor.setType(outType, substitutedTypeParameters, substitutedExpectedThisObject, substitutedReceiverType); - PropertyGetterDescriptor newGetter = getter == null ? null : new PropertyGetterDescriptor( + PropertyGetterDescriptorImpl newGetter = getter == null ? null : new PropertyGetterDescriptorImpl( substitutedDescriptor, Lists.newArrayList(getter.getAnnotations()), DescriptorUtils.convertModality(getter.getModality(), false), convertVisibility(getter.getVisibility(), newVisibility), getter.hasBody(), getter.isDefault(), kind, getter.getOriginal()); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyGetterDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyGetterDescriptor.java index ef856202881..a70519dd1b6 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyGetterDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyGetterDescriptor.java @@ -17,73 +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 java.util.Collections; -import java.util.List; -import java.util.Set; - -public class PropertyGetterDescriptor extends PropertyAccessorDescriptorImpl { - private JetType returnType; - - @NotNull - private final PropertyGetterDescriptor original; - - public PropertyGetterDescriptor(@NotNull PropertyDescriptor correspondingProperty, - @NotNull List annotations, - @NotNull Modality modality, - @NotNull Visibility visibility, - boolean hasBody, - boolean isDefault, - @NotNull Kind kind) { - this(correspondingProperty, annotations, modality, visibility, hasBody, isDefault, kind, null); - } - - public PropertyGetterDescriptor(@NotNull PropertyDescriptor correspondingProperty, - @NotNull List annotations, - @NotNull Modality modality, - @NotNull Visibility visibility, - boolean hasBody, - boolean isDefault, - @NotNull Kind kind, - @Nullable PropertyGetterDescriptor original) - { - super(modality, visibility, correspondingProperty, annotations, Name.special(""), hasBody, isDefault, kind); - this.original = original != null ? original : this; - } - - public void initialize(JetType returnType) { - this.returnType = returnType == null ? getCorrespondingProperty().getType() : returnType; - } +public interface PropertyGetterDescriptor extends PropertyAccessorDescriptor { @NotNull @Override - public Set getOverriddenDescriptors() { - return super.getOverriddenDescriptors(true); - } - - @NotNull - @Override - public List getValueParameters() { - return Collections.emptyList(); - } - - @Override - public JetType getReturnType() { - return returnType; - } - - @Override - public R accept(DeclarationDescriptorVisitor visitor, D data) { - return visitor.visitPropertyGetterDescriptor(this, data); - } - - @NotNull - @Override - public PropertyGetterDescriptor getOriginal() { - return this.original; - } + PropertyGetterDescriptor getOriginal(); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyGetterDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyGetterDescriptorImpl.java new file mode 100644 index 00000000000..5f914cbe9b6 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyGetterDescriptorImpl.java @@ -0,0 +1,93 @@ +/* + * 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 java.util.Collections; +import java.util.List; +import java.util.Set; + +public class PropertyGetterDescriptorImpl extends PropertyAccessorDescriptorImpl implements PropertyGetterDescriptor { + private JetType returnType; + + @NotNull + private final PropertyGetterDescriptor original; + + public PropertyGetterDescriptorImpl( + @NotNull PropertyDescriptor correspondingProperty, + @NotNull List annotations, + @NotNull Modality modality, + @NotNull Visibility visibility, + boolean hasBody, + boolean isDefault, + @NotNull Kind kind + ) { + this(correspondingProperty, annotations, modality, visibility, hasBody, isDefault, kind, null); + } + + public PropertyGetterDescriptorImpl( + @NotNull PropertyDescriptor correspondingProperty, + @NotNull List annotations, + @NotNull Modality modality, + @NotNull Visibility visibility, + boolean hasBody, + boolean isDefault, + @NotNull Kind kind, + @Nullable PropertyGetterDescriptor original + ) + { + super(modality, visibility, correspondingProperty, annotations, Name.special(""), hasBody, isDefault, kind); + this.original = original != null ? original : this; + } + + public void initialize(JetType returnType) { + this.returnType = returnType == null ? getCorrespondingProperty().getType() : returnType; + } + + @NotNull + @Override + public Set getOverriddenDescriptors() { + return super.getOverriddenDescriptors(true); + } + + @NotNull + @Override + public List getValueParameters() { + return Collections.emptyList(); + } + + @Override + public JetType getReturnType() { + return returnType; + } + + @Override + public R accept(DeclarationDescriptorVisitor visitor, D data) { + return visitor.visitPropertyGetterDescriptor(this, data); + } + + @NotNull + @Override + public PropertyGetterDescriptor getOriginal() { + return this.original; + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ScriptDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ScriptDescriptor.java index 16775bb2f92..3f19ffc98f5 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ScriptDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ScriptDescriptor.java @@ -118,7 +118,7 @@ public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl { } public static void initializeWithDefaultGetterSetter(PropertyDescriptorImpl propertyDescriptor) { - PropertyGetterDescriptor getter = propertyDescriptor.getGetter(); + PropertyGetterDescriptorImpl getter = propertyDescriptor.getGetter(); if(getter == null) { getter = propertyDescriptor.getVisibility() != Visibilities.PRIVATE ? DescriptorResolver.createDefaultGetter(propertyDescriptor) : null; if(getter != null) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java index 9e039863207..8a77e885754 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java @@ -946,7 +946,7 @@ public class DescriptorResolver { propertyDescriptor.setType(type, typeParameterDescriptors, getExpectedThisObjectIfNeeded(containingDeclaration), receiverDescriptor); - PropertyGetterDescriptor getter = resolvePropertyGetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor, trace); + PropertyGetterDescriptorImpl getter = resolvePropertyGetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor, trace); PropertySetterDescriptor setter = resolvePropertySetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor, trace); propertyDescriptor.initialize(getter, setter); @@ -1087,13 +1087,13 @@ public class DescriptorResolver { } @Nullable - private PropertyGetterDescriptor resolvePropertyGetterDescriptor( + private PropertyGetterDescriptorImpl resolvePropertyGetterDescriptor( @NotNull JetScope scope, @NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor, BindingTrace trace ) { - PropertyGetterDescriptor getterDescriptor; + PropertyGetterDescriptorImpl getterDescriptor; JetPropertyAccessor getter = property.getGetter(); if (getter != null) { List annotations = annotationResolver.resolveAnnotations(scope, getter.getModifierList(), trace); @@ -1108,7 +1108,7 @@ public class DescriptorResolver { } } - getterDescriptor = new PropertyGetterDescriptor( + getterDescriptor = new PropertyGetterDescriptorImpl( propertyDescriptor, annotations, resolveModalityFromModifiers(getter, propertyDescriptor.getModality()), resolveVisibilityFromModifiers(getter, propertyDescriptor.getVisibility()), @@ -1123,9 +1123,9 @@ public class DescriptorResolver { return getterDescriptor; } - public static PropertyGetterDescriptor createDefaultGetter(PropertyDescriptor propertyDescriptor) { - PropertyGetterDescriptor getterDescriptor; - getterDescriptor = new PropertyGetterDescriptor( + public static PropertyGetterDescriptorImpl createDefaultGetter(PropertyDescriptor propertyDescriptor) { + PropertyGetterDescriptorImpl getterDescriptor; + getterDescriptor = new PropertyGetterDescriptorImpl( propertyDescriptor, Collections.emptyList(), propertyDescriptor.getModality(), propertyDescriptor.getVisibility(), false, true, CallableMemberDescriptor.Kind.DECLARATION); @@ -1208,7 +1208,7 @@ public class DescriptorResolver { propertyDescriptor.setType(type, Collections.emptyList(), getExpectedThisObjectIfNeeded(classDescriptor), NO_RECEIVER_PARAMETER); - PropertyGetterDescriptor getter = createDefaultGetter(propertyDescriptor); + PropertyGetterDescriptorImpl getter = createDefaultGetter(propertyDescriptor); PropertySetterDescriptor setter = propertyDescriptor.isVar() ? createDefaultSetter(propertyDescriptor) : null; propertyDescriptor.initialize(getter, setter);