diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/LazyScriptClassMemberScope.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/LazyScriptClassMemberScope.java deleted file mode 100644 index 7f41b3012f0..00000000000 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/LazyScriptClassMemberScope.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2010-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.lang.resolve.lazy.descriptors; - -import kotlin.Function0; -import kotlin.Function1; -import kotlin.KotlinPackage; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.descriptors.*; -import org.jetbrains.jet.lang.descriptors.impl.ConstructorDescriptorImpl; -import org.jetbrains.jet.lang.descriptors.impl.ScriptDescriptorImpl; -import org.jetbrains.jet.lang.resolve.BindingTrace; -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 org.jetbrains.jet.utils.UtilsPackage; - -import java.util.Collection; -import java.util.Set; - -// SCRIPT: Members of a script class -public class LazyScriptClassMemberScope extends LazyClassMemberScope { - - private final NotNullLazyValue scriptResultProperty; - - protected LazyScriptClassMemberScope( - @NotNull ResolveSession _resolveSession, - @NotNull ClassMemberDeclarationProvider _declarationProvider, - @NotNull LazyClassDescriptor thisClass, - @NotNull BindingTrace trace - ) { - super(_resolveSession, _declarationProvider, thisClass, trace); - this.scriptResultProperty = _resolveSession.getStorageManager().createLazyValue( - new Function0() { - @Override - public PropertyDescriptor invoke() { - JetScriptInfo scriptInfo = (JetScriptInfo) getDeclarationProvider().getOwnerInfo(); - - return ScriptDescriptorImpl.createScriptResultProperty(getResolveSession().getScriptDescriptor(scriptInfo.getScript())); - } - } - ); - } - - @NotNull - @Override - protected Collection computeExtraDescriptors() { - return UtilsPackage.toReadOnlyList(KotlinPackage.plus( - super.computeExtraDescriptors(), - KotlinPackage.plus( - getProperties(Name.identifier(ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME)), - getPropertiesForScriptParameters() - ) - )); - } - - private Collection getPropertiesForScriptParameters() { - return KotlinPackage.flatMap( - getPrimaryConstructor().getValueParameters(), - new Function1>() { - @Override - public Iterable invoke(ValueParameterDescriptor descriptor) { - return getProperties(descriptor.getName()); - } - } - ); - } - - @Override - protected void getNonDeclaredProperties(@NotNull Name name, @NotNull Set result) { - super.getNonDeclaredProperties(name, result); - - if (name.asString().equals(ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME)) { - result.add(scriptResultProperty.invoke()); - } - } - - @NotNull - public PropertyDescriptor getScriptResultProperty() { - return scriptResultProperty.invoke(); - } - - @Override - protected void createPropertiesFromPrimaryConstructorParameters(@NotNull Name name, @NotNull Set result) { - JetScriptInfo scriptInfo = (JetScriptInfo) getDeclarationProvider().getOwnerInfo(); - - // From primary constructor parameters - ConstructorDescriptor primaryConstructor = getPrimaryConstructor(); - if (primaryConstructor == null) return; - - for (ValueParameterDescriptor valueParameterDescriptor : primaryConstructor.getValueParameters()) { - if (!name.equals(valueParameterDescriptor.getName())) continue; - - result.add( - ScriptDescriptorImpl.createPropertyFromScriptParameter( - getResolveSession().getScriptDescriptor(scriptInfo.getScript()), - valueParameterDescriptor - ) - ); - } - } - - @Override - @Nullable - protected ConstructorDescriptor resolvePrimaryConstructor() { - JetScriptInfo scriptInfo = (JetScriptInfo) getDeclarationProvider().getOwnerInfo(); - ScriptDescriptor scriptDescriptor = getResolveSession().getScriptDescriptor(scriptInfo.getScript()); - ConstructorDescriptorImpl constructor = ScriptDescriptorImpl.createConstructor(scriptDescriptor, - scriptDescriptor.getScriptCodeDescriptor() - .getValueParameters()); - setDeferredReturnType(constructor); - return constructor; - } -} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/LazyScriptClassMemberScope.kt b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/LazyScriptClassMemberScope.kt new file mode 100644 index 00000000000..baa1054522c --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/LazyScriptClassMemberScope.kt @@ -0,0 +1,81 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.lang.resolve.lazy.descriptors + +import org.jetbrains.jet.lang.descriptors.* +import org.jetbrains.jet.lang.descriptors.impl.ScriptDescriptorImpl +import org.jetbrains.jet.lang.resolve.BindingTrace +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 org.jetbrains.jet.utils.toReadOnlyList + +// SCRIPT: Members of a script class +public class LazyScriptClassMemberScope protected( + resolveSession: ResolveSession, + declarationProvider: ClassMemberDeclarationProvider, + thisClass: LazyClassDescriptor, + trace: BindingTrace) +: LazyClassMemberScope(resolveSession, declarationProvider, thisClass, trace) { + + private val scriptResultProperty: NotNullLazyValue = resolveSession.getStorageManager().createLazyValue { + val scriptInfo = declarationProvider.getOwnerInfo() as JetScriptInfo + ScriptDescriptorImpl.createScriptResultProperty(resolveSession.getScriptDescriptor(scriptInfo.script)) + } + + override fun computeExtraDescriptors(): Collection { + return (super.computeExtraDescriptors() + + getProperties(Name.identifier(ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME)) + + getPropertiesForScriptParameters()).toReadOnlyList() + } + + private fun getPropertiesForScriptParameters() = getPrimaryConstructor()!!.getValueParameters().flatMap { getProperties(it.getName()) } + + override fun getNonDeclaredProperties(name: Name, result: MutableSet) { + super.getNonDeclaredProperties(name, result) + + if (name.asString() == ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME) { + result.add(scriptResultProperty.invoke()) + } + } + + public fun getScriptResultProperty(): PropertyDescriptor = scriptResultProperty.invoke() + + override fun createPropertiesFromPrimaryConstructorParameters(name: Name, result: MutableSet) { + val scriptInfo = declarationProvider.getOwnerInfo() as JetScriptInfo + + // From primary constructor parameters + val primaryConstructor = getPrimaryConstructor() + if (primaryConstructor == null) return + + for (valueParameterDescriptor in primaryConstructor.getValueParameters()) { + if (name == valueParameterDescriptor.getName()) { + result.add(ScriptDescriptorImpl.createPropertyFromScriptParameter(resolveSession.getScriptDescriptor(scriptInfo.script), valueParameterDescriptor)) + } + } + } + + override fun resolvePrimaryConstructor(): ConstructorDescriptor? { + val scriptInfo = declarationProvider.getOwnerInfo() as JetScriptInfo + val scriptDescriptor = resolveSession.getScriptDescriptor(scriptInfo.script) + val constructor = ScriptDescriptorImpl.createConstructor(scriptDescriptor, scriptDescriptor.getScriptCodeDescriptor().getValueParameters()) + setDeferredReturnType(constructor) + return constructor + } +}