Extract method
This commit is contained in:
@@ -56,22 +56,11 @@ public class ScriptBodyResolver {
|
|||||||
for (Map.Entry<JetScript, ScriptDescriptor> e : c.getScripts().entrySet()) {
|
for (Map.Entry<JetScript, ScriptDescriptor> e : c.getScripts().entrySet()) {
|
||||||
JetScript declaration = e.getKey();
|
JetScript declaration = e.getKey();
|
||||||
ScriptDescriptorImpl descriptor = (ScriptDescriptorImpl) e.getValue();
|
ScriptDescriptorImpl descriptor = (ScriptDescriptorImpl) e.getValue();
|
||||||
WritableScope scope = descriptor.getScopeForBodyResolution();
|
|
||||||
|
|
||||||
// TODO: lock in resolveScriptDeclarations
|
// TODO: lock in resolveScriptDeclarations
|
||||||
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
descriptor.getScopeForBodyResolution().changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
|
|
||||||
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
JetType returnType = resolveScriptReturnType(declaration, descriptor, trace);
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<PropertyDescriptorImpl> properties = new ArrayList<PropertyDescriptorImpl>();
|
List<PropertyDescriptorImpl> properties = new ArrayList<PropertyDescriptorImpl>();
|
||||||
List<SimpleFunctionDescriptor> functions = new ArrayList<SimpleFunctionDescriptor>();
|
List<SimpleFunctionDescriptor> functions = new ArrayList<SimpleFunctionDescriptor>();
|
||||||
@@ -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) {
|
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
|
// 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
|
// we only add those vals, vars and funs that have explicitly specified return types
|
||||||
|
|||||||
Reference in New Issue
Block a user