Extract interface: PropertyGetterDescriptor

This commit is contained in:
Andrey Breslav
2013-02-05 11:58:08 +04:00
parent e09cba03cc
commit d8258ef9fb
7 changed files with 113 additions and 84 deletions
@@ -35,7 +35,7 @@ public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl {
initialize(new Getter(this), new Setter(this)); initialize(new Getter(this), new Setter(this));
} }
public static class Getter extends PropertyGetterDescriptor { public static class Getter extends PropertyGetterDescriptorImpl {
public Getter(AccessorForPropertyDescriptor property) { public Getter(AccessorForPropertyDescriptor property) {
super(property, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibilities.PUBLIC, super(property, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibilities.PUBLIC,
false, false,
@@ -206,7 +206,7 @@ public final class JavaPropertyResolver {
trace.record(BindingContext.OBJECT_DECLARATION_CLASS, propertyDescriptor, dummyClassDescriptorForEnumEntryObject); 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); PropertySetterDescriptor setterDescriptor = resolveSetter(psiData, kind, propertyDescriptor);
propertyDescriptor.initialize(getterDescriptor, setterDescriptor); propertyDescriptor.initialize(getterDescriptor, setterDescriptor);
@@ -268,7 +268,7 @@ public final class JavaPropertyResolver {
private static void initializeSetterAndGetter( private static void initializeSetterAndGetter(
PropertyDescriptor propertyDescriptor, PropertyDescriptor propertyDescriptor,
PropertyGetterDescriptor getterDescriptor, PropertyGetterDescriptorImpl getterDescriptor,
PropertySetterDescriptor setterDescriptor, PropertySetterDescriptor setterDescriptor,
JetType propertyType JetType propertyType
) { ) {
@@ -307,7 +307,7 @@ public final class JavaPropertyResolver {
} }
@Nullable @Nullable
private PropertyGetterDescriptor resolveGetter( private PropertyGetterDescriptorImpl resolveGetter(
Visibility visibility, Visibility visibility,
CallableMemberDescriptor.Kind kind, CallableMemberDescriptor.Kind kind,
PropertyPsiDataElement getter, PropertyPsiDataElement getter,
@@ -316,7 +316,7 @@ public final class JavaPropertyResolver {
if (getter == null) { if (getter == null) {
return null; return null;
} }
return new PropertyGetterDescriptor( return new PropertyGetterDescriptorImpl(
propertyDescriptor, propertyDescriptor,
annotationResolver.resolveAnnotations(getter.getMember().getPsiMember()), annotationResolver.resolveAnnotations(getter.getMember().getPsiMember()),
Modality.OPEN, Modality.OPEN,
@@ -46,7 +46,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr
private ReceiverParameterDescriptor expectedThisObject; private ReceiverParameterDescriptor expectedThisObject;
private ReceiverParameterDescriptor receiverParameter; private ReceiverParameterDescriptor receiverParameter;
private List<TypeParameterDescriptor> typeParameters; private List<TypeParameterDescriptor> typeParameters;
private PropertyGetterDescriptor getter; private PropertyGetterDescriptorImpl getter;
private PropertySetterDescriptor setter; private PropertySetterDescriptor setter;
private PropertyDescriptorImpl( private PropertyDescriptorImpl(
@@ -119,7 +119,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr
this.expectedThisObject = expectedThisObject; 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.getter = getter;
this.setter = setter; this.setter = setter;
} }
@@ -171,7 +171,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr
@Override @Override
@Nullable @Nullable
public PropertyGetterDescriptor getGetter() { public PropertyGetterDescriptorImpl getGetter() {
return getter; return getter;
} }
@@ -238,7 +238,7 @@ public class PropertyDescriptorImpl extends VariableDescriptorImpl implements Pr
substitutedDescriptor.setType(outType, substitutedTypeParameters, substitutedExpectedThisObject, substitutedReceiverType); 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()), substitutedDescriptor, Lists.newArrayList(getter.getAnnotations()),
DescriptorUtils.convertModality(getter.getModality(), false), convertVisibility(getter.getVisibility(), newVisibility), DescriptorUtils.convertModality(getter.getModality(), false), convertVisibility(getter.getVisibility(), newVisibility),
getter.hasBody(), getter.isDefault(), kind, getter.getOriginal()); getter.hasBody(), getter.isDefault(), kind, getter.getOriginal());
@@ -17,73 +17,9 @@
package org.jetbrains.jet.lang.descriptors; package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull; 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<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 PropertyGetterDescriptor(@NotNull PropertyDescriptor correspondingProperty,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull Modality modality,
@NotNull Visibility visibility,
boolean hasBody,
boolean isDefault,
@NotNull Kind kind,
@Nullable PropertyGetterDescriptor original)
{
super(modality, visibility, correspondingProperty, annotations, Name.special("<get-" + correspondingProperty.getName() + ">"), 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 @NotNull
@Override @Override
public Set<? extends PropertyAccessorDescriptor> getOverriddenDescriptors() { PropertyGetterDescriptor getOriginal();
return super.getOverriddenDescriptors(true);
}
@NotNull
@Override
public List<ValueParameterDescriptor> getValueParameters() {
return Collections.emptyList();
}
@Override
public JetType getReturnType() {
return returnType;
}
@Override
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
return visitor.visitPropertyGetterDescriptor(this, data);
}
@NotNull
@Override
public PropertyGetterDescriptor getOriginal() {
return this.original;
}
} }
@@ -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<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 PropertyGetterDescriptorImpl(
@NotNull PropertyDescriptor correspondingProperty,
@NotNull List<AnnotationDescriptor> annotations,
@NotNull Modality modality,
@NotNull Visibility visibility,
boolean hasBody,
boolean isDefault,
@NotNull Kind kind,
@Nullable PropertyGetterDescriptor original
)
{
super(modality, visibility, correspondingProperty, annotations, Name.special("<get-" + correspondingProperty.getName() + ">"), 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<? extends PropertyAccessorDescriptor> getOverriddenDescriptors() {
return super.getOverriddenDescriptors(true);
}
@NotNull
@Override
public List<ValueParameterDescriptor> getValueParameters() {
return Collections.emptyList();
}
@Override
public JetType getReturnType() {
return returnType;
}
@Override
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
return visitor.visitPropertyGetterDescriptor(this, data);
}
@NotNull
@Override
public PropertyGetterDescriptor getOriginal() {
return this.original;
}
}
@@ -118,7 +118,7 @@ public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl {
} }
public static void initializeWithDefaultGetterSetter(PropertyDescriptorImpl propertyDescriptor) { public static void initializeWithDefaultGetterSetter(PropertyDescriptorImpl propertyDescriptor) {
PropertyGetterDescriptor getter = propertyDescriptor.getGetter(); PropertyGetterDescriptorImpl getter = propertyDescriptor.getGetter();
if(getter == null) { if(getter == null) {
getter = propertyDescriptor.getVisibility() != Visibilities.PRIVATE ? DescriptorResolver.createDefaultGetter(propertyDescriptor) : null; getter = propertyDescriptor.getVisibility() != Visibilities.PRIVATE ? DescriptorResolver.createDefaultGetter(propertyDescriptor) : null;
if(getter != null) if(getter != null)
@@ -946,7 +946,7 @@ public class DescriptorResolver {
propertyDescriptor.setType(type, typeParameterDescriptors, getExpectedThisObjectIfNeeded(containingDeclaration), propertyDescriptor.setType(type, typeParameterDescriptors, getExpectedThisObjectIfNeeded(containingDeclaration),
receiverDescriptor); receiverDescriptor);
PropertyGetterDescriptor getter = resolvePropertyGetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor, trace); PropertyGetterDescriptorImpl getter = resolvePropertyGetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor, trace);
PropertySetterDescriptor setter = resolvePropertySetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor, trace); PropertySetterDescriptor setter = resolvePropertySetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor, trace);
propertyDescriptor.initialize(getter, setter); propertyDescriptor.initialize(getter, setter);
@@ -1087,13 +1087,13 @@ public class DescriptorResolver {
} }
@Nullable @Nullable
private PropertyGetterDescriptor resolvePropertyGetterDescriptor( private PropertyGetterDescriptorImpl resolvePropertyGetterDescriptor(
@NotNull JetScope scope, @NotNull JetScope scope,
@NotNull JetProperty property, @NotNull JetProperty property,
@NotNull PropertyDescriptor propertyDescriptor, @NotNull PropertyDescriptor propertyDescriptor,
BindingTrace trace BindingTrace trace
) { ) {
PropertyGetterDescriptor getterDescriptor; PropertyGetterDescriptorImpl getterDescriptor;
JetPropertyAccessor getter = property.getGetter(); JetPropertyAccessor getter = property.getGetter();
if (getter != null) { if (getter != null) {
List<AnnotationDescriptor> annotations = annotationResolver.resolveAnnotations(scope, getter.getModifierList(), trace); List<AnnotationDescriptor> annotations = annotationResolver.resolveAnnotations(scope, getter.getModifierList(), trace);
@@ -1108,7 +1108,7 @@ public class DescriptorResolver {
} }
} }
getterDescriptor = new PropertyGetterDescriptor( getterDescriptor = new PropertyGetterDescriptorImpl(
propertyDescriptor, annotations, propertyDescriptor, annotations,
resolveModalityFromModifiers(getter, propertyDescriptor.getModality()), resolveModalityFromModifiers(getter, propertyDescriptor.getModality()),
resolveVisibilityFromModifiers(getter, propertyDescriptor.getVisibility()), resolveVisibilityFromModifiers(getter, propertyDescriptor.getVisibility()),
@@ -1123,9 +1123,9 @@ public class DescriptorResolver {
return getterDescriptor; return getterDescriptor;
} }
public static PropertyGetterDescriptor createDefaultGetter(PropertyDescriptor propertyDescriptor) { public static PropertyGetterDescriptorImpl createDefaultGetter(PropertyDescriptor propertyDescriptor) {
PropertyGetterDescriptor getterDescriptor; PropertyGetterDescriptorImpl getterDescriptor;
getterDescriptor = new PropertyGetterDescriptor( getterDescriptor = new PropertyGetterDescriptorImpl(
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(), propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
propertyDescriptor.getVisibility(), propertyDescriptor.getVisibility(),
false, true, CallableMemberDescriptor.Kind.DECLARATION); false, true, CallableMemberDescriptor.Kind.DECLARATION);
@@ -1208,7 +1208,7 @@ public class DescriptorResolver {
propertyDescriptor.setType(type, Collections.<TypeParameterDescriptor>emptyList(), propertyDescriptor.setType(type, Collections.<TypeParameterDescriptor>emptyList(),
getExpectedThisObjectIfNeeded(classDescriptor), NO_RECEIVER_PARAMETER); getExpectedThisObjectIfNeeded(classDescriptor), NO_RECEIVER_PARAMETER);
PropertyGetterDescriptor getter = createDefaultGetter(propertyDescriptor); PropertyGetterDescriptorImpl getter = createDefaultGetter(propertyDescriptor);
PropertySetterDescriptor setter = propertyDescriptor.isVar() ? createDefaultSetter(propertyDescriptor) : null; PropertySetterDescriptor setter = propertyDescriptor.isVar() ? createDefaultSetter(propertyDescriptor) : null;
propertyDescriptor.initialize(getter, setter); propertyDescriptor.initialize(getter, setter);