Esempio n. 1
0
 @NotNull
 public static ClassFileFactory generateFiles(
     @NotNull JetCoreEnvironment environment, @NotNull CodegenTestFiles files) {
   AnalyzeExhaust analyzeExhaust =
       AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationAndCheckForErrors(
           environment.getProject(),
           files.getPsiFiles(),
           files.getScriptParameterTypes(),
           Predicates.<PsiFile>alwaysTrue());
   analyzeExhaust.throwIfError();
   AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext());
   CompilerConfiguration configuration = environment.getConfiguration();
   GenerationState state =
       new GenerationState(
           environment.getProject(),
           ClassBuilderFactories.TEST,
           Progress.DEAF,
           analyzeExhaust.getBindingContext(),
           files.getPsiFiles(),
           configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_ASSERTIONS, true),
           configuration.get(JVMConfigurationKeys.GENERATE_NOT_NULL_PARAMETER_ASSERTIONS, true),
           /*generateDeclaredClasses = */ true,
           configuration.get(
               JVMConfigurationKeys.ENABLE_INLINE, InlineUtil.DEFAULT_INLINE_FLAG_FOR_TEST));
   KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
   return state.getFactory();
 }
  @Override
  protected void analyzeAndCheck(File testDataFile, List<TestFile> testFiles) {
    List<JetFile> jetFiles = getJetFiles(testFiles);

    CliLightClassGenerationSupport support =
        CliLightClassGenerationSupport.getInstanceForCli(getProject());

    BindingContext bindingContext =
        AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
                getProject(),
                jetFiles,
                support.getTrace(),
                Predicates.<PsiFile>alwaysTrue(),
                false,
                support.getModule(),
                MemberFilter.ALWAYS_TRUE)
            .getBindingContext();

    boolean ok = true;

    StringBuilder actualText = new StringBuilder();
    for (TestFile testFile : testFiles) {
      ok &= testFile.getActualText(bindingContext, actualText);
    }

    JetTestUtils.assertEqualsToFile(testDataFile, actualText.toString());

    assertTrue("Diagnostics mismatch. See the output above", ok);

    checkAllResolvedCallsAreCompleted(jetFiles, bindingContext);
  }
Esempio n. 3
0
  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])));
  }