use of org.jetbrains.kotlin.descriptors.ModuleDescriptor in project kotlin by JetBrains.
the class TypeSubstitutorTest method getContextScope.
private LexicalScope getContextScope() throws IOException {
// todo comments
String text = FileUtil.loadFile(new File("compiler/testData/type-substitutor.kt"), true);
KtFile ktFile = KtPsiFactoryKt.KtPsiFactory(getProject()).createFile(text);
AnalysisResult analysisResult = JvmResolveUtil.analyze(ktFile, getEnvironment());
ModuleDescriptor module = analysisResult.getModuleDescriptor();
LexicalScope topLevelScope = analysisResult.getBindingContext().get(BindingContext.LEXICAL_SCOPE, ktFile);
final ClassifierDescriptor contextClass = ScopeUtilsKt.findClassifier(topLevelScope, Name.identifier("___Context"), NoLookupLocation.FROM_TEST);
assert contextClass instanceof ClassDescriptor;
LocalRedeclarationChecker redeclarationChecker = new ThrowingLocalRedeclarationChecker(new OverloadChecker(TypeSpecificityComparator.NONE.INSTANCE));
LexicalScope typeParameters = new LexicalScopeImpl(topLevelScope, module, false, null, LexicalScopeKind.SYNTHETIC, redeclarationChecker, new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
@Override
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
for (TypeParameterDescriptor parameterDescriptor : contextClass.getTypeConstructor().getParameters()) {
handler.addClassifierDescriptor(parameterDescriptor);
}
return Unit.INSTANCE;
}
});
return new LexicalChainedScope(typeParameters, module, false, null, LexicalScopeKind.SYNTHETIC, Arrays.asList(contextClass.getDefaultType().getMemberScope(), module.getBuiltIns().getBuiltInsPackageScope()));
}
use of org.jetbrains.kotlin.descriptors.ModuleDescriptor in project kotlin by JetBrains.
the class ResolveDescriptorsFromExternalLibraries method parseLibraryFileChunk.
private static boolean parseLibraryFileChunk(File jar, String libDescription, ZipInputStream zip, int classesPerChunk) throws IOException {
Disposable junk = new Disposable() {
@Override
public void dispose() {
}
};
KotlinCoreEnvironment environment;
if (jar != null) {
environment = KotlinCoreEnvironment.createForTests(junk, KotlinTestUtils.newConfiguration(ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, KotlinTestUtils.getAnnotationsJar(), jar), EnvironmentConfigFiles.JVM_CONFIG_FILES);
} else {
CompilerConfiguration configuration = KotlinTestUtils.newConfiguration(ConfigurationKind.JDK_ONLY, TestJdkKind.FULL_JDK);
environment = KotlinCoreEnvironment.createForTests(junk, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
if (!findRtJar().equals(jar)) {
throw new RuntimeException("rt.jar mismatch: " + jar + ", " + findRtJar());
}
}
ModuleDescriptor module = JvmResolveUtil.analyze(environment).getModuleDescriptor();
boolean hasErrors;
try {
hasErrors = false;
for (int count = 0; count < classesPerChunk; ) {
ZipEntry entry = zip.getNextEntry();
if (entry == null) {
break;
}
if (count == 0) {
System.err.println("chunk from " + entry.getName());
}
System.err.println(entry.getName());
String entryName = entry.getName();
if (!entryName.endsWith(".class")) {
continue;
}
if (entryName.matches("(.*/|)package-info\\.class")) {
continue;
}
if (entryName.contains("$")) {
continue;
}
String className = entryName.substring(0, entryName.length() - ".class".length()).replace("/", ".");
try {
ClassDescriptor clazz = DescriptorUtilsKt.resolveTopLevelClass(module, new FqName(className), NoLookupLocation.FROM_TEST);
if (clazz == null) {
throw new IllegalStateException("class not found by name " + className + " in " + libDescription);
}
DescriptorUtils.getAllDescriptors(clazz.getDefaultType().getMemberScope());
} catch (Exception e) {
System.err.println("failed to resolve " + className);
e.printStackTrace();
//throw new RuntimeException("failed to resolve " + className + ": " + e, e);
hasErrors = true;
}
++count;
}
} finally {
Disposer.dispose(junk);
}
return hasErrors;
}
use of org.jetbrains.kotlin.descriptors.ModuleDescriptor in project kotlin by JetBrains.
the class AbstractResolveByStubTest method performTest.
private void performTest(@NotNull String path, boolean checkPrimaryConstructors, boolean checkPropertyAccessors) {
KtFile file = (KtFile) getFile();
ModuleDescriptor module = ResolutionUtils.findModuleDescriptor(file);
PackageViewDescriptor packageViewDescriptor = module.getPackage(new FqName("test"));
Assert.assertFalse(packageViewDescriptor.isEmpty());
File fileToCompareTo = new File(FileUtil.getNameWithoutExtension(path) + ".txt");
RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(packageViewDescriptor, RecursiveDescriptorComparator.DONT_INCLUDE_METHODS_OF_OBJECT.filterRecursion(RecursiveDescriptorComparator.SKIP_BUILT_INS_PACKAGES).checkPrimaryConstructors(checkPrimaryConstructors).checkPropertyAccessors(checkPropertyAccessors).withValidationStrategy(errorTypesForbidden()), fileToCompareTo);
}
use of org.jetbrains.kotlin.descriptors.ModuleDescriptor in project kotlin by JetBrains.
the class K2JSTranslator method translate.
@NotNull
public TranslationResult translate(@NotNull List<KtFile> files, @NotNull MainCallParameters mainCallParameters, @Nullable JsAnalysisResult analysisResult) throws TranslationException {
if (analysisResult == null) {
analysisResult = TopDownAnalyzerFacadeForJS.analyzeFiles(files, config);
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
}
BindingTrace bindingTrace = analysisResult.getBindingTrace();
TopDownAnalyzerFacadeForJS.checkForErrors(files, bindingTrace.getBindingContext());
ModuleDescriptor moduleDescriptor = analysisResult.getModuleDescriptor();
Diagnostics diagnostics = bindingTrace.getBindingContext().getDiagnostics();
TranslationContext context = Translation.generateAst(bindingTrace, files, mainCallParameters, moduleDescriptor, config);
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
if (hasError(diagnostics))
return new TranslationResult.Fail(diagnostics);
JsProgram program = JsInliner.process(context);
ResolveTemporaryNamesKt.resolveTemporaryNames(program);
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
if (hasError(diagnostics))
return new TranslationResult.Fail(diagnostics);
CoroutineTransformer coroutineTransformer = new CoroutineTransformer(program);
coroutineTransformer.accept(program);
RemoveUnusedImportsKt.removeUnusedImports(program);
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
if (hasError(diagnostics))
return new TranslationResult.Fail(diagnostics);
expandIsCalls(program, context);
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
List<String> importedModules = new ArrayList<String>();
for (StaticContext.ImportedModule module : context.getImportedModules()) {
importedModules.add(module.getExternalName());
}
return new TranslationResult.Success(config, files, program, diagnostics, importedModules, moduleDescriptor, bindingTrace.getBindingContext());
}
use of org.jetbrains.kotlin.descriptors.ModuleDescriptor in project kotlin by JetBrains.
the class LoadBuiltinsTest method testBuiltIns.
public void testBuiltIns() throws Exception {
RecursiveDescriptorComparator.Configuration configuration = RecursiveDescriptorComparator.RECURSIVE_ALL.includeMethodsOfKotlinAny(false).withRenderer(DescriptorRenderer.Companion.withOptions(new Function1<DescriptorRendererOptions, Unit>() {
@Override
public Unit invoke(DescriptorRendererOptions options) {
options.setWithDefinedIn(false);
options.setOverrideRenderingPolicy(OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE);
options.setVerbose(true);
options.setAnnotationArgumentsRenderingPolicy(AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY);
options.setModifiers(DescriptorRendererModifier.ALL);
return Unit.INSTANCE;
}
}));
PackageFragmentProvider packageFragmentProvider = createBuiltInsPackageFragmentProvider();
List<KtFile> files = KotlinTestUtils.loadToJetFiles(getEnvironment(), ContainerUtil.concat(allFilesUnder("core/builtins/native"), allFilesUnder("core/builtins/src")));
ModuleDescriptor module = LazyResolveTestUtilsKt.createResolveSessionForFiles(getEnvironment().getProject(), files, false).getModuleDescriptor();
for (FqName packageFqName : CollectionsKt.listOf(BUILT_INS_PACKAGE_FQ_NAME, COLLECTIONS_PACKAGE_FQ_NAME, RANGES_PACKAGE_FQ_NAME)) {
PackageFragmentDescriptor fromLazyResolve = CollectionsKt.single(module.getPackage(packageFqName).getFragments());
if (fromLazyResolve instanceof LazyPackageDescriptor) {
PackageFragmentDescriptor deserialized = CollectionsKt.single(packageFragmentProvider.getPackageFragments(packageFqName));
RecursiveDescriptorComparator.validateAndCompareDescriptors(fromLazyResolve, deserialized, configuration, new File("compiler/testData/builtin-classes/default/" + packageFqName.asString().replace('.', '-') + ".txt"));
}
}
}
Aggregations