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