001    /*
002     * Copyright 2010-2013 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.jet.lang.descriptors.impl;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.annotations.Nullable;
021    import org.jetbrains.jet.lang.descriptors.*;
022    import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
023    import org.jetbrains.jet.lang.resolve.name.Name;
024    import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver;
025    import org.jetbrains.jet.lang.types.JetType;
026    import org.jetbrains.jet.lang.types.TypeSubstitutor;
027    import org.jetbrains.jet.lang.types.Variance;
028    
029    import java.util.Collections;
030    import java.util.List;
031    import java.util.Set;
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.EMPTY, RECEIVER_PARAMETER_NAME);
038        }
039    
040        @Nullable
041        @Override
042        public ReceiverParameterDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
043            if (substitutor.isEmpty()) return this;
044            JetType substitutedType = substitutor.substitute(getType(), Variance.INVARIANT);
045            if (substitutedType == null) return null;
046    
047            return new ReceiverParameterDescriptorImpl(getContainingDeclaration(), substitutedType, 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 getReceiverParameter() {
058            return null;
059        }
060    
061        @Nullable
062        @Override
063        public ReceiverParameterDescriptor getExpectedThisObject() {
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 JetType getReturnType() {
076            return getType();
077        }
078    
079        @NotNull
080        @Override
081        public List<ValueParameterDescriptor> getValueParameters() {
082            return Collections.emptyList();
083        }
084    
085        @Override
086        public boolean hasStableParameterNames() {
087            return false;
088        }
089    
090        @Override
091        public boolean hasSynthesizedParameterNames() {
092            return false;
093        }
094    
095        @NotNull
096        @Override
097        public Set<? extends CallableDescriptor> getOverriddenDescriptors() {
098            return Collections.emptySet();
099        }
100    
101        @NotNull
102        @Override
103        public Visibility getVisibility() {
104            return Visibilities.LOCAL;
105        }
106    
107        @NotNull
108        @Override
109        public CallableDescriptor getOriginal() {
110            return this;
111        }
112    }