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.types.JetType;
025    import org.jetbrains.jet.lang.types.TypeSubstitutor;
026    import org.jetbrains.jet.lang.types.lang.InlineStrategy;
027    import org.jetbrains.jet.lang.types.lang.InlineUtil;
028    
029    import java.util.List;
030    
031    public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl implements SimpleFunctionDescriptor {
032    
033        private InlineStrategy inlineStrategy;
034    
035        protected SimpleFunctionDescriptorImpl(
036                @NotNull DeclarationDescriptor containingDeclaration,
037                @Nullable SimpleFunctionDescriptor original,
038                @NotNull Annotations annotations,
039                @NotNull Name name,
040                @NotNull Kind kind) {
041            super(containingDeclaration, original, annotations, name, kind);
042        }
043    
044        @NotNull
045        public static SimpleFunctionDescriptorImpl create(
046                @NotNull DeclarationDescriptor containingDeclaration,
047                @NotNull Annotations annotations,
048                @NotNull Name name,
049                @NotNull Kind kind
050        ) {
051            return new SimpleFunctionDescriptorImpl(containingDeclaration, null, annotations, name, kind);
052        }
053    
054    
055        @NotNull
056        @Override
057        public SimpleFunctionDescriptorImpl initialize(
058                @Nullable JetType receiverParameterType,
059                @Nullable ReceiverParameterDescriptor expectedThisObject,
060                @NotNull List<? extends TypeParameterDescriptor> typeParameters,
061                @NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
062                @Nullable JetType unsubstitutedReturnType,
063                @Nullable Modality modality,
064                @NotNull Visibility visibility
065        ) {
066            super.initialize(receiverParameterType, expectedThisObject, typeParameters, unsubstitutedValueParameters, unsubstitutedReturnType,
067                             modality, visibility);
068            this.inlineStrategy = InlineUtil.getInlineType(getAnnotations());
069            return this;
070        }
071    
072        @NotNull
073        @Override
074        public SimpleFunctionDescriptor getOriginal() {
075            return (SimpleFunctionDescriptor) super.getOriginal();
076        }
077    
078        @NotNull
079        @Override
080        protected FunctionDescriptorImpl createSubstitutedCopy(
081                @NotNull DeclarationDescriptor newOwner,
082                @Nullable FunctionDescriptor original,
083                @NotNull Kind kind
084        ) {
085            return new SimpleFunctionDescriptorImpl(
086                    newOwner,
087                    (SimpleFunctionDescriptor) original,
088                    // TODO : safeSubstitute
089                    getAnnotations(),
090                    getName(),
091                    kind);
092        }
093    
094        @NotNull
095        @Override
096        public SimpleFunctionDescriptor copy(DeclarationDescriptor newOwner, Modality modality, Visibility visibility, Kind kind, boolean copyOverrides) {
097            return (SimpleFunctionDescriptorImpl)doSubstitute(TypeSubstitutor.EMPTY, newOwner, modality, visibility, null, copyOverrides, kind);
098        }
099    
100        @NotNull
101        @Override
102        public InlineStrategy getInlineStrategy() {
103            return inlineStrategy;
104        }
105    }