Exemplo n.º 1
0
 public ScriptContext(
     @NotNull JetTypeMapper typeMapper,
     @NotNull ScriptDescriptor scriptDescriptor,
     @NotNull List<ScriptDescriptor> earlierScripts,
     @NotNull ClassDescriptor contextDescriptor,
     @Nullable CodegenContext parentContext) {
   super(typeMapper, contextDescriptor, OwnerKind.IMPLEMENTATION, parentContext, null);
   this.scriptDescriptor = scriptDescriptor;
   this.earlierScripts = earlierScripts;
   KtScript script = (KtScript) DescriptorToSourceUtils.getSourceFromDescriptor(scriptDescriptor);
   assert script != null : "Declaration should be present for script: " + scriptDescriptor;
   KtDeclaration lastDeclaration = CollectionsKt.lastOrNull(script.getDeclarations());
   if (lastDeclaration instanceof KtAnonymousInitializer) {
     this.lastStatement = ((KtAnonymousInitializer) lastDeclaration).getBody();
   } else {
     this.lastStatement = null;
   }
 }
Exemplo n.º 2
0
 @NotNull
 public KotlinType resolveScriptReturnType(
     @NotNull KtScript script,
     @NotNull LexicalScope scopeForBodyResolution,
     @NotNull BindingTrace trace) {
   // Resolve all contents of the script
   ExpressionTypingContext context =
       ExpressionTypingContext.newContext(
           trace, scopeForBodyResolution, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE);
   PreliminaryDeclarationVisitor.Companion.createForDeclaration(script, trace);
   KotlinType returnType =
       expressionTypingServices
           .getBlockReturnedType(
               script.getBlockExpression(), CoercionStrategy.NO_COERCION, context)
           .getType();
   if (returnType == null) {
     returnType = ErrorUtils.createErrorType("getBlockReturnedType returned null");
   }
   return returnType;
 }