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