public ReplInterpreter( @NotNull Disposable disposable, @NotNull CompilerConfiguration configuration) { jetCoreEnvironment = JetCoreEnvironment.createForProduction(disposable, configuration); Project project = jetCoreEnvironment.getProject(); trace = new BindingTraceContext(); module = AnalyzerFacadeForJVM.createJavaModule("<repl>"); TopDownAnalysisParameters topDownAnalysisParameters = TopDownAnalysisParameters.createForLocalDeclarations( new LockBasedStorageManager(), new ExceptionTracker(), // dummy Predicates.<PsiFile>alwaysTrue()); injector = new InjectorForTopDownAnalyzerForJvm( project, topDownAnalysisParameters, trace, module, MemberFilter.ALWAYS_TRUE); topDownAnalysisContext = new TopDownAnalysisContext(topDownAnalysisParameters); module.addFragmentProvider(SOURCES, injector.getTopDownAnalyzer().getPackageFragmentProvider()); module.addFragmentProvider( BUILT_INS, KotlinBuiltIns.getInstance().getBuiltInsModule().getPackageFragmentProvider()); module.addFragmentProvider( BINARIES, injector.getJavaDescriptorResolver().getPackageFragmentProvider()); List<URL> classpath = Lists.newArrayList(); for (File file : configuration.getList(JVMConfigurationKeys.CLASSPATH_KEY)) { try { classpath.add(file.toURI().toURL()); } catch (MalformedURLException e) { throw UtilsPackage.rethrow(e); } } classLoader = new ReplClassLoader(new URLClassLoader(classpath.toArray(new URL[0]))); }
@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; }
public InjectorForJavaSemanticServices(@NotNull Project project) { this.javaSemanticServices = new JavaSemanticServices(); this.javaDescriptorResolver = new JavaDescriptorResolver(); this.bindingTrace = new org.jetbrains.jet.lang.resolve.BindingTraceContext(); this.javaBridgeConfiguration = new JavaBridgeConfiguration(); this.psiClassFinder = new PsiClassFinderImpl(); this.moduleDescriptor = new org.jetbrains.jet.lang.descriptors.ModuleDescriptorImpl( org.jetbrains.jet.lang.resolve.name.Name.special("<dummy>"), org.jetbrains.jet.lang.resolve.java.JavaBridgeConfiguration.ALL_JAVA_IMPORTS, org.jetbrains.jet.lang.resolve.java.JavaToKotlinClassMap.getInstance()); this.project = project; this.psiDeclarationProviderFactory = new PsiDeclarationProviderFactory(getPsiClassFinder()); this.javaTypeTransformer = new JavaTypeTransformer(); this.javaClassResolver = new JavaClassResolver(); this.javaAnnotationResolver = new JavaAnnotationResolver(); this.javaCompileTimeConstResolver = new JavaCompileTimeConstResolver(); this.javaClassObjectResolver = new JavaClassObjectResolver(); this.javaSupertypeResolver = new JavaSupertypeResolver(); this.javaFunctionResolver = new JavaFunctionResolver(); this.javaValueParameterResolver = new JavaValueParameterResolver(); this.javaSignatureResolver = new JavaSignatureResolver(); this.javaNamespaceResolver = new JavaNamespaceResolver(); this.javaConstructorResolver = new JavaConstructorResolver(); this.javaInnerClassResolver = new JavaInnerClassResolver(); this.javaPropertyResolver = new JavaPropertyResolver(); this.javaSemanticServices.setDescriptorResolver(javaDescriptorResolver); this.javaSemanticServices.setPsiClassFinder(psiClassFinder); this.javaSemanticServices.setPsiDeclarationProviderFactory(psiDeclarationProviderFactory); this.javaSemanticServices.setTrace(bindingTrace); this.javaSemanticServices.setTypeTransformer(javaTypeTransformer); this.javaDescriptorResolver.setClassResolver(javaClassResolver); this.javaDescriptorResolver.setConstructorResolver(javaConstructorResolver); this.javaDescriptorResolver.setFunctionResolver(javaFunctionResolver); this.javaDescriptorResolver.setInnerClassResolver(javaInnerClassResolver); this.javaDescriptorResolver.setNamespaceResolver(javaNamespaceResolver); this.javaDescriptorResolver.setPropertiesResolver(javaPropertyResolver); javaBridgeConfiguration.setJavaSemanticServices(javaSemanticServices); this.psiClassFinder.setProject(project); moduleDescriptor.setModuleConfiguration(javaBridgeConfiguration); javaTypeTransformer.setJavaSemanticServices(javaSemanticServices); javaTypeTransformer.setResolver(javaDescriptorResolver); javaClassResolver.setAnnotationResolver(javaAnnotationResolver); javaClassResolver.setClassObjectResolver(javaClassObjectResolver); javaClassResolver.setFunctionResolver(javaFunctionResolver); javaClassResolver.setNamespaceResolver(javaNamespaceResolver); javaClassResolver.setPsiClassFinder(psiClassFinder); javaClassResolver.setSemanticServices(javaSemanticServices); javaClassResolver.setSignatureResolver(javaSignatureResolver); javaClassResolver.setSupertypesResolver(javaSupertypeResolver); javaClassResolver.setTrace(bindingTrace); javaAnnotationResolver.setClassResolver(javaClassResolver); javaAnnotationResolver.setCompileTimeConstResolver(javaCompileTimeConstResolver); javaCompileTimeConstResolver.setAnnotationResolver(javaAnnotationResolver); javaCompileTimeConstResolver.setClassResolver(javaClassResolver); javaClassObjectResolver.setSemanticServices(javaSemanticServices); javaClassObjectResolver.setSupertypesResolver(javaSupertypeResolver); javaClassObjectResolver.setTrace(bindingTrace); javaSupertypeResolver.setClassResolver(javaClassResolver); javaSupertypeResolver.setSemanticServices(javaSemanticServices); javaSupertypeResolver.setTrace(bindingTrace); javaSupertypeResolver.setTypeTransformer(javaTypeTransformer); javaFunctionResolver.setAnnotationResolver(javaAnnotationResolver); javaFunctionResolver.setParameterResolver(javaValueParameterResolver); javaFunctionResolver.setSignatureResolver(javaSignatureResolver); javaFunctionResolver.setTrace(bindingTrace); javaFunctionResolver.setTypeTransformer(javaTypeTransformer); javaValueParameterResolver.setTypeTransformer(javaTypeTransformer); javaSignatureResolver.setJavaSemanticServices(javaSemanticServices); javaNamespaceResolver.setJavaSemanticServices(javaSemanticServices); javaNamespaceResolver.setPsiClassFinder(psiClassFinder); javaNamespaceResolver.setTrace(bindingTrace); javaConstructorResolver.setTrace(bindingTrace); javaConstructorResolver.setTypeTransformer(javaTypeTransformer); javaConstructorResolver.setValueParameterResolver(javaValueParameterResolver); javaInnerClassResolver.setClassResolver(javaClassResolver); javaPropertyResolver.setAnnotationResolver(javaAnnotationResolver); javaPropertyResolver.setJavaSignatureResolver(javaSignatureResolver); javaPropertyResolver.setSemanticServices(javaSemanticServices); javaPropertyResolver.setTrace(bindingTrace); psiClassFinder.initialize(); }