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.jet.codegen.context.ClassContext; 022 import org.jetbrains.jet.codegen.state.GenerationState; 023 import org.jetbrains.jet.lang.psi.JetClassOrObject; 024 import org.jetbrains.jet.lang.resolve.DescriptorUtils; 025 026 import static org.jetbrains.asm4.Opcodes.*; 027 import static org.jetbrains.jet.codegen.AsmUtil.writeKotlinSyntheticClassAnnotation; 028 import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.KotlinSyntheticClass; 029 030 public class TraitImplBodyCodegen extends ClassBodyCodegen { 031 032 public TraitImplBodyCodegen( 033 @NotNull JetClassOrObject aClass, 034 @NotNull ClassContext context, 035 @NotNull ClassBuilder v, 036 @NotNull GenerationState state, 037 @Nullable MemberCodegen parentCodegen 038 ) { 039 super(aClass, context, v, state, parentCodegen); 040 } 041 042 @Override 043 protected void generateDeclaration() { 044 v.defineClass(myClass, V1_6, 045 ACC_PUBLIC | ACC_FINAL, 046 typeMapper.mapTraitImpl(descriptor).getInternalName(), 047 null, 048 "java/lang/Object", 049 new String[0] 050 ); 051 v.visitSource(myClass.getContainingFile().getName(), null); 052 } 053 054 @Override 055 protected void generateKotlinAnnotation() { 056 // We write LOCAL_CLASS to local trait-impl, because we don't want PSI classes to be constructed for such files 057 // (currently PSI for synthetic class is built only if this class is a trait-impl, see DecompiledUtils.kt) 058 writeKotlinSyntheticClassAnnotation(v, DescriptorUtils.isTopLevelOrInnerClass(descriptor) 059 ? KotlinSyntheticClass.Kind.TRAIT_IMPL 060 : KotlinSyntheticClass.Kind.LOCAL_CLASS); 061 } 062 }