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