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.codegen.signature.kotlin;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.asm4.AnnotationVisitor;
021    import org.jetbrains.asm4.MethodVisitor;
022    import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
023    
024    public class JetValueParameterAnnotationWriter {
025        private final AnnotationVisitor av;
026    
027        private JetValueParameterAnnotationWriter(AnnotationVisitor av) {
028            this.av = av;
029        }
030    
031        public void writeName(@NotNull String name) {
032            if (name.length() > 0) {
033                av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_NAME_FIELD, name);
034            }
035        }
036    
037        public static JetValueParameterAnnotationWriter visitParameterAnnotation(MethodVisitor mv, int n) {
038            return new JetValueParameterAnnotationWriter(
039                    mv.visitParameterAnnotation(n, JvmStdlibNames.JET_VALUE_PARAMETER.getDescriptor(), true));
040        }
041    
042        public void writeReceiver() {
043            av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_RECEIVER_FIELD, true);
044        }
045    
046        public void writeType(@NotNull String kotlinSignature) {
047            if (kotlinSignature.length() > 0) {
048                av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_TYPE_FIELD, kotlinSignature);
049            }
050        }
051    
052        public void visitEnd() {
053            av.visitEnd();
054        }
055    
056        public void writeHasDefaultValue(boolean hasDefaultValue) {
057            if (hasDefaultValue) {
058                av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_HAS_DEFAULT_VALUE_FIELD, true);
059            }
060        }
061    
062        public void writeVararg(boolean vararg) {
063            if (vararg) {
064                av.visit(JvmStdlibNames.JET_VALUE_PARAMETER_VARARG, true);
065            }
066        }
067    }