001 /*
002 * Copyright 2010-2015 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.kotlin.codegen;
018
019 import com.intellij.util.ArrayUtil;
020 import org.jetbrains.annotations.NotNull;
021 import org.jetbrains.annotations.Nullable;
022 import org.jetbrains.kotlin.codegen.context.ClassContext;
023 import org.jetbrains.kotlin.codegen.state.GenerationState;
024 import org.jetbrains.kotlin.psi.JetClassOrObject;
025 import org.jetbrains.kotlin.resolve.DescriptorUtils;
026
027 import static org.jetbrains.kotlin.codegen.AsmUtil.writeKotlinSyntheticClassAnnotation;
028 import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass;
029 import static org.jetbrains.org.objectweb.asm.Opcodes.*;
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 ArrayUtil.EMPTY_STRING_ARRAY
051 );
052 v.visitSource(myClass.getContainingFile().getName(), null);
053 }
054
055 @Override
056 protected void generateKotlinAnnotation() {
057 writeKotlinSyntheticClassAnnotation(v, DescriptorUtils.isTopLevelOrInnerClass(descriptor)
058 ? KotlinSyntheticClass.Kind.TRAIT_IMPL
059 : KotlinSyntheticClass.Kind.LOCAL_TRAIT_IMPL);
060 }
061 }