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;
}
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;
}
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));
}
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;
}
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);
}
Aggregations