private static Collection<ClassDescriptor> getClassOrObjectDescriptorsByFqName( NamespaceDescriptor packageDescriptor, FqName path, boolean includeObjectDeclarations) { if (path.isRoot()) { return Collections.emptyList(); } Collection<JetScope> scopes = Arrays.asList(packageDescriptor.getMemberScope()); List<Name> names = path.pathSegments(); if (names.size() > 1) { for (Name subName : path.pathSegments().subList(0, names.size() - 1)) { Collection<JetScope> tempScopes = Lists.newArrayList(); for (JetScope scope : scopes) { ClassifierDescriptor classifier = scope.getClassifier(subName); if (classifier instanceof ClassDescriptorBase) { ClassDescriptorBase classDescriptor = (ClassDescriptorBase) classifier; tempScopes.add(classDescriptor.getUnsubstitutedInnerClassesScope()); } } scopes = tempScopes; } } Name shortName = path.shortName(); Collection<ClassDescriptor> resultClassifierDescriptors = Lists.newArrayList(); for (JetScope scope : scopes) { ClassifierDescriptor classifier = scope.getClassifier(shortName); if (classifier instanceof ClassDescriptor) { resultClassifierDescriptors.add((ClassDescriptor) classifier); } if (includeObjectDeclarations) { ClassDescriptor objectDescriptor = scope.getObjectDescriptor(shortName); if (objectDescriptor != null) { resultClassifierDescriptors.add(objectDescriptor); } } } return resultClassifierDescriptors; }
@Nullable public static ClassDescriptor getKotlinBuiltinClassDescriptor(@NotNull FqName qualifiedName) { if (!qualifiedName.firstSegmentIs(KotlinBuiltIns.BUILT_INS_PACKAGE_NAME)) return null; List<Name> segments = qualifiedName.pathSegments(); if (segments.size() < 2) return null; JetScope scope = KotlinBuiltIns.getInstance().getBuiltInsPackageScope(); for (int i = 1, size = segments.size(); i < size; i++) { ClassifierDescriptor classifier = scope.getClassifier(segments.get(i)); if (classifier == null) return null; assert classifier instanceof ClassDescriptor : "Unexpected classifier in built-ins: " + classifier; scope = ((ClassDescriptor) classifier).getUnsubstitutedInnerClassesScope(); } return (ClassDescriptor) scope.getContainingDeclaration(); }