diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/JavaClassFinderImpl.java b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/JavaClassFinderImpl.java index c55e0238aa8..222b45bbf98 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/JavaClassFinderImpl.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/JavaClassFinderImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -61,38 +61,37 @@ public class JavaClassFinderImpl implements JavaClassFinder { // Only activate post create } - public class DelegatingGlobalSearchScopeWithBaseAccess extends DelegatingGlobalSearchScope { - - public DelegatingGlobalSearchScopeWithBaseAccess(@NotNull GlobalSearchScope baseScope) { + public class FilterOutKotlinSourceFilesScope extends DelegatingGlobalSearchScope { + public FilterOutKotlinSourceFilesScope(@NotNull GlobalSearchScope baseScope) { super(baseScope); } + @Override + public boolean contains(@NotNull VirtualFile file) { + return myBaseScope.contains(file) && (file.isDirectory() || file.getFileType() != KotlinFileType.INSTANCE); + } + + @NotNull public GlobalSearchScope getBase() { return myBaseScope; } + + //NOTE: expected by class finder to be not null + @NotNull + @Override + public Project getProject() { + return project; + } + + @Override + public String toString() { + return "JCFI: " + myBaseScope; + } } @PostConstruct public void initialize() { - javaSearchScope = new DelegatingGlobalSearchScopeWithBaseAccess(baseScope) { - @Override - public boolean contains(@NotNull VirtualFile file) { - return myBaseScope.contains(file) && (file.isDirectory() || file.getFileType() != KotlinFileType.INSTANCE); - } - - //NOTE: expected by class finder to be not null - @NotNull - @Override - public Project getProject() { - return project; - } - - @Override - public String toString() { - return "JCFI: " + baseScope; - } - }; - + javaSearchScope = new FilterOutKotlinSourceFilesScope(baseScope); javaFacade = KotlinJavaPsiFacade.getInstance(project); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java index f1280a1ad20..96620c8c207 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -567,9 +567,6 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes return parameters.invoke(); } - @Nullable - public List getInjectedSupertypes() { return null; } - private class LazyClassTypeConstructor extends AbstractClassTypeConstructor implements LazyEntity { private final NotNullLazyValue> parameters = c.getStorageManager().createLazyValue(new Function0>() { @Override @@ -594,26 +591,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes @NotNull @Override protected Collection computeSupertypes() { - if (KotlinBuiltIns.isSpecialClassWithNoSupertypes(LazyClassDescriptor.this)) { - return Collections.emptyList(); - } - - List injectedSupertypes = getInjectedSupertypes(); - if (injectedSupertypes != null) { - return Lists.newArrayList(Collections2.filter(injectedSupertypes, VALID_SUPERTYPE)); - } - - KtClassOrObject classOrObject = declarationProvider.getOwnerInfo().getCorrespondingClassOrObject(); - if (classOrObject == null) { - return Collections.singleton(c.getModuleDescriptor().getBuiltIns().getAnyType()); - } - - List allSupertypes = - c.getDescriptorResolver() - .resolveSupertypes(getScopeForClassHeaderResolution(), LazyClassDescriptor.this, classOrObject, - c.getTrace()); - - return Lists.newArrayList(Collections2.filter(allSupertypes, VALID_SUPERTYPE)); + return LazyClassDescriptor.this.computeSupertypes(); } @Override @@ -706,4 +684,23 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes ForceResolveUtil.forceResolveAllContents(getParameters()); } } + + @NotNull + protected Collection computeSupertypes() { + if (KotlinBuiltIns.isSpecialClassWithNoSupertypes(this)) { + return Collections.emptyList(); + } + + KtClassOrObject classOrObject = declarationProvider.getOwnerInfo().getCorrespondingClassOrObject(); + if (classOrObject == null) { + return Collections.singleton(c.getModuleDescriptor().getBuiltIns().getAnyType()); + } + + List allSupertypes = + c.getDescriptorResolver() + .resolveSupertypes(getScopeForClassHeaderResolution(), this, classOrObject, + c.getTrace()); + + return Lists.newArrayList(Collections2.filter(allSupertypes, VALID_SUPERTYPE)); + } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyScriptClassMemberScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyScriptClassMemberScope.kt index 74fd56e9314..7bbe8b7c32d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyScriptClassMemberScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyScriptClassMemberScope.kt @@ -1,18 +1,18 @@ /* -* Copyright 2010-2015 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. -*/ + * Copyright 2010-2016 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.kotlin.resolve.lazy.descriptors @@ -28,8 +28,6 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.BindingTrace import org.jetbrains.kotlin.resolve.lazy.ResolveSession import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider -import org.jetbrains.kotlin.script.KotlinScriptDefinitionProvider -import org.jetbrains.kotlin.script.getScriptDefinition import org.jetbrains.kotlin.utils.toReadOnlyList class LazyScriptClassMemberScope( @@ -55,10 +53,7 @@ class LazyScriptClassMemberScope( } private fun createScriptParameters(constructor: ConstructorDescriptorImpl): List { - val file = scriptDescriptor.scriptInfo.script.getContainingKtFile() - val scriptDefinition = getScriptDefinition(file) ?: - throw RuntimeException("file ${file.name} is not a script") - return scriptDefinition.getScriptParameters(scriptDescriptor).mapIndexed { index, scriptParameter -> + return scriptDescriptor.scriptDefinition.getScriptParameters(scriptDescriptor).mapIndexed { index, scriptParameter -> ValueParameterDescriptorImpl( constructor, null, index, Annotations.EMPTY, scriptParameter.name, scriptParameter.type, /* declaresDefaultValue = */ false, diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyScriptDescriptor.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyScriptDescriptor.kt index 174f6ecb480..1b704d5e8e6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyScriptDescriptor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyScriptDescriptor.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 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. @@ -21,17 +21,18 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptorVisitor import org.jetbrains.kotlin.descriptors.ScriptDescriptor import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.resolve.lazy.LazyClassContext import org.jetbrains.kotlin.resolve.lazy.ResolveSession import org.jetbrains.kotlin.resolve.lazy.data.KtScriptInfo import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider import org.jetbrains.kotlin.resolve.source.toSourceElement import org.jetbrains.kotlin.script.KotlinScriptDefinition -import org.jetbrains.kotlin.script.KotlinScriptDefinitionProvider import org.jetbrains.kotlin.script.ScriptPriorities import org.jetbrains.kotlin.script.getScriptDefinition import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeSubstitutor +import org.jetbrains.kotlin.utils.ifEmpty class LazyScriptDescriptor( resolveSession: ResolveSession, @@ -56,11 +57,10 @@ class LazyScriptDescriptor( override fun getPriority() = priority - private val scriptDefinition: KotlinScriptDefinition + val scriptDefinition: KotlinScriptDefinition by lazy { val file = scriptInfo.script.getContainingKtFile() - getScriptDefinition(file) ?: - throw RuntimeException("file ${file.name} is not a script") + getScriptDefinition(file) ?: throw RuntimeException("file ${file.name} is not a script") } override fun substitute(substitutor: TypeSubstitutor) = this @@ -79,8 +79,7 @@ class LazyScriptDescriptor( override fun getUnsubstitutedPrimaryConstructor() = super.getUnsubstitutedPrimaryConstructor()!! - override fun getInjectedSupertypes(): List? = - scriptDefinition.getScriptSupertypes(this).let { if (it.isEmpty()) null else it } + override fun computeSupertypes() = scriptDefinition.getScriptSupertypes(this).ifEmpty { listOf(builtIns.anyType) } override fun getScriptParametersToPassToSuperclass(): List> { val scriptParams = scriptDefinition.getScriptParameters(this)