Search in sources :

Example 1 with JvmFileClassInfo

use of org.jetbrains.kotlin.fileClasses.JvmFileClassInfo in project kotlin by JetBrains.

the class IdeStubIndexService method createFileStub.

@NotNull
@Override
public KotlinFileStub createFileStub(@NotNull KtFile file) {
    StringRef packageFqName = StringRef.fromString(file.getPackageFqNameByTree().asString());
    boolean isScript = file.isScriptByTree();
    if (PackagePartClassUtils.fileHasTopLevelCallables(file)) {
        JvmFileClassInfo fileClassInfo = JvmFileClassUtil.getFileClassInfoNoResolve(file);
        StringRef facadeSimpleName = StringRef.fromString(fileClassInfo.getFacadeClassFqName().shortName().asString());
        StringRef partSimpleName = StringRef.fromString(fileClassInfo.getFileClassFqName().shortName().asString());
        return new KotlinFileStubForIde(file, packageFqName, isScript, facadeSimpleName, partSimpleName, null);
    }
    return new KotlinFileStubForIde(file, packageFqName, isScript, null, null, null);
}
Also used : JvmFileClassInfo(org.jetbrains.kotlin.fileClasses.JvmFileClassInfo) StringRef(com.intellij.util.io.StringRef) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JvmFileClassInfo

use of org.jetbrains.kotlin.fileClasses.JvmFileClassInfo in project kotlin by JetBrains.

the class KotlinCodegenFacade method doGenerateFiles.

public static void doGenerateFiles(@NotNull Collection<KtFile> files, @NotNull GenerationState state, @NotNull CompilationErrorHandler errorHandler) {
    MultiMap<FqName, KtFile> filesInPackages = new MultiMap<FqName, KtFile>();
    MultiMap<FqName, KtFile> filesInMultifileClasses = new MultiMap<FqName, KtFile>();
    for (KtFile file : files) {
        if (file == null)
            throw new IllegalArgumentException("A null file given for compilation");
        JvmFileClassInfo fileClassInfo = state.getFileClassesProvider().getFileClassInfo(file);
        if (fileClassInfo.getWithJvmMultifileClass()) {
            filesInMultifileClasses.putValue(fileClassInfo.getFacadeClassFqName(), file);
        } else {
            filesInPackages.putValue(file.getPackageFqName(), file);
        }
    }
    Set<FqName> obsoleteMultifileClasses = new HashSet<FqName>(state.getObsoleteMultifileClasses());
    for (FqName multifileClassFqName : Sets.union(filesInMultifileClasses.keySet(), obsoleteMultifileClasses)) {
        doCheckCancelled(state);
        generateMultifileClass(state, multifileClassFqName, filesInMultifileClasses.get(multifileClassFqName), errorHandler);
    }
    Set<FqName> packagesWithObsoleteParts = new HashSet<FqName>(state.getPackagesWithObsoleteParts());
    for (FqName packageFqName : Sets.union(packagesWithObsoleteParts, filesInPackages.keySet())) {
        doCheckCancelled(state);
        generatePackage(state, packageFqName, filesInPackages.get(packageFqName), errorHandler);
    }
    doCheckCancelled(state);
    state.getFactory().done();
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) JvmFileClassInfo(org.jetbrains.kotlin.fileClasses.JvmFileClassInfo) FqName(org.jetbrains.kotlin.name.FqName) KtFile(org.jetbrains.kotlin.psi.KtFile) HashSet(java.util.HashSet)

Example 3 with JvmFileClassInfo

use of org.jetbrains.kotlin.fileClasses.JvmFileClassInfo 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)

Example 4 with JvmFileClassInfo

use of org.jetbrains.kotlin.fileClasses.JvmFileClassInfo in project kotlin by JetBrains.

the class KotlinTypeMapper method getPartSimpleNameForMangling.

@Nullable
private String getPartSimpleNameForMangling(@NotNull CallableMemberDescriptor descriptor) {
    KtFile containingFile = DescriptorToSourceUtils.getContainingFile(descriptor);
    if (containingFile != null) {
        JvmFileClassInfo fileClassInfo = JvmFileClassUtil.getFileClassInfoNoResolve(containingFile);
        if (fileClassInfo.getWithJvmMultifileClass()) {
            return fileClassInfo.getFileClassFqName().shortName().asString();
        }
        return null;
    }
    descriptor = DescriptorUtils.getDirectMember(descriptor);
    assert descriptor instanceof DeserializedCallableMemberDescriptor : "Descriptor without sources should be instance of DeserializedCallableMemberDescriptor, but: " + descriptor;
    ContainingClassesInfo containingClassesInfo = getContainingClassesForDeserializedCallable((DeserializedCallableMemberDescriptor) descriptor);
    String facadeShortName = containingClassesInfo.getFacadeClassId().getShortClassName().asString();
    String implShortName = containingClassesInfo.getImplClassId().getShortClassName().asString();
    return !facadeShortName.equals(implShortName) ? implShortName : null;
}
Also used : JvmFileClassInfo(org.jetbrains.kotlin.fileClasses.JvmFileClassInfo) DeserializedCallableMemberDescriptor(org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor) KtFile(org.jetbrains.kotlin.psi.KtFile) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JvmFileClassInfo (org.jetbrains.kotlin.fileClasses.JvmFileClassInfo)4 KtFile (org.jetbrains.kotlin.psi.KtFile)2 MultiMap (com.intellij.util.containers.MultiMap)1 StringRef (com.intellij.util.io.StringRef)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1 PackageContext (org.jetbrains.kotlin.codegen.context.PackageContext)1 FqName (org.jetbrains.kotlin.name.FqName)1 DeserializedCallableMemberDescriptor (org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor)1 Type (org.jetbrains.org.objectweb.asm.Type)1