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;
018    
019    import org.jetbrains.annotations.NotNull;
020    import org.jetbrains.annotations.Nullable;
021    import org.jetbrains.asm4.AnnotationVisitor;
022    import org.jetbrains.jet.codegen.context.ClassContext;
023    import org.jetbrains.jet.codegen.state.GenerationState;
024    import org.jetbrains.jet.lang.psi.JetClassOrObject;
025    import org.jetbrains.jet.lang.resolve.java.JvmAbi;
026    import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames;
027    
028    import static org.jetbrains.asm4.Opcodes.*;
029    import static org.jetbrains.jet.codegen.AsmUtil.asmDescByFqNameWithoutInnerClasses;
030    
031    public class TraitImplBodyCodegen extends ClassBodyCodegen {
032    
033        public TraitImplBodyCodegen(
034                @NotNull JetClassOrObject aClass,
035                @NotNull ClassContext context,
036                @NotNull ClassBuilder v,
037                @NotNull GenerationState state,
038                @Nullable MemberCodegen parentCodegen
039        ) {
040            super(aClass, context, v, state, parentCodegen);
041        }
042    
043        @Override
044        protected void generateDeclaration() {
045            v.defineClass(myClass, V1_6,
046                          ACC_PUBLIC | ACC_FINAL,
047                          typeMapper.mapTraitImpl(descriptor).getInternalName(),
048                          null,
049                          "java/lang/Object",
050                          new String[0]
051            );
052            v.visitSource(myClass.getContainingFile().getName(), null);
053        }
054    
055        @Override
056        protected void generateKotlinAnnotation() {
057            AnnotationVisitor av =
058                    v.getVisitor().visitAnnotation(asmDescByFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_TRAIT_IMPL), true);
059            av.visit(JvmAnnotationNames.ABI_VERSION_FIELD_NAME, JvmAbi.VERSION);
060            av.visitEnd();
061        }
062    }