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.load.java.descriptors;
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.descriptors.impl.ConstructorDescriptorImpl;
024    
025    public class JavaConstructorDescriptor extends ConstructorDescriptorImpl implements JavaCallableMemberDescriptor {
026        private Boolean hasStableParameterNames = null;
027        private Boolean hasSynthesizedParameterNames = null;
028    
029        protected JavaConstructorDescriptor(
030                @NotNull ClassDescriptor containingDeclaration,
031                @Nullable JavaConstructorDescriptor original,
032                @NotNull Annotations annotations,
033                boolean isPrimary,
034                @NotNull Kind kind,
035                @NotNull SourceElement source
036        ) {
037            super(containingDeclaration, original, annotations, isPrimary, kind, source);
038        }
039    
040        @NotNull
041        public static JavaConstructorDescriptor createJavaConstructor(
042                @NotNull ClassDescriptor containingDeclaration,
043                @NotNull Annotations annotations,
044                boolean isPrimary,
045                @NotNull SourceElement source,
046                Kind kind
047        ) {
048            return new JavaConstructorDescriptor(containingDeclaration, null, annotations, isPrimary, kind, source);
049        }
050    
051        @Override
052        public boolean hasStableParameterNames() {
053            assert hasStableParameterNames != null : "hasStableParameterNames was not set: " + this;
054            return hasStableParameterNames;
055        }
056    
057        public void setHasStableParameterNames(boolean hasStableParameterNames) {
058            this.hasStableParameterNames = hasStableParameterNames;
059        }
060    
061        @Override
062        public boolean hasSynthesizedParameterNames() {
063            assert hasSynthesizedParameterNames != null : "hasSynthesizedParameterNames was not set: " + this;
064            return hasSynthesizedParameterNames;
065        }
066    
067        public void setHasSynthesizedParameterNames(boolean hasSynthesizedParameterNames) {
068            this.hasSynthesizedParameterNames = hasSynthesizedParameterNames;
069        }
070    
071        @NotNull
072        @Override
073        protected JavaConstructorDescriptor createSubstitutedCopy(
074                @NotNull DeclarationDescriptor newOwner,
075                @Nullable FunctionDescriptor original,
076                @NotNull Kind kind
077        ) {
078            if (kind != Kind.DECLARATION && kind != Kind.SYNTHESIZED) {
079                throw new IllegalStateException(
080                        "Attempt at creating a constructor that is not a declaration: \n" +
081                        "copy from: " + this + "\n" +
082                        "newOwner: " + newOwner + "\n" +
083                        "kind: " + kind
084                );
085            }
086            JavaConstructorDescriptor result = new JavaConstructorDescriptor(
087                    (ClassDescriptor) newOwner, this, getAnnotations(), isPrimary, kind, SourceElement.NO_SOURCE
088            );
089            result.setHasStableParameterNames(hasStableParameterNames());
090            result.setHasSynthesizedParameterNames(hasSynthesizedParameterNames());
091            return result;
092        }
093    }