ScriptDescriptor exposes result property
This commit is contained in:
+7
-1
@@ -38,7 +38,7 @@ public class LazyScriptClassDescriptor extends LazyClassDescriptor {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LazyClassMemberScope createMemberScope(
|
||||
protected LazyScriptClassMemberScope createMemberScope(
|
||||
@NotNull ResolveSession resolveSession, @NotNull ClassMemberDeclarationProvider declarationProvider
|
||||
) {
|
||||
return new LazyScriptClassMemberScope(
|
||||
@@ -49,6 +49,12 @@ public class LazyScriptClassDescriptor extends LazyClassDescriptor {
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public LazyScriptClassMemberScope getScopeForMemberLookup() {
|
||||
return (LazyScriptClassMemberScope) super.getScopeForMemberLookup();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Visibility getVisibility() {
|
||||
|
||||
+24
-6
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.lazy.descriptors;
|
||||
|
||||
import kotlin.Function0;
|
||||
import kotlin.Function1;
|
||||
import kotlin.KotlinPackage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -27,19 +28,33 @@ import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.data.JetScriptInfo;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.ClassMemberDeclarationProvider;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.storage.NotNullLazyValue;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
// SCRIPT: Members of a script class
|
||||
public class LazyScriptClassMemberScope extends LazyClassMemberScope {
|
||||
|
||||
private final NotNullLazyValue<PropertyDescriptor> scriptResultProperty;
|
||||
|
||||
protected LazyScriptClassMemberScope(
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull ClassMemberDeclarationProvider declarationProvider,
|
||||
@NotNull ResolveSession _resolveSession,
|
||||
@NotNull ClassMemberDeclarationProvider _declarationProvider,
|
||||
@NotNull LazyClassDescriptor thisClass,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
super(resolveSession, declarationProvider, thisClass, trace);
|
||||
super(_resolveSession, _declarationProvider, thisClass, trace);
|
||||
this.scriptResultProperty = _resolveSession.getStorageManager().createLazyValue(
|
||||
new Function0<PropertyDescriptor>() {
|
||||
@Override
|
||||
public PropertyDescriptor invoke() {
|
||||
JetScriptInfo scriptInfo = (JetScriptInfo) declarationProvider.getOwnerInfo();
|
||||
|
||||
return ScriptDescriptorImpl.createScriptResultProperty(resolveSession.getScriptDescriptor(scriptInfo.getScript()));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -70,13 +85,16 @@ public class LazyScriptClassMemberScope extends LazyClassMemberScope {
|
||||
protected void getNonDeclaredProperties(@NotNull Name name, @NotNull Set<VariableDescriptor> result) {
|
||||
super.getNonDeclaredProperties(name, result);
|
||||
|
||||
JetScriptInfo scriptInfo = (JetScriptInfo) declarationProvider.getOwnerInfo();
|
||||
|
||||
if (name.asString().equals(ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME)) {
|
||||
result.add(ScriptDescriptorImpl.createScriptResultProperty(resolveSession.getScriptDescriptor(scriptInfo.getScript())));
|
||||
result.add(scriptResultProperty.invoke());
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PropertyDescriptor getScriptResultProperty() {
|
||||
return scriptResultProperty.invoke();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createPropertiesFromPrimaryConstructorParameters(@NotNull Name name, @NotNull Set<VariableDescriptor> result) {
|
||||
JetScriptInfo scriptInfo = (JetScriptInfo) declarationProvider.getOwnerInfo();
|
||||
|
||||
+4
-1
@@ -39,6 +39,7 @@ import org.jetbrains.jet.lang.types.TypeSubstitutor
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor
|
||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor
|
||||
|
||||
public class LazyScriptDescriptor(
|
||||
val resolveSession: ResolveSession,
|
||||
@@ -64,7 +65,9 @@ public class LazyScriptDescriptor(
|
||||
|
||||
override fun getPriority() = _priority
|
||||
|
||||
override fun getClassDescriptor() = resolveSession.getClassDescriptorForScript(jetScript)
|
||||
override fun getClassDescriptor() = resolveSession.getClassDescriptorForScript(jetScript) as LazyScriptClassDescriptor
|
||||
|
||||
override fun getScriptResultProperty(): PropertyDescriptor = getClassDescriptor().getScopeForMemberLookup().getScriptResultProperty()
|
||||
|
||||
private val _scriptCodeDescriptor = resolveSession.getStorageManager().createLazyValue {
|
||||
val result = ScriptCodeDescriptor(this)
|
||||
|
||||
@@ -39,4 +39,7 @@ public interface ScriptDescriptor extends Annotated, DeclarationDescriptor, Decl
|
||||
|
||||
@NotNull
|
||||
JetScope getScopeForBodyResolution();
|
||||
|
||||
@NotNull
|
||||
PropertyDescriptor getScriptResultProperty();
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ public class ScriptDescriptorImpl extends DeclarationDescriptorNonRootImpl imple
|
||||
|
||||
private final WritableScopeImpl classScope;
|
||||
private WritableScope scopeForBodyResolution;
|
||||
private PropertyDescriptor scriptResultProperty;
|
||||
|
||||
public ScriptDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@@ -81,7 +82,8 @@ public class ScriptDescriptorImpl extends DeclarationDescriptorNonRootImpl imple
|
||||
assert valueParameters != null : "setValueParameters() must be called before this method";
|
||||
scriptCodeDescriptor.initialize(implicitReceiver, valueParameters, returnType);
|
||||
|
||||
classScope.addPropertyDescriptor(createScriptResultProperty(this));
|
||||
scriptResultProperty = createScriptResultProperty(this);
|
||||
classScope.addPropertyDescriptor(scriptResultProperty);
|
||||
|
||||
for (PropertyDescriptorImpl property : properties) {
|
||||
classScope.addPropertyDescriptor(property);
|
||||
@@ -112,6 +114,12 @@ public class ScriptDescriptorImpl extends DeclarationDescriptorNonRootImpl imple
|
||||
return propertyDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PropertyDescriptor getScriptResultProperty() {
|
||||
return scriptResultProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return priority;
|
||||
|
||||
Reference in New Issue
Block a user