Support script return value field in LAZY mode
This commit is contained in:
+6
@@ -254,6 +254,12 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
|
||||
}
|
||||
}
|
||||
|
||||
// SCRIPT: Adding script result
|
||||
if (classInfo instanceof JetScriptInfo && name.asString().equals(ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME)) {
|
||||
JetScriptInfo scriptInfo = (JetScriptInfo) classInfo;
|
||||
result.add(ScriptDescriptorImpl.createScriptResultProperty(resolveSession.getScriptDescriptor(scriptInfo.getScript())));
|
||||
}
|
||||
|
||||
// Members from supertypes
|
||||
Collection<PropertyDescriptor> fromSupertypes = Lists.newArrayList();
|
||||
for (JetType supertype : thisDescriptor.getTypeConstructor().getSupertypes()) {
|
||||
|
||||
@@ -77,20 +77,7 @@ public class ScriptDescriptorImpl extends DeclarationDescriptorNonRootImpl imple
|
||||
assert valueParameters != null : "setValueParameters() must be called before this method";
|
||||
scriptCodeDescriptor.initialize(implicitReceiver, valueParameters, returnType);
|
||||
|
||||
PropertyDescriptorImpl propertyDescriptor = PropertyDescriptorImpl.create(classDescriptor,
|
||||
Annotations.EMPTY,
|
||||
Modality.FINAL,
|
||||
Visibilities.PUBLIC,
|
||||
false,
|
||||
Name.identifier(LAST_EXPRESSION_VALUE_FIELD_NAME),
|
||||
CallableMemberDescriptor.Kind.DECLARATION);
|
||||
propertyDescriptor.setType(
|
||||
returnType,
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
classDescriptor.getThisAsReceiverParameter(),
|
||||
ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER);
|
||||
propertyDescriptor.initialize(null, null);
|
||||
classScope.addPropertyDescriptor(propertyDescriptor);
|
||||
classScope.addPropertyDescriptor(createScriptResultProperty(this));
|
||||
|
||||
for (PropertyDescriptorImpl property : properties) {
|
||||
classScope.addPropertyDescriptor(property);
|
||||
@@ -101,6 +88,26 @@ public class ScriptDescriptorImpl extends DeclarationDescriptorNonRootImpl imple
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PropertyDescriptor createScriptResultProperty(@NotNull ScriptDescriptor scriptDescriptor) {
|
||||
PropertyDescriptorImpl propertyDescriptor = PropertyDescriptorImpl.create(scriptDescriptor.getClassDescriptor(),
|
||||
Annotations.EMPTY,
|
||||
Modality.FINAL,
|
||||
Visibilities.PUBLIC,
|
||||
false,
|
||||
Name.identifier(LAST_EXPRESSION_VALUE_FIELD_NAME),
|
||||
CallableMemberDescriptor.Kind.DECLARATION);
|
||||
JetType returnType = scriptDescriptor.getScriptCodeDescriptor().getReturnType();
|
||||
assert returnType != null : "Return type not initialized for " + scriptDescriptor;
|
||||
propertyDescriptor.setType(
|
||||
returnType,
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
scriptDescriptor.getThisAsReceiverParameter(),
|
||||
ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER);
|
||||
propertyDescriptor.initialize(null, null);
|
||||
return propertyDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
|
||||
Reference in New Issue
Block a user