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.types.KotlinType;
025    
026    import java.util.LinkedHashMap;
027    import java.util.List;
028    import java.util.Map;
029    
030    public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl implements SimpleFunctionDescriptor {
031        protected SimpleFunctionDescriptorImpl(
032                @NotNull DeclarationDescriptor containingDeclaration,
033                @Nullable SimpleFunctionDescriptor original,
034                @NotNull Annotations annotations,
035                @NotNull Name name,
036                @NotNull Kind kind,
037                @NotNull SourceElement source
038        ) {
039            super(containingDeclaration, original, annotations, name, kind, source);
040        }
041    
042        @NotNull
043        public static SimpleFunctionDescriptorImpl create(
044                @NotNull DeclarationDescriptor containingDeclaration,
045                @NotNull Annotations annotations,
046                @NotNull Name name,
047                @NotNull Kind kind,
048                @NotNull SourceElement source
049        ) {
050            return new SimpleFunctionDescriptorImpl(containingDeclaration, null, annotations, name, kind, source);
051        }
052    
053        @NotNull
054        @Override
055        public SimpleFunctionDescriptorImpl initialize(
056                @Nullable KotlinType receiverParameterType,
057                @Nullable ReceiverParameterDescriptor dispatchReceiverParameter,
058                @NotNull List<? extends TypeParameterDescriptor> typeParameters,
059                @NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
060                @Nullable KotlinType unsubstitutedReturnType,
061                @Nullable Modality modality,
062                @NotNull Visibility visibility
063        ) {
064            return initialize(receiverParameterType, dispatchReceiverParameter, typeParameters, unsubstitutedValueParameters,
065                              unsubstitutedReturnType, modality, visibility, null);
066        }
067    
068        @NotNull
069        public SimpleFunctionDescriptorImpl initialize(
070                @Nullable KotlinType receiverParameterType,
071                @Nullable ReceiverParameterDescriptor dispatchReceiverParameter,
072                @NotNull List<? extends TypeParameterDescriptor> typeParameters,
073                @NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
074                @Nullable KotlinType unsubstitutedReturnType,
075                @Nullable Modality modality,
076                @NotNull Visibility visibility,
077                @Nullable Map<? extends UserDataKey<?>, ?> userData
078        ) {
079            super.initialize(receiverParameterType, dispatchReceiverParameter, typeParameters, unsubstitutedValueParameters,
080                             unsubstitutedReturnType, modality, visibility);
081    
082            if (userData != null) {
083                userDataMap = new LinkedHashMap<UserDataKey<?>, Object>(userData);
084            }
085    
086            return this;
087        }
088    
089        @NotNull
090        @Override
091        public SimpleFunctionDescriptor getOriginal() {
092            return (SimpleFunctionDescriptor) super.getOriginal();
093        }
094    
095        @NotNull
096        @Override
097        protected FunctionDescriptorImpl createSubstitutedCopy(
098                @NotNull DeclarationDescriptor newOwner,
099                @Nullable FunctionDescriptor original,
100                @NotNull Kind kind,
101                @Nullable Name newName,
102                @NotNull Annotations annotations,
103                @NotNull SourceElement source
104        ) {
105            return new SimpleFunctionDescriptorImpl(
106                    newOwner,
107                    (SimpleFunctionDescriptor) original,
108                    annotations,
109                    newName != null ? newName : getName(),
110                    kind,
111                    source
112            );
113        }
114    
115        @NotNull
116        @Override
117        public SimpleFunctionDescriptor copy(
118                DeclarationDescriptor newOwner,
119                Modality modality,
120                Visibility visibility,
121                Kind kind,
122                boolean copyOverrides
123        ) {
124            return (SimpleFunctionDescriptor) super.copy(newOwner, modality, visibility, kind, copyOverrides);
125        }
126    
127        @NotNull
128        @Override
129        public CopyBuilder<? extends SimpleFunctionDescriptor> newCopyBuilder() {
130            //noinspection unchecked
131            return (CopyBuilder<? extends SimpleFunctionDescriptor>) super.newCopyBuilder();
132        }
133    }