Search in sources :

Example 1 with PackageContext

use of org.jetbrains.kotlin.codegen.context.PackageContext in project kotlin by JetBrains.

the class PackageCodegenImpl method generateFile.

private void generateFile(@NotNull KtFile file) {
    JvmFileClassInfo fileClassInfo = state.getFileClassesProvider().getFileClassInfo(file);
    if (fileClassInfo.getWithJvmMultifileClass()) {
        return;
    }
    Type fileClassType = AsmUtil.asmTypeByFqNameWithoutInnerClasses(fileClassInfo.getFileClassFqName());
    PackageContext packagePartContext = state.getRootContext().intoPackagePart(packageFragment, fileClassType, file);
    boolean generatePackagePart = false;
    List<KtClassOrObject> classOrObjects = new ArrayList<KtClassOrObject>();
    for (KtDeclaration declaration : file.getDeclarations()) {
        if (declaration.hasModifier(KtTokens.HEADER_KEYWORD))
            continue;
        if (declaration instanceof KtProperty || declaration instanceof KtNamedFunction || declaration instanceof KtTypeAlias) {
            generatePackagePart = true;
        } else if (declaration instanceof KtClassOrObject) {
            KtClassOrObject classOrObject = (KtClassOrObject) declaration;
            if (state.getGenerateDeclaredClassFilter().shouldGenerateClass(classOrObject)) {
                classOrObjects.add(classOrObject);
            }
        } else if (declaration instanceof KtScript) {
            KtScript script = (KtScript) declaration;
            if (state.getGenerateDeclaredClassFilter().shouldGenerateScript(script)) {
                ScriptCodegen.createScriptCodegen(script, state, packagePartContext).generate();
            }
        }
    }
    generateClassesAndObjectsInFile(classOrObjects, packagePartContext);
    if (!generatePackagePart || !state.getGenerateDeclaredClassFilter().shouldGeneratePackagePart(file))
        return;
    String name = fileClassType.getInternalName();
    packagePartRegistry.addPart(StringsKt.substringAfterLast(name, '/', name), null);
    ClassBuilder builder = state.getFactory().newVisitor(JvmDeclarationOriginKt.PackagePart(file, packageFragment), fileClassType, file);
    new PackagePartCodegen(builder, file, fileClassType, packagePartContext, state).generate();
}
Also used : PackageContext(org.jetbrains.kotlin.codegen.context.PackageContext) ArrayList(java.util.ArrayList) Type(org.jetbrains.org.objectweb.asm.Type) JvmFileClassInfo(org.jetbrains.kotlin.fileClasses.JvmFileClassInfo)

Aggregations

ArrayList (java.util.ArrayList)1 PackageContext (org.jetbrains.kotlin.codegen.context.PackageContext)1 JvmFileClassInfo (org.jetbrains.kotlin.fileClasses.JvmFileClassInfo)1 Type (org.jetbrains.org.objectweb.asm.Type)1