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