@Nullable private ScriptDescriptor doAnalyze( @NotNull JetFile psiFile, @NotNull ReplMessageCollectorWrapper messageCollector) { scriptDeclarationFactory.setDelegateFactory( new FileBasedDeclarationProviderFactory( resolveSession.getStorageManager(), Collections.singletonList(psiFile))); TopDownAnalysisContext context = topDownAnalyzer.analyzeDeclarations( topDownAnalysisContext.getTopDownAnalysisMode(), Collections.singletonList(psiFile)); if (trace.get(BindingContext.FILE_TO_PACKAGE_FRAGMENT, psiFile) == null) { trace.record( BindingContext.FILE_TO_PACKAGE_FRAGMENT, psiFile, resolveSession.getPackageFragment(FqName.ROOT)); } boolean hasErrors = AnalyzerWithCompilerReport.reportDiagnostics( trace.getBindingContext().getDiagnostics(), messageCollector.getMessageCollector()); if (hasErrors) { return null; } ScriptDescriptor scriptDescriptor = context.getScripts().get(psiFile.getScript()); lastLineScope = trace.get(BindingContext.SCRIPT_SCOPE, scriptDescriptor); if (lastLineScope == null) { throw new IllegalStateException("last line scope is not initialized"); } return scriptDescriptor; }
@Nullable private ScriptDescriptor doAnalyze( @NotNull JetFile psiFile, @NotNull MessageCollector messageCollector) { WritableScope scope = new WritableScopeImpl( JetScope.EMPTY, module, new TraceBasedRedeclarationHandler(trace), "Root scope in analyzePackage"); scope.changeLockLevel(WritableScope.LockLevel.BOTH); // Import a scope that contains all top-level packages that come from dependencies // This makes the packages visible at all, does not import themselves scope.importScope(module.getPackage(FqName.ROOT).getMemberScope()); if (lastLineScope != null) { scope.importScope(lastLineScope); } scope.changeLockLevel(WritableScope.LockLevel.READING); // dummy builder is used because "root" is module descriptor, // packages added to module explicitly in injector .getTopDownAnalyzer() .doProcess( topDownAnalysisContext, scope, new PackageLikeBuilderDummy(), Collections.singletonList(psiFile)); boolean hasErrors = AnalyzerWithCompilerReport.reportDiagnostics(trace.getBindingContext(), messageCollector); if (hasErrors) { return null; } ScriptDescriptor scriptDescriptor = topDownAnalysisContext.getScripts().get(psiFile.getScript()); lastLineScope = trace.get(BindingContext.SCRIPT_SCOPE, scriptDescriptor); if (lastLineScope == null) { throw new IllegalStateException("last line scope is not initialized"); } return scriptDescriptor; }