Search in sources :

Example 21 with FqName

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

the class JavaClassFinderImpl method findClass.

@Nullable
@Override
public JavaClass findClass(@NotNull ClassId classId) {
    PsiClass psiClass = javaFacade.findClass(classId, javaSearchScope);
    if (psiClass == null)
        return null;
    JavaClassImpl javaClass = new JavaClassImpl(psiClass);
    FqName fqName = classId.asSingleFqName();
    if (!fqName.equals(javaClass.getFqName())) {
        throw new IllegalStateException("Requested " + fqName + ", got " + javaClass.getFqName());
    }
    if (psiClass instanceof KtLightClassMarker) {
        throw new IllegalStateException("Kotlin light classes should not be found by JavaPsiFacade, resolving: " + fqName);
    }
    return javaClass;
}
Also used : JavaClassImpl(org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl) KtLightClassMarker(org.jetbrains.kotlin.asJava.KtLightClassMarker) FqName(org.jetbrains.kotlin.name.FqName) PsiClass(com.intellij.psi.PsiClass) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with FqName

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

the class CodegenBinding method allFilesInPackages.

@NotNull
private static Collection<KtFile> allFilesInPackages(BindingContext bindingContext, Collection<KtFile> files) {
    // todo: we use Set and add given files but ignoring other scripts because something non-clear kept in binding
    // for scripts especially in case of REPL
    Set<FqName> names = new HashSet<FqName>();
    for (KtFile file : files) {
        if (!file.isScript()) {
            names.add(file.getPackageFqName());
        }
    }
    Set<KtFile> answer = new HashSet<KtFile>();
    answer.addAll(files);
    for (FqName name : names) {
        Collection<KtFile> jetFiles = bindingContext.get(PACKAGE_TO_FILES, name);
        if (jetFiles != null) {
            answer.addAll(jetFiles);
        }
    }
    List<KtFile> sortedAnswer = new ArrayList<KtFile>(answer);
    Collections.sort(sortedAnswer, new Comparator<KtFile>() {

        @NotNull
        private String path(KtFile file) {
            VirtualFile virtualFile = file.getVirtualFile();
            assert virtualFile != null : "VirtualFile is null for JetFile: " + file.getName();
            return virtualFile.getPath();
        }

        @Override
        public int compare(@NotNull KtFile first, @NotNull KtFile second) {
            return path(first).compareTo(path(second));
        }
    });
    return sortedAnswer;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FqName(org.jetbrains.kotlin.name.FqName) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 23 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 24 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 25 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)

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