Ejemplo n.º 1
0
  public static void compileScript(
      @NotNull JetScript script,
      @NotNull Type classType,
      @NotNull List<Pair<ScriptDescriptor, Type>> earlierScripts,
      @NotNull GenerationState state,
      @NotNull CompilationErrorHandler errorHandler) {
    registerEarlierScripts(state, earlierScripts);
    registerClassNameForScript(state.getBindingTrace(), script, classType);

    state.beforeCompile();
    KotlinCodegenFacade.generatePackage(
        state,
        script.getContainingJetFile().getPackageFqName(),
        Collections.singleton(script.getContainingJetFile()),
        errorHandler);
  }
Ejemplo n.º 2
0
 @NotNull
 public JetType resolveScriptReturnType(
     @NotNull JetScript script,
     @NotNull ScriptDescriptor scriptDescriptor,
     @NotNull BindingTrace trace) {
   // Resolve all contents of the script
   ExpressionTypingContext context =
       ExpressionTypingContext.newContext(
           trace,
           scriptDescriptor.getScopeForBodyResolution(),
           DataFlowInfo.EMPTY,
           NO_EXPECTED_TYPE);
   JetType returnType =
       expressionTypingServices
           .getBlockReturnedType(
               script.getBlockExpression(), CoercionStrategy.NO_COERCION, context)
           .getType();
   if (returnType == null) {
     returnType = ErrorUtils.createErrorType("getBlockReturnedType returned null");
   }
   return returnType;
 }