DescriptorUtils: add getPackagesFqNames
This commit is contained in:
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.name.SpecialNames;
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter;
|
||||
import org.jetbrains.kotlin.resolve.scopes.FilteringScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.types.ErrorUtils;
|
||||
@@ -500,4 +501,28 @@ public class DescriptorUtils {
|
||||
public static boolean canHaveSecondaryConstructors(@NotNull ClassDescriptor classDescriptor) {
|
||||
return !isSingletonOrAnonymousObject(classDescriptor) && !isTrait(classDescriptor);
|
||||
}
|
||||
|
||||
public static Set<FqName> getPackagesFqNames(ModuleDescriptor module) {
|
||||
return getSubPackagesFqNames(module.getPackage(FqName.ROOT));
|
||||
}
|
||||
|
||||
public static Set<FqName> getSubPackagesFqNames(PackageViewDescriptor packageView) {
|
||||
Set<FqName> result = new HashSet<FqName>();
|
||||
getSubPackagesFqNames(packageView, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void getSubPackagesFqNames(PackageViewDescriptor packageView, Set<FqName> result) {
|
||||
FqName fqName = packageView.getFqName();
|
||||
if (!fqName.isRoot()) {
|
||||
result.add(fqName);
|
||||
}
|
||||
|
||||
for (DeclarationDescriptor descriptor : packageView.getMemberScope().getDescriptors(DescriptorKindFilter.PACKAGES, JetScope.ALL_NAME_FILTER)) {
|
||||
if (descriptor instanceof PackageViewDescriptor) {
|
||||
getSubPackagesFqNames((PackageViewDescriptor) descriptor, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user