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