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.AnnotationDescriptor;
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    
027    import java.util.List;
028    
029    public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl implements SimpleFunctionDescriptor {
030    
031        private boolean isInline = false;
032    
033        private final SimpleFunctionDescriptor originalOfSynthesized; // TODO replace with user data
034    
035        public SimpleFunctionDescriptorImpl(
036                @NotNull DeclarationDescriptor containingDeclaration,
037                @NotNull List<AnnotationDescriptor> annotations,
038                @NotNull Name name,
039                @NotNull Kind kind
040        ) {
041            this(containingDeclaration, annotations, name, kind, null);
042        }
043    
044        public SimpleFunctionDescriptorImpl(
045                @NotNull DeclarationDescriptor containingDeclaration,
046                @NotNull List<AnnotationDescriptor> annotations,
047                @NotNull Name name,
048                @NotNull Kind kind,
049                @Nullable SimpleFunctionDescriptor originalOfSynthesized
050        ) {
051            super(containingDeclaration, annotations, name, kind);
052            this.originalOfSynthesized = originalOfSynthesized;
053            if (originalOfSynthesized != null) {
054                assert kind == Kind.SYNTHESIZED;
055            }
056        }
057    
058        private SimpleFunctionDescriptorImpl(
059                @NotNull DeclarationDescriptor containingDeclaration,
060                @NotNull SimpleFunctionDescriptor original,
061                @NotNull List<AnnotationDescriptor> annotations,
062                @NotNull Name name,
063                @NotNull Kind kind) {
064            super(containingDeclaration, original, annotations, name, kind);
065            originalOfSynthesized = null;
066        }
067    
068        public SimpleFunctionDescriptorImpl initialize(
069                @Nullable JetType receiverParameterType,
070                @Nullable ReceiverParameterDescriptor expectedThisObject,
071                @NotNull List<? extends TypeParameterDescriptor> typeParameters,
072                @NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
073                @Nullable JetType unsubstitutedReturnType,
074                @Nullable Modality modality,
075                @NotNull Visibility visibility,
076                boolean isInline) {
077            super.initialize(receiverParameterType, expectedThisObject, typeParameters, unsubstitutedValueParameters, unsubstitutedReturnType, modality, visibility);
078            this.isInline = isInline;
079            return this;
080        }
081    
082        @NotNull
083        @Override
084        public SimpleFunctionDescriptor getOriginal() {
085            return (SimpleFunctionDescriptor) super.getOriginal();
086        }
087    
088        @Override
089        protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
090            if (preserveOriginal) {
091                return new SimpleFunctionDescriptorImpl(
092                        newOwner,
093                        getOriginal(),
094                        // TODO : safeSubstitute
095                        getAnnotations(),
096                        getName(),
097                        kind);
098            }
099            else {
100                return new SimpleFunctionDescriptorImpl(
101                        newOwner,
102                        // TODO : safeSubstitute
103                        getAnnotations(),
104                        getName(),
105                        kind);
106            }
107        }
108    
109        @NotNull
110        @Override
111        public SimpleFunctionDescriptor copy(DeclarationDescriptor newOwner, Modality modality, Visibility visibility, Kind kind, boolean copyOverrides) {
112            SimpleFunctionDescriptorImpl copy = (SimpleFunctionDescriptorImpl)doSubstitute(TypeSubstitutor.EMPTY, newOwner, modality, visibility, false, copyOverrides, kind);
113            copy.isInline = isInline;
114            return copy;
115        }
116    
117        @Override
118        public boolean isInline() {
119            return isInline;
120        }
121    
122        // TODO replace with user data
123        @Nullable
124        public SimpleFunctionDescriptor getOriginalOfSynthesized() {
125            return originalOfSynthesized;
126        }
127    }