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.resolve.java.descriptor;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.annotations.Nullable;
021    import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
022    import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
023    import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
024    import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
025    import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorImpl;
026    import org.jetbrains.jet.lang.descriptors.impl.SimpleFunctionDescriptorImpl;
027    import org.jetbrains.jet.lang.resolve.name.Name;
028    
029    public class JavaMethodDescriptor extends SimpleFunctionDescriptorImpl implements JavaCallableMemberDescriptor {
030        private Boolean hasStableParameterNames = null;
031        private Boolean hasSynthesizedParameterNames = null;
032    
033        private JavaMethodDescriptor(
034                @NotNull DeclarationDescriptor containingDeclaration,
035                @Nullable SimpleFunctionDescriptor original,
036                @NotNull Annotations annotations,
037                @NotNull Name name,
038                @NotNull Kind kind
039        ) {
040            super(containingDeclaration, original, annotations, name, kind);
041        }
042    
043        @NotNull
044        public static JavaMethodDescriptor createJavaMethod(
045                @NotNull DeclarationDescriptor containingDeclaration,
046                @NotNull Annotations annotations,
047                @NotNull Name name
048        ) {
049            return new JavaMethodDescriptor(containingDeclaration, null, annotations, name, Kind.DECLARATION);
050        }
051    
052        @Override
053        public boolean hasStableParameterNames() {
054            assert hasStableParameterNames != null : "hasStableParameterNames was not set: " + this;
055            return hasStableParameterNames;
056        }
057    
058        public void setHasStableParameterNames(boolean hasStableParameterNames) {
059            this.hasStableParameterNames = hasStableParameterNames;
060        }
061    
062        @Override
063        public boolean hasSynthesizedParameterNames() {
064            assert hasSynthesizedParameterNames != null : "hasSynthesizedParameterNames was not set: " + this;
065            return hasSynthesizedParameterNames;
066        }
067    
068        public void setHasSynthesizedParameterNames(boolean hasSynthesizedParameterNames) {
069            this.hasSynthesizedParameterNames = hasSynthesizedParameterNames;
070        }
071    
072        @NotNull
073        @Override
074        protected FunctionDescriptorImpl createSubstitutedCopy(
075                @NotNull DeclarationDescriptor newOwner,
076                @Nullable FunctionDescriptor original,
077                @NotNull Kind kind
078        ) {
079            JavaMethodDescriptor result = new JavaMethodDescriptor(
080                    newOwner,
081                    (SimpleFunctionDescriptor) original,
082                    getAnnotations(),
083                    getName(),
084                    kind
085            );
086            result.setHasStableParameterNames(hasStableParameterNames());
087            result.setHasSynthesizedParameterNames(hasSynthesizedParameterNames());
088            return result;
089        }
090    }