Refactor LazyClassDescriptor and minor changes
Minor: get script definition once Refactor: get rid of 'LazyClassDescriptor#getInjectedSupertypes' Minor: rename scope
This commit is contained in:
committed by
Ilya Chernikov
parent
4d95e873a9
commit
d5b486eb80
+22
-23
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+21
-24
@@ -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<? extends KotlinType> getInjectedSupertypes() { return null; }
|
||||
|
||||
private class LazyClassTypeConstructor extends AbstractClassTypeConstructor implements LazyEntity {
|
||||
private final NotNullLazyValue<List<TypeParameterDescriptor>> parameters = c.getStorageManager().createLazyValue(new Function0<List<TypeParameterDescriptor>>() {
|
||||
@Override
|
||||
@@ -594,26 +591,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
@NotNull
|
||||
@Override
|
||||
protected Collection<KotlinType> computeSupertypes() {
|
||||
if (KotlinBuiltIns.isSpecialClassWithNoSupertypes(LazyClassDescriptor.this)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<? extends KotlinType> 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<KotlinType> 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<KotlinType> computeSupertypes() {
|
||||
if (KotlinBuiltIns.isSpecialClassWithNoSupertypes(this)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
KtClassOrObject classOrObject = declarationProvider.getOwnerInfo().getCorrespondingClassOrObject();
|
||||
if (classOrObject == null) {
|
||||
return Collections.singleton(c.getModuleDescriptor().getBuiltIns().getAnyType());
|
||||
}
|
||||
|
||||
List<KotlinType> allSupertypes =
|
||||
c.getDescriptorResolver()
|
||||
.resolveSupertypes(getScopeForClassHeaderResolution(), this, classOrObject,
|
||||
c.getTrace());
|
||||
|
||||
return Lists.newArrayList(Collections2.filter(allSupertypes, VALID_SUPERTYPE));
|
||||
}
|
||||
}
|
||||
|
||||
+15
-20
@@ -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<ValueParameterDescriptor> {
|
||||
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,
|
||||
|
||||
+6
-7
@@ -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<KotlinType>? =
|
||||
scriptDefinition.getScriptSupertypes(this).let { if (it.isEmpty()) null else it }
|
||||
override fun computeSupertypes() = scriptDefinition.getScriptSupertypes(this).ifEmpty { listOf(builtIns.anyType) }
|
||||
|
||||
override fun getScriptParametersToPassToSuperclass(): List<Pair<Name, KotlinType>> {
|
||||
val scriptParams = scriptDefinition.getScriptParameters(this)
|
||||
|
||||
Reference in New Issue
Block a user