use of org.jetbrains.kotlin.descriptors.PackageViewDescriptor in project kotlin by JetBrains.
the class ResolveSessionUtils method getClassOrObjectDescriptorsByFqName.
@NotNull
public static Collection<ClassDescriptor> getClassOrObjectDescriptorsByFqName(@NotNull ModuleDescriptor module, @NotNull FqName fqName, @NotNull Predicate<ClassDescriptor> filter) {
if (fqName.isRoot())
return Collections.emptyList();
Collection<ClassDescriptor> result = new ArrayList<ClassDescriptor>(1);
FqName packageFqName = fqName.parent();
while (true) {
PackageViewDescriptor packageDescriptor = module.getPackage(packageFqName);
if (!packageDescriptor.isEmpty()) {
FqName relativeClassFqName = FqNamesUtilKt.tail(fqName, packageFqName);
ClassDescriptor classDescriptor = findClassByRelativePath(packageDescriptor.getMemberScope(), relativeClassFqName);
if (classDescriptor != null && filter.apply(classDescriptor)) {
result.add(classDescriptor);
}
}
if (packageFqName.isRoot()) {
break;
}
packageFqName = packageFqName.parent();
}
return result;
}
use of org.jetbrains.kotlin.descriptors.PackageViewDescriptor in project kotlin by JetBrains.
the class CompileKotlinAgainstCustomBinariesTest method doTestWithTxt.
private void doTestWithTxt(@NotNull File... extraClassPath) throws Exception {
PackageViewDescriptor packageView = analyzeFileToPackageView(extraClassPath);
RecursiveDescriptorComparator.Configuration comparator = AbstractLoadJavaTest.COMPARATOR_CONFIGURATION.withValidationStrategy(DescriptorValidator.ValidationVisitor.errorTypesAllowed());
validateAndCompareDescriptorWithFile(packageView, comparator, getTestDataFileWithExtension("txt"));
}
use of org.jetbrains.kotlin.descriptors.PackageViewDescriptor in project kotlin by JetBrains.
the class CompileKotlinAgainstCustomBinariesTest method analyzeFileToPackageView.
@NotNull
private PackageViewDescriptor analyzeFileToPackageView(@NotNull File... extraClassPath) throws IOException {
KotlinCoreEnvironment environment = createEnvironment(Arrays.asList(extraClassPath));
AnalysisResult result = JvmResolveUtil.analyzeAndCheckForErrors(KotlinTestUtils.loadJetFile(environment.getProject(), getTestDataFileWithExtension("kt")), environment);
PackageViewDescriptor packageView = result.getModuleDescriptor().getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME);
assertFalse("Failed to find package: " + LoadDescriptorUtil.TEST_PACKAGE_FQNAME, packageView.isEmpty());
return packageView;
}
use of org.jetbrains.kotlin.descriptors.PackageViewDescriptor in project kotlin by JetBrains.
the class AbstractCompileJavaAgainstKotlinTest method doTest.
protected void doTest(String ktFilePath) throws IOException {
Assert.assertTrue(ktFilePath.endsWith(".kt"));
File ktFile = new File(ktFilePath);
File javaFile = new File(ktFilePath.replaceFirst("\\.kt$", ".java"));
File expectedFile = new File(ktFilePath.replaceFirst("\\.kt$", ".txt"));
File javaErrorFile = new File(ktFilePath.replaceFirst("\\.kt$", ".javaerr.txt"));
File out = new File(tmpdir, "out");
compileKotlinWithJava(Collections.singletonList(javaFile), Collections.singletonList(ktFile), out, getTestRootDisposable(), javaErrorFile);
KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(getTestRootDisposable(), newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, getAnnotationsJar(), out), EnvironmentConfigFiles.JVM_CONFIG_FILES);
AnalysisResult analysisResult = JvmResolveUtil.analyze(environment);
PackageViewDescriptor packageView = analysisResult.getModuleDescriptor().getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME);
assertFalse("Nothing found in package " + LoadDescriptorUtil.TEST_PACKAGE_FQNAME, packageView.isEmpty());
validateAndCompareDescriptorWithFile(packageView, CONFIGURATION, expectedFile);
}
use of org.jetbrains.kotlin.descriptors.PackageViewDescriptor in project kotlin by JetBrains.
the class LoadDescriptorUtil method loadTestPackageAndBindingContextFromJavaRoot.
@NotNull
public static Pair<PackageViewDescriptor, BindingContext> loadTestPackageAndBindingContextFromJavaRoot(@NotNull File javaRoot, @NotNull Disposable disposable, @NotNull TestJdkKind testJdkKind, @NotNull ConfigurationKind configurationKind, boolean isBinaryRoot) {
List<File> javaBinaryRoots = new ArrayList<File>();
javaBinaryRoots.add(KotlinTestUtils.getAnnotationsJar());
List<File> javaSourceRoots = new ArrayList<File>();
javaSourceRoots.add(new File("compiler/testData/loadJava/include"));
if (isBinaryRoot) {
javaBinaryRoots.add(javaRoot);
} else {
javaSourceRoots.add(javaRoot);
}
CompilerConfiguration configuration = KotlinTestUtils.newConfiguration(configurationKind, testJdkKind, javaBinaryRoots, javaSourceRoots);
KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForTests(disposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
AnalysisResult analysisResult = JvmResolveUtil.analyze(environment);
PackageViewDescriptor packageView = analysisResult.getModuleDescriptor().getPackage(TEST_PACKAGE_FQNAME);
return Pair.create(packageView, analysisResult.getBindingContext());
}
Aggregations