Support script return value field in LAZY mode

This commit is contained in:
Andrey Breslav
2014-03-29 15:44:11 +04:00
parent b8119a57ab
commit 64a80baacc
2 changed files with 27 additions and 14 deletions
@@ -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;