diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/AbstractReceiverParameterDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/AbstractReceiverParameterDescriptor.java new file mode 100644 index 00000000000..d28eb6d6f22 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/AbstractReceiverParameterDescriptor.java @@ -0,0 +1,50 @@ +/* + * Copyright 2010-2012 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.Nullable; +import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; +import org.jetbrains.jet.lang.resolve.name.Name; +import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver; +import org.jetbrains.jet.lang.types.JetType; +import org.jetbrains.jet.lang.types.TypeSubstitutor; +import org.jetbrains.jet.lang.types.Variance; + +import java.util.Collections; + +public abstract class AbstractReceiverParameterDescriptor extends DeclarationDescriptorImpl implements ReceiverParameterDescriptor { + private static final Name RECEIVER_PARAMETER_NAME = Name.special(""); + + public AbstractReceiverParameterDescriptor() { + super(Collections.emptyList(), RECEIVER_PARAMETER_NAME); + } + + @Nullable + @Override + public ReceiverParameterDescriptor substitute(TypeSubstitutor substitutor) { + if (substitutor.isEmpty()) return this; + JetType substitutedType = substitutor.substitute(getType(), Variance.INVARIANT); + if (substitutedType == null) return null; + + return new ReceiverParameterDescriptorImpl(getContainingDeclaration(), substitutedType, new TransientReceiver(substitutedType)); + } + + @Override + public R accept(DeclarationDescriptorVisitor visitor, D data) { + return visitor.visitReceiverParameterDescriptor(this, data); + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorVisitor.java index 2ba9c419332..fe0eec62d83 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorVisitor.java @@ -45,4 +45,6 @@ public interface DeclarationDescriptorVisitor { R visitPropertyGetterDescriptor(PropertyGetterDescriptor descriptor, D data); R visitPropertySetterDescriptor(PropertySetterDescriptor descriptor, D data); + + R visitReceiverParameterDescriptor(ReceiverParameterDescriptor descriptor, D data); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NoReceiverParameter.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NoReceiverParameter.java new file mode 100644 index 00000000000..442dd0045ca --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NoReceiverParameter.java @@ -0,0 +1,95 @@ +/* + * Copyright 2010-2012 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.resolve.scopes.receivers.ReceiverDescriptor; +import org.jetbrains.jet.lang.types.JetType; +import org.jetbrains.jet.lang.types.TypeSubstitutor; + +import java.util.Collections; +import java.util.List; + +/*package*/ class NoReceiverParameter implements ReceiverParameterDescriptor { + /*package*/ static final ReceiverParameterDescriptor INSTANCE = new NoReceiverParameter(); + + private NoReceiverParameter() {} + + @NotNull + @Override + public JetType getType() { + throw new UnsupportedOperationException("NO_RECEIVER_PARAMETER.getType()"); + } + + @NotNull + @Override + public ReceiverDescriptor getValue() { + return ReceiverDescriptor.NO_RECEIVER; + } + + @NotNull + @Override + public DeclarationDescriptor getOriginal() { + return this; + } + + @NotNull + @Override + public DeclarationDescriptor getContainingDeclaration() { + throw new UnsupportedOperationException("NO_RECEIVER_PARAMETER.getContainingDeclaration()"); + } + + @Nullable + @Override + public ReceiverParameterDescriptor substitute(TypeSubstitutor substitutor) { + return this; + } + + @Override + public R accept(DeclarationDescriptorVisitor visitor, D data) { + return visitor.visitReceiverParameterDescriptor(this, data); + } + + @Override + public void acceptVoid(DeclarationDescriptorVisitor visitor) { + visitor.visitReceiverParameterDescriptor(this, null); + } + + @Override + public boolean exists() { + return false; + } + + @Override + public String toString() { + return "NO_RECEIVER_PARAMETER"; + } + + @Override + public List getAnnotations() { + return Collections.emptyList(); + } + + @NotNull + @Override + public Name getName() { + throw new UnsupportedOperationException("NO_RECEIVER_PARAMETER.getName()"); + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ReceiverParameterDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ReceiverParameterDescriptor.java new file mode 100644 index 00000000000..70b8269ca37 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ReceiverParameterDescriptor.java @@ -0,0 +1,48 @@ +/* + * Copyright 2010-2012 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.resolve.scopes.receivers.ReceiverDescriptor; +import org.jetbrains.jet.lang.types.JetType; +import org.jetbrains.jet.lang.types.TypeSubstitutor; + +/** + * @author abreslav + */ +public interface ReceiverParameterDescriptor extends DeclarationDescriptor { + + // NOTE: Instead of comparing to NO_RECEIVER_PARAMETER, call exists() + ReceiverParameterDescriptor NO_RECEIVER_PARAMETER = NoReceiverParameter.INSTANCE; + + @NotNull + JetType getType(); + + @NotNull + ReceiverDescriptor getValue(); + + @Override + @NotNull + DeclarationDescriptor getContainingDeclaration(); + + boolean exists(); + + @Nullable + @Override + ReceiverParameterDescriptor substitute(TypeSubstitutor substitutor); +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ReceiverParameterDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ReceiverParameterDescriptorImpl.java new file mode 100644 index 00000000000..60704978f90 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ReceiverParameterDescriptorImpl.java @@ -0,0 +1,60 @@ +/* + * Copyright 2010-2012 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.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; +import org.jetbrains.jet.lang.types.JetType; + +public class ReceiverParameterDescriptorImpl extends AbstractReceiverParameterDescriptor { + private final DeclarationDescriptor containingDeclaration; + private final JetType type; + private final ReceiverDescriptor value; + + public ReceiverParameterDescriptorImpl( + @NotNull DeclarationDescriptor containingDeclaration, + @NotNull JetType type, + @NotNull ReceiverDescriptor value + ) { + this.containingDeclaration = containingDeclaration; + this.type = type; + this.value = value; + } + + @NotNull + @Override + public JetType getType() { + return type; + } + + @NotNull + @Override + public ReceiverDescriptor getValue() { + return value; + } + + @NotNull + @Override + public DeclarationDescriptor getContainingDeclaration() { + return containingDeclaration; + } + + @Override + public boolean exists() { + return true; + } +}