From 214465a81c0bac286aca145eaf86e59de09b3e34 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 27 Mar 2014 20:58:59 +0400 Subject: [PATCH] Extract method --- .../jet/lang/resolve/ScriptBodyResolver.java | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ScriptBodyResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ScriptBodyResolver.java index 382f5e3a052..8b07aeae159 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ScriptBodyResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ScriptBodyResolver.java @@ -56,22 +56,11 @@ public class ScriptBodyResolver { for (Map.Entry e : c.getScripts().entrySet()) { JetScript declaration = e.getKey(); ScriptDescriptorImpl descriptor = (ScriptDescriptorImpl) e.getValue(); - WritableScope scope = descriptor.getScopeForBodyResolution(); // TODO: lock in resolveScriptDeclarations - scope.changeLockLevel(WritableScope.LockLevel.READING); + descriptor.getScopeForBodyResolution().changeLockLevel(WritableScope.LockLevel.READING); - ExpressionTypingContext context = ExpressionTypingContext.newContext( - expressionTypingServices, - trace, - scope, - DataFlowInfo.EMPTY, - NO_EXPECTED_TYPE - ); - JetType returnType = expressionTypingServices.getBlockReturnedType(declaration.getBlockExpression(), CoercionStrategy.NO_COERCION, context).getType(); - if (returnType == null) { - returnType = ErrorUtils.createErrorType("getBlockReturnedType returned null"); - } + JetType returnType = resolveScriptReturnType(declaration, descriptor, trace); List properties = new ArrayList(); List functions = new ArrayList(); @@ -97,6 +86,26 @@ public class ScriptBodyResolver { } } + private JetType resolveScriptReturnType( + @NotNull JetScript script, + @NotNull ScriptDescriptor scriptDescriptor, + @NotNull BindingTrace trace + ) { + // Resolve all contents of the script + ExpressionTypingContext context = ExpressionTypingContext.newContext( + expressionTypingServices, + 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; + } + public static boolean shouldBeScriptClassMember(@NotNull JetDeclaration declaration) { // To avoid the necessity to always analyze the whole body of a script even if just its class descriptor is needed // we only add those vals, vars and funs that have explicitly specified return types