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
017package org.jetbrains.jet.codegen.signature.kotlin;
018
019import org.jetbrains.annotations.NotNull;
020import org.jetbrains.asm4.AnnotationVisitor;
021import org.jetbrains.asm4.MethodVisitor;
022import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
023
024public class JetMethodAnnotationWriter {
025    private final AnnotationVisitor av;
026
027    private JetMethodAnnotationWriter(AnnotationVisitor av) {
028        this.av = av;
029    }
030
031    public void writeFlags(int flags) {
032        if (flags != JvmStdlibNames.FLAGS_DEFAULT_VALUE) {
033            av.visit(JvmStdlibNames.JET_FLAGS_FIELD, flags);
034        }
035    }
036
037    public void writeTypeParameters(@NotNull String typeParameters) {
038        if (typeParameters.length() > 0) {
039            av.visit(JvmStdlibNames.JET_METHOD_TYPE_PARAMETERS_FIELD, typeParameters);
040        }
041    }
042
043    public void writeReturnType(@NotNull String returnType) {
044        if (returnType.length() > 0) {
045            av.visit(JvmStdlibNames.JET_METHOD_RETURN_TYPE_FIELD, returnType);
046        }
047    }
048
049    public void writePropertyType(@NotNull String propertyType) {
050        if (propertyType.length() > 0) {
051            av.visit(JvmStdlibNames.JET_METHOD_PROPERTY_TYPE_FIELD, propertyType);
052        }
053    }
054
055    public void visitEnd() {
056        av.visitEnd();
057    }
058
059    public static JetMethodAnnotationWriter visitAnnotation(MethodVisitor mv) {
060        return new JetMethodAnnotationWriter(mv.visitAnnotation(JvmStdlibNames.JET_METHOD.getDescriptor(), true));
061    }
062}