Search in sources :

Example 11 with FqName

use of org.jetbrains.kotlin.name.FqName in project kotlin by JetBrains.

the class JavaAnnotationImpl method computeClassId.

@Nullable
private static ClassId computeClassId(@NotNull PsiClass psiClass) {
    PsiClass container = psiClass.getContainingClass();
    if (container != null) {
        ClassId parentClassId = computeClassId(container);
        String name = psiClass.getName();
        return parentClassId == null || name == null ? null : parentClassId.createNestedClassId(Name.identifier(name));
    }
    String fqName = psiClass.getQualifiedName();
    return fqName == null ? null : ClassId.topLevel(new FqName(fqName));
}
Also used : FqName(org.jetbrains.kotlin.name.FqName) PsiClass(com.intellij.psi.PsiClass) ClassId(org.jetbrains.kotlin.name.ClassId) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with FqName

use of org.jetbrains.kotlin.name.FqName in project kotlin by JetBrains.

the class JavaAnnotationImpl method getClassId.

@Override
@Nullable
public ClassId getClassId() {
    PsiClass resolved = resolvePsi();
    if (resolved != null)
        return computeClassId(resolved);
    // External annotations do not have PSI behind them,
    // so we can only heuristically reconstruct annotation class ids from qualified names
    String qualifiedName = getPsi().getQualifiedName();
    if (qualifiedName != null)
        return ClassId.topLevel(new FqName(qualifiedName));
    return null;
}
Also used : FqName(org.jetbrains.kotlin.name.FqName) PsiClass(com.intellij.psi.PsiClass) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with FqName

use of org.jetbrains.kotlin.name.FqName in project kotlin by JetBrains.

the class FileBasedKotlinClass method resolveNameByInternalName.

@NotNull
private static ClassId resolveNameByInternalName(@NotNull String name, @NotNull InnerClassesInfo innerClasses) {
    if (!name.contains("$")) {
        return ClassId.topLevel(new FqName(name.replace('/', '.')));
    }
    List<String> classes = new ArrayList<String>(1);
    boolean local = false;
    while (true) {
        OuterAndInnerName outer = innerClasses.get(name);
        if (outer == null)
            break;
        if (outer.outerInternalName == null) {
            local = true;
            break;
        }
        classes.add(outer.innerSimpleName);
        name = outer.outerInternalName;
    }
    FqName outermostClassFqName = new FqName(name.replace('/', '.'));
    classes.add(outermostClassFqName.shortName().asString());
    Collections.reverse(classes);
    FqName packageFqName = outermostClassFqName.parent();
    FqName relativeClassName = FqName.fromSegments(classes);
    return new ClassId(packageFqName, relativeClassName, local);
}
Also used : FqName(org.jetbrains.kotlin.name.FqName) ClassId(org.jetbrains.kotlin.name.ClassId) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with FqName

use of org.jetbrains.kotlin.name.FqName 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 15 with FqName

use of org.jetbrains.kotlin.name.FqName in project kotlin by JetBrains.

the class ImplementationBodyCodegen method signature.

@NotNull
public static JvmClassSignature signature(@NotNull ClassDescriptor descriptor, @NotNull Type classAsmType, @NotNull SuperClassInfo superClassInfo, @NotNull KotlinTypeMapper typeMapper) {
    JvmSignatureWriter sw = new BothSignatureWriter(BothSignatureWriter.Mode.CLASS);
    typeMapper.writeFormalTypeParameters(descriptor.getDeclaredTypeParameters(), sw);
    sw.writeSuperclass();
    if (superClassInfo.getKotlinType() == null) {
        sw.writeClassBegin(superClassInfo.getType());
        sw.writeClassEnd();
    } else {
        typeMapper.mapSupertype(superClassInfo.getKotlinType(), sw);
    }
    sw.writeSuperclassEnd();
    LinkedHashSet<String> superInterfaces = new LinkedHashSet<String>();
    Set<String> kotlinMarkerInterfaces = new LinkedHashSet<String>();
    for (KotlinType supertype : descriptor.getTypeConstructor().getSupertypes()) {
        if (isJvmInterface(supertype.getConstructor().getDeclarationDescriptor())) {
            sw.writeInterface();
            Type jvmInterfaceType = typeMapper.mapSupertype(supertype, sw);
            sw.writeInterfaceEnd();
            String jvmInterfaceInternalName = jvmInterfaceType.getInternalName();
            superInterfaces.add(jvmInterfaceInternalName);
            FqName kotlinInterfaceName = DescriptorUtils.getFqName(supertype.getConstructor().getDeclarationDescriptor()).toSafe();
            String kotlinMarkerInterfaceInternalName = KOTLIN_MARKER_INTERFACES.get(kotlinInterfaceName);
            if (kotlinMarkerInterfaceInternalName != null) {
                kotlinMarkerInterfaces.add(kotlinMarkerInterfaceInternalName);
            }
        }
    }
    for (String kotlinMarkerInterface : kotlinMarkerInterfaces) {
        sw.writeInterface();
        sw.writeAsmType(getObjectType(kotlinMarkerInterface));
        sw.writeInterfaceEnd();
    }
    superInterfaces.addAll(kotlinMarkerInterfaces);
    return new JvmClassSignature(classAsmType.getInternalName(), superClassInfo.getType().getInternalName(), new ArrayList<String>(superInterfaces), sw.makeJavaGenericSignature());
}
Also used : Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType) Type.getObjectType(org.jetbrains.org.objectweb.asm.Type.getObjectType) JvmSignatureWriter(org.jetbrains.kotlin.codegen.signature.JvmSignatureWriter) BothSignatureWriter(org.jetbrains.kotlin.codegen.signature.BothSignatureWriter) FqName(org.jetbrains.kotlin.name.FqName) KotlinType(org.jetbrains.kotlin.types.KotlinType) JvmClassSignature(org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmClassSignature) NotNull(org.jetbrains.annotations.NotNull) BindingContextUtils.getNotNull(org.jetbrains.kotlin.resolve.BindingContextUtils.getNotNull)

Aggregations

FqName (org.jetbrains.kotlin.name.FqName)74 NotNull (org.jetbrains.annotations.NotNull)25 Nullable (org.jetbrains.annotations.Nullable)15 KtFile (org.jetbrains.kotlin.psi.KtFile)10 StringRef (com.intellij.util.io.StringRef)6 File (java.io.File)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)4 ModuleDescriptor (org.jetbrains.kotlin.descriptors.ModuleDescriptor)4 Name (org.jetbrains.kotlin.name.Name)4 PsiClass (com.intellij.psi.PsiClass)3 ClassId (org.jetbrains.kotlin.name.ClassId)3 Disposable (com.intellij.openapi.Disposable)2 ConfigurationException (com.intellij.openapi.options.ConfigurationException)2 SmartList (com.intellij.util.SmartList)2 Function1 (kotlin.jvm.functions.Function1)2 KotlinCoreEnvironment (org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment)2 CompilerConfiguration (org.jetbrains.kotlin.config.CompilerConfiguration)2 JavaClassDescriptor (org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor)2 KtClassOrObject (org.jetbrains.kotlin.psi.KtClassOrObject)2