001 /*
002 * Copyright 2010-2015 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
017 package org.jetbrains.kotlin.descriptors.impl;
018
019 import org.jetbrains.annotations.NotNull;
020 import org.jetbrains.annotations.Nullable;
021 import org.jetbrains.kotlin.descriptors.*;
022 import org.jetbrains.kotlin.descriptors.annotations.Annotations;
023 import org.jetbrains.kotlin.name.Name;
024 import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver;
025 import org.jetbrains.kotlin.types.KotlinType;
026 import org.jetbrains.kotlin.types.TypeSubstitutor;
027 import org.jetbrains.kotlin.types.Variance;
028
029 import java.util.Collection;
030 import java.util.Collections;
031 import java.util.List;
032
033 public abstract class AbstractReceiverParameterDescriptor extends DeclarationDescriptorImpl implements ReceiverParameterDescriptor {
034 private static final Name RECEIVER_PARAMETER_NAME = Name.special("<this>");
035
036 public AbstractReceiverParameterDescriptor() {
037 super(Annotations.Companion.getEMPTY(), RECEIVER_PARAMETER_NAME);
038 }
039
040 @Nullable
041 @Override
042 public ReceiverParameterDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
043 if (substitutor.isEmpty()) return this;
044 KotlinType substitutedType = substitutor.substitute(getType(), Variance.INVARIANT);
045 if (substitutedType == null) return null;
046
047 return new ReceiverParameterDescriptorImpl(getContainingDeclaration(), new TransientReceiver(substitutedType));
048 }
049
050 @Override
051 public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
052 return visitor.visitReceiverParameterDescriptor(this, data);
053 }
054
055 @Nullable
056 @Override
057 public ReceiverParameterDescriptor getExtensionReceiverParameter() {
058 return null;
059 }
060
061 @Nullable
062 @Override
063 public ReceiverParameterDescriptor getDispatchReceiverParameter() {
064 return null;
065 }
066
067 @NotNull
068 @Override
069 public List<TypeParameterDescriptor> getTypeParameters() {
070 return Collections.emptyList();
071 }
072
073 @Nullable
074 @Override
075 public KotlinType getReturnType() {
076 return getType();
077 }
078
079 @NotNull
080 @Override
081 public KotlinType getType() {
082 return getValue().getType();
083 }
084
085 @NotNull
086 @Override
087 public List<ValueParameterDescriptor> getValueParameters() {
088 return Collections.emptyList();
089 }
090
091 @Override
092 public boolean hasStableParameterNames() {
093 return false;
094 }
095
096 @Override
097 public boolean hasSynthesizedParameterNames() {
098 return false;
099 }
100
101 @NotNull
102 @Override
103 public Collection<? extends CallableDescriptor> getOverriddenDescriptors() {
104 return Collections.emptySet();
105 }
106
107 @NotNull
108 @Override
109 public Visibility getVisibility() {
110 return Visibilities.LOCAL;
111 }
112
113 @NotNull
114 @Override
115 public ParameterDescriptor getOriginal() {
116 return this;
117 }
118
119 @NotNull
120 @Override
121 public SourceElement getSource() {
122 return SourceElement.NO_SOURCE;
123 }
124 }