Move some script related part of frontend to separate module to avoid using kotlin-reflect.jar in frontend module

Main goal is get rid of kotlin-reflect.jar from modules what required for minimal compiler.jar which can compile Kotlin only to JS to make it smaller.
This commit is contained in:
Zalim Bashorov
2017-04-13 22:07:18 +03:00
parent 05c3e7e81d
commit 51e84f7ce4
27 changed files with 175 additions and 35 deletions
+1
View File
@@ -60,6 +60,7 @@
<element id="module-output" name="backend.jvm" /> <element id="module-output" name="backend.jvm" />
<element id="module-output" name="ir.psi2ir" /> <element id="module-output" name="ir.psi2ir" />
<element id="module-output" name="annotation-based-compiler-plugins-ide-support" /> <element id="module-output" name="annotation-based-compiler-plugins-ide-support" />
<element id="module-output" name="frontend.script" />
</element> </element>
<element id="library" level="project" name="javax.inject" /> <element id="library" level="project" name="javax.inject" />
<element id="directory" name="jps"> <element id="directory" name="jps">
+1
View File
@@ -41,6 +41,7 @@
<module fileurl="file://$PROJECT_DIR$/idea/formatter/formatter.iml" filepath="$PROJECT_DIR$/idea/formatter/formatter.iml" group="ide" /> <module fileurl="file://$PROJECT_DIR$/idea/formatter/formatter.iml" filepath="$PROJECT_DIR$/idea/formatter/formatter.iml" group="ide" />
<module fileurl="file://$PROJECT_DIR$/compiler/frontend/frontend.iml" filepath="$PROJECT_DIR$/compiler/frontend/frontend.iml" group="compiler" /> <module fileurl="file://$PROJECT_DIR$/compiler/frontend/frontend.iml" filepath="$PROJECT_DIR$/compiler/frontend/frontend.iml" group="compiler" />
<module fileurl="file://$PROJECT_DIR$/compiler/frontend.java/frontend.java.iml" filepath="$PROJECT_DIR$/compiler/frontend.java/frontend.java.iml" group="compiler/java" /> <module fileurl="file://$PROJECT_DIR$/compiler/frontend.java/frontend.java.iml" filepath="$PROJECT_DIR$/compiler/frontend.java/frontend.java.iml" group="compiler/java" />
<module fileurl="file://$PROJECT_DIR$/compiler/frontend.script/frontend.script.iml" filepath="$PROJECT_DIR$/compiler/frontend.script/frontend.script.iml" group="compiler" />
<module fileurl="file://$PROJECT_DIR$/generators/generators.iml" filepath="$PROJECT_DIR$/generators/generators.iml" group="infrastructure" /> <module fileurl="file://$PROJECT_DIR$/generators/generators.iml" filepath="$PROJECT_DIR$/generators/generators.iml" group="infrastructure" />
<module fileurl="file://$PROJECT_DIR$/grammar/grammar.iml" filepath="$PROJECT_DIR$/grammar/grammar.iml" group="compiler" /> <module fileurl="file://$PROJECT_DIR$/grammar/grammar.iml" filepath="$PROJECT_DIR$/grammar/grammar.iml" group="compiler" />
<module fileurl="file://$PROJECT_DIR$/idea/ide-common/ide-common.iml" filepath="$PROJECT_DIR$/idea/ide-common/ide-common.iml" group="ide" /> <module fileurl="file://$PROJECT_DIR$/idea/ide-common/ide-common.iml" filepath="$PROJECT_DIR$/idea/ide-common/ide-common.iml" group="ide" />
+3
View File
@@ -96,6 +96,7 @@
<include name="compiler/plugin-api/src"/> <include name="compiler/plugin-api/src"/>
<include name="compiler/daemon/src"/> <include name="compiler/daemon/src"/>
<include name="compiler/daemon/daemon-common/src"/> <include name="compiler/daemon/daemon-common/src"/>
<include name="compiler/frontend.script/src"/>
<include name="build-common/src"/> <include name="build-common/src"/>
<include name="compiler/incremental-compilation-impl/src"/> <include name="compiler/incremental-compilation-impl/src"/>
<include name="compiler/serialization/src"/> <include name="compiler/serialization/src"/>
@@ -130,6 +131,7 @@
<include name="conditional-preprocessor/**"/> <include name="conditional-preprocessor/**"/>
<include name="daemon/**"/> <include name="daemon/**"/>
<include name="daemon-common/**"/> <include name="daemon-common/**"/>
<include name="frontend.script/**"/>
<include name="build-common/**"/> <include name="build-common/**"/>
<include name="incremental-compilation-impl/**"/> <include name="incremental-compilation-impl/**"/>
<include name="util/**"/> <include name="util/**"/>
@@ -245,6 +247,7 @@
<fileset dir="compiler/resolution/src"/> <fileset dir="compiler/resolution/src"/>
<fileset dir="compiler/frontend.java/src"/> <fileset dir="compiler/frontend.java/src"/>
<fileset dir="compiler/light-classes/src"/> <fileset dir="compiler/light-classes/src"/>
<fileset dir="compiler/frontend.script/src"/>
<fileset dir="compiler/plugin-api/src"/> <fileset dir="compiler/plugin-api/src"/>
<fileset dir="plugins/annotation-collector/src"/> <fileset dir="plugins/annotation-collector/src"/>
<fileset dir="compiler/serialization/src"/> <fileset dir="compiler/serialization/src"/>
+1
View File
@@ -23,5 +23,6 @@
<orderEntry type="module" module-name="annotation-collector" /> <orderEntry type="module" module-name="annotation-collector" />
<orderEntry type="module" module-name="builtins-serializer" /> <orderEntry type="module" module-name="builtins-serializer" />
<orderEntry type="module" module-name="script.runtime" /> <orderEntry type="module" module-name="script.runtime" />
<orderEntry type="module" module-name="frontend.script" />
</component> </component>
</module> </module>
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2016 JetBrains s.r.o. * Copyright 2010-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -104,6 +104,7 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.CliDeclarationProviderFact
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactoryService import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactoryService
import org.jetbrains.kotlin.script.KotlinScriptDefinitionProvider import org.jetbrains.kotlin.script.KotlinScriptDefinitionProvider
import org.jetbrains.kotlin.script.KotlinScriptExternalImportsProvider import org.jetbrains.kotlin.script.KotlinScriptExternalImportsProvider
import org.jetbrains.kotlin.script.KotlinScriptExternalImportsProviderImpl
import org.jetbrains.kotlin.utils.PathUtil import org.jetbrains.kotlin.utils.PathUtil
import java.io.File import java.io.File
@@ -481,7 +482,7 @@ class KotlinCoreEnvironment private constructor(
with (projectEnvironment.project) { with (projectEnvironment.project) {
val kotlinScriptDefinitionProvider = KotlinScriptDefinitionProvider() val kotlinScriptDefinitionProvider = KotlinScriptDefinitionProvider()
registerService(KotlinScriptDefinitionProvider::class.java, kotlinScriptDefinitionProvider) registerService(KotlinScriptDefinitionProvider::class.java, kotlinScriptDefinitionProvider)
registerService(KotlinScriptExternalImportsProvider::class.java, KotlinScriptExternalImportsProvider(projectEnvironment.project, kotlinScriptDefinitionProvider)) registerService(KotlinScriptExternalImportsProvider::class.java, KotlinScriptExternalImportsProviderImpl(projectEnvironment.project, kotlinScriptDefinitionProvider))
registerService(KotlinJavaPsiFacade::class.java, KotlinJavaPsiFacade(this)) registerService(KotlinJavaPsiFacade::class.java, KotlinJavaPsiFacade(this))
registerService(KtLightClassForFacade.FacadeStubCache::class.java, KtLightClassForFacade.FacadeStubCache(this)) registerService(KtLightClassForFacade.FacadeStubCache::class.java, KtLightClassForFacade.FacadeStubCache(this))
} }
+1
View File
@@ -15,5 +15,6 @@
<orderEntry type="module" module-name="incremental-compilation-impl" /> <orderEntry type="module" module-name="incremental-compilation-impl" />
<orderEntry type="module" module-name="build-common" /> <orderEntry type="module" module-name="build-common" />
<orderEntry type="module" module-name="descriptor.loader.java" /> <orderEntry type="module" module-name="descriptor.loader.java" />
<orderEntry type="module" module-name="frontend.script" />
</component> </component>
</module> </module>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlin-runtime" level="project" />
<orderEntry type="library" name="intellij-core" level="project" />
<orderEntry type="module" module-name="frontend" />
<orderEntry type="module" module-name="util" />
<orderEntry type="library" name="kotlin-reflect" level="project" />
</component>
</module>
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2016 JetBrains s.r.o. * Copyright 2010-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2016 JetBrains s.r.o. * Copyright 2010-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -19,19 +19,23 @@ package org.jetbrains.kotlin.script
import com.intellij.openapi.components.ServiceManager import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import java.io.File import java.io.File
import java.util.concurrent.locks.ReentrantReadWriteLock import java.util.concurrent.locks.ReentrantReadWriteLock
import kotlin.concurrent.read import kotlin.concurrent.read
import kotlin.concurrent.write import kotlin.concurrent.write
import kotlin.script.dependencies.KotlinScriptExternalDependencies import kotlin.script.dependencies.KotlinScriptExternalDependencies
class KotlinScriptExternalImportsProvider(val project: Project, private val scriptDefinitionProvider: KotlinScriptDefinitionProvider) { class KotlinScriptExternalImportsProviderImpl(
val project: Project,
private val scriptDefinitionProvider: KotlinScriptDefinitionProvider
) : KotlinScriptExternalImportsProvider {
private val cacheLock = ReentrantReadWriteLock() private val cacheLock = ReentrantReadWriteLock()
private val cache = hashMapOf<String, KotlinScriptExternalDependencies?>() private val cache = hashMapOf<String, KotlinScriptExternalDependencies?>()
fun <TF: Any> getExternalImports(file: TF): KotlinScriptExternalDependencies? = cacheLock.read { calculateExternalDependencies(file) } override fun <TF: Any> getExternalImports(file: TF): KotlinScriptExternalDependencies? = cacheLock.read {
calculateExternalDependencies(file)
}
fun <TF: Any> getExternalImports(files: Iterable<TF>): List<KotlinScriptExternalDependencies> = cacheLock.read { fun <TF: Any> getExternalImports(files: Iterable<TF>): List<KotlinScriptExternalDependencies> = cacheLock.read {
files.mapNotNull { calculateExternalDependencies(it) } files.mapNotNull { calculateExternalDependencies(it) }
@@ -58,7 +62,7 @@ class KotlinScriptExternalImportsProvider(val project: Project, private val scri
// optimized for initial caching, additional handling of possible duplicates to save a call to distinct // optimized for initial caching, additional handling of possible duplicates to save a call to distinct
// returns list of cached files // returns list of cached files
fun <TF: Any> cacheExternalImports(files: Iterable<TF>): Iterable<TF> = cacheLock.write { override fun <TF: Any> cacheExternalImports(files: Iterable<TF>): Iterable<TF> = cacheLock.write {
val uncached = hashSetOf<String>() val uncached = hashSetOf<String>()
files.mapNotNull { file -> files.mapNotNull { file ->
val path = getFilePath(file) val path = getFilePath(file)
@@ -84,7 +88,7 @@ class KotlinScriptExternalImportsProvider(val project: Project, private val scri
// optimized for update, no special duplicates handling // optimized for update, no special duplicates handling
// returns files with valid script definition (or deleted from cache - which in fact should have script def too) // returns files with valid script definition (or deleted from cache - which in fact should have script def too)
// TODO: this is the badly designed contract, since it mixes the entities, but these files are needed on the calling site now. Find out other solution // TODO: this is the badly designed contract, since it mixes the entities, but these files are needed on the calling site now. Find out other solution
fun <TF: Any> updateExternalImportsCache(files: Iterable<TF>): Iterable<TF> = cacheLock.write { override fun <TF: Any> updateExternalImportsCache(files: Iterable<TF>): Iterable<TF> = cacheLock.write {
files.mapNotNull { file -> files.mapNotNull { file ->
val path = getFilePath(file) val path = getFilePath(file)
if (!isValidFile(file)) { if (!isValidFile(file)) {
@@ -124,19 +128,19 @@ class KotlinScriptExternalImportsProvider(val project: Project, private val scri
} }
} }
fun invalidateCaches() { override fun invalidateCaches() {
cacheLock.write(cache::clear) cacheLock.write(cache::clear)
} }
fun getKnownCombinedClasspath(): List<File> = cacheLock.read { override fun getKnownCombinedClasspath(): List<File> = cacheLock.read {
cache.values.flatMap { it?.classpath ?: emptyList() } cache.values.flatMap { it?.classpath ?: emptyList() }
}.distinct() }.distinct()
fun getKnownSourceRoots(): List<File> = cacheLock.read { override fun getKnownSourceRoots(): List<File> = cacheLock.read {
cache.values.flatMap { it?.sources ?: emptyList() } cache.values.flatMap { it?.sources ?: emptyList() }
}.distinct() }.distinct()
fun <TF: Any> getCombinedClasspathFor(files: Iterable<TF>): List<File> = override fun <TF: Any> getCombinedClasspathFor(files: Iterable<TF>): List<File> =
getExternalImports(files) getExternalImports(files)
.flatMap { it.classpath } .flatMap { it.classpath }
.distinct() .distinct()
@@ -149,13 +153,10 @@ class KotlinScriptExternalImportsProvider(val project: Project, private val scri
} }
} }
internal fun Iterable<File>.isSamePathListAs(other: Iterable<File>): Boolean = private fun Iterable<File>.isSamePathListAs(other: Iterable<File>): Boolean =
with (Pair(iterator(), other.iterator())) { with (Pair(iterator(), other.iterator())) {
while (first.hasNext() && second.hasNext()) { while (first.hasNext() && second.hasNext()) {
if (first.next().canonicalPath != second.next().canonicalPath) return false if (first.next().canonicalPath != second.next().canonicalPath) return false
} }
!(first.hasNext() || second.hasNext()) !(first.hasNext() || second.hasNext())
} }
fun getScriptExternalDependencies(file: VirtualFile, project: Project): KotlinScriptExternalDependencies? =
KotlinScriptExternalImportsProvider.getInstance(project)?.getExternalImports(file)
@@ -0,0 +1,28 @@
/*
* Copyright 2010-2017 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.script
import org.jetbrains.kotlin.descriptors.ScriptDescriptor
import kotlin.reflect.KClass
class ScriptHelperImpl : ScriptHelper {
override fun getScriptParameters(kotlinScriptDefinition: KotlinScriptDefinition, scriptDefinition: ScriptDescriptor) =
kotlinScriptDefinition.getScriptParameters(scriptDefinition)
override fun getKotlinType(scriptDescriptor: ScriptDescriptor, kClass: KClass<out Any>) =
getKotlinTypeByKClass(scriptDescriptor, kClass)
}
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2016 JetBrains s.r.o. * Copyright 2010-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2016 JetBrains s.r.o. * Copyright 2010-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2016 JetBrains s.r.o. * Copyright 2010-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -26,21 +26,22 @@ import org.jetbrains.kotlin.serialization.deserialization.NotFoundClasses
import org.jetbrains.kotlin.serialization.deserialization.findNonGenericClassAcrossDependencies import org.jetbrains.kotlin.serialization.deserialization.findNonGenericClassAcrossDependencies
import org.jetbrains.kotlin.storage.LockBasedStorageManager import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.*
import kotlin.reflect.* import kotlin.reflect.KClass
import kotlin.reflect.KType
import kotlin.reflect.KTypeProjection
import kotlin.reflect.KVariance
import kotlin.reflect.full.primaryConstructor import kotlin.reflect.full.primaryConstructor
data class ScriptParameter(val name: Name, val type: KotlinType)
fun KotlinScriptDefinition.getScriptParameters(scriptDescriptor: ScriptDescriptor): List<ScriptParameter> = fun KotlinScriptDefinition.getScriptParameters(scriptDescriptor: ScriptDescriptor): List<ScriptParameter> =
template.primaryConstructor?.parameters template.primaryConstructor?.parameters
?.map { ScriptParameter(Name.identifier(it.name!!), getKotlinTypeByKType(scriptDescriptor, it.type)) } ?.map { ScriptParameter(Name.identifier(it.name!!), getKotlinTypeByKType(scriptDescriptor, it.type)) }
?: emptyList() ?: emptyList()
fun getKotlinType(scriptDescriptor: ScriptDescriptor, kClass: KClass<out Any>): KotlinType = fun getKotlinTypeByKClass(scriptDescriptor: ScriptDescriptor, kClass: KClass<out Any>): KotlinType =
getKotlinTypeByFqName(scriptDescriptor, getKotlinTypeByFqName(scriptDescriptor,
kClass.qualifiedName ?: throw RuntimeException("Cannot get FQN from $kClass")) kClass.qualifiedName ?: throw RuntimeException("Cannot get FQN from $kClass"))
fun getKotlinTypeByFqName(scriptDescriptor: ScriptDescriptor, fqName: String): KotlinType = private fun getKotlinTypeByFqName(scriptDescriptor: ScriptDescriptor, fqName: String): KotlinType =
scriptDescriptor.module.findNonGenericClassAcrossDependencies( scriptDescriptor.module.findNonGenericClassAcrossDependencies(
ClassId.topLevel(FqName(fqName)), ClassId.topLevel(FqName(fqName)),
NotFoundClasses(LockBasedStorageManager.NO_LOCKS, scriptDescriptor.module) NotFoundClasses(LockBasedStorageManager.NO_LOCKS, scriptDescriptor.module)
@@ -49,12 +50,12 @@ fun getKotlinTypeByFqName(scriptDescriptor: ScriptDescriptor, fqName: String): K
// TODO: support star projections // TODO: support star projections
// TODO: support annotations on types and type parameters // TODO: support annotations on types and type parameters
// TODO: support type parameters on types and type projections // TODO: support type parameters on types and type projections
fun getKotlinTypeByKType(scriptDescriptor: ScriptDescriptor, kType: KType): KotlinType { private fun getKotlinTypeByKType(scriptDescriptor: ScriptDescriptor, kType: KType): KotlinType {
val classifier = kType.classifier val classifier = kType.classifier
if (classifier !is KClass<*>) if (classifier !is KClass<*>)
throw java.lang.UnsupportedOperationException("Only classes are supported as parameters in script template: $classifier") throw java.lang.UnsupportedOperationException("Only classes are supported as parameters in script template: $classifier")
val type = getKotlinType(scriptDescriptor, classifier) val type = getKotlinTypeByKClass(scriptDescriptor, classifier)
val typeProjections = kType.arguments.map { getTypeProjection(scriptDescriptor, it) } val typeProjections = kType.arguments.map { getTypeProjection(scriptDescriptor, it) }
val isNullable = kType.isMarkedNullable val isNullable = kType.isMarkedNullable
-1
View File
@@ -18,6 +18,5 @@
<orderEntry type="library" exported="" name="kotlin-script-runtime" level="project" /> <orderEntry type="library" exported="" name="kotlin-script-runtime" level="project" />
<orderEntry type="module" module-name="script.runtime" /> <orderEntry type="module" module-name="script.runtime" />
<orderEntry type="library" name="javaslang" level="project" /> <orderEntry type="library" name="javaslang" level="project" />
<orderEntry type="library" name="kotlin-reflect" level="project" />
</component> </component>
</module> </module>
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2016 JetBrains s.r.o. * Copyright 2010-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.BindingTrace import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.lazy.ResolveSession import org.jetbrains.kotlin.resolve.lazy.ResolveSession
import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider
import org.jetbrains.kotlin.script.getScriptParameters import org.jetbrains.kotlin.script.ScriptHelper
class LazyScriptClassMemberScope( class LazyScriptClassMemberScope(
resolveSession: ResolveSession, resolveSession: ResolveSession,
@@ -49,7 +49,7 @@ class LazyScriptClassMemberScope(
} }
private fun createScriptParameters(constructor: ClassConstructorDescriptorImpl): List<ValueParameterDescriptor> { private fun createScriptParameters(constructor: ClassConstructorDescriptorImpl): List<ValueParameterDescriptor> {
return scriptDescriptor.scriptDefinition.getScriptParameters(scriptDescriptor).mapIndexed { index, (name, type) -> return ScriptHelper.getInstance()!!.getScriptParameters(scriptDescriptor.scriptDefinition, scriptDescriptor).mapIndexed { index, (name, type) ->
ValueParameterDescriptorImpl( ValueParameterDescriptorImpl(
constructor, null, index, Annotations.EMPTY, name, type, constructor, null, index, Annotations.EMPTY, name, type,
/* declaresDefaultValue = */ false, /* declaresDefaultValue = */ false,
@@ -1,5 +1,5 @@
/* /*
* Copyright 2010-2016 JetBrains s.r.o. * Copyright 2010-2017 JetBrains s.r.o.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -28,8 +28,8 @@ import org.jetbrains.kotlin.resolve.lazy.data.KtScriptInfo
import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider
import org.jetbrains.kotlin.resolve.source.toSourceElement import org.jetbrains.kotlin.resolve.source.toSourceElement
import org.jetbrains.kotlin.script.KotlinScriptDefinition import org.jetbrains.kotlin.script.KotlinScriptDefinition
import org.jetbrains.kotlin.script.ScriptHelper
import org.jetbrains.kotlin.script.ScriptPriorities import org.jetbrains.kotlin.script.ScriptPriorities
import org.jetbrains.kotlin.script.getKotlinTypeByFqName
import org.jetbrains.kotlin.script.getScriptDefinition import org.jetbrains.kotlin.script.getScriptDefinition
import org.jetbrains.kotlin.types.TypeSubstitutor import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.utils.ifEmpty import org.jetbrains.kotlin.utils.ifEmpty
@@ -80,5 +80,5 @@ class LazyScriptDescriptor(
override fun getUnsubstitutedPrimaryConstructor() = super.getUnsubstitutedPrimaryConstructor()!! override fun getUnsubstitutedPrimaryConstructor() = super.getUnsubstitutedPrimaryConstructor()!!
override fun computeSupertypes() = listOf(getKotlinTypeByFqName(this, scriptDefinition.template.qualifiedName!!)).ifEmpty { listOf(builtIns.anyType) } override fun computeSupertypes() = listOf(ScriptHelper.getInstance()!!.getKotlinType(this, scriptDefinition.template)).ifEmpty { listOf(builtIns.anyType) }
} }
@@ -0,0 +1,41 @@
/*
* Copyright 2010-2017 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.script
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import java.io.File
import kotlin.script.dependencies.KotlinScriptExternalDependencies
interface KotlinScriptExternalImportsProvider {
fun <TF: Any> getExternalImports(file: TF): KotlinScriptExternalDependencies?
fun <TF: Any> cacheExternalImports(files: Iterable<TF>): Iterable<TF>
fun <TF: Any> updateExternalImportsCache(files: Iterable<TF>): Iterable<TF>
fun invalidateCaches()
fun getKnownCombinedClasspath(): List<File>
fun getKnownSourceRoots(): List<File>
fun <TF: Any> getCombinedClasspathFor(files: Iterable<TF>): List<File>
companion object {
fun getInstance(project: Project): KotlinScriptExternalImportsProvider? =
ServiceManager.getService(project, KotlinScriptExternalImportsProvider::class.java)
}
}
fun getScriptExternalDependencies(file: VirtualFile, project: Project): KotlinScriptExternalDependencies? =
KotlinScriptExternalImportsProvider.getInstance(project)?.getExternalImports(file)
@@ -0,0 +1,36 @@
/*
* Copyright 2010-2017 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.script
import com.intellij.openapi.extensions.ExtensionPointName
import org.jetbrains.kotlin.descriptors.ScriptDescriptor
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.types.KotlinType
import kotlin.reflect.KClass
data class ScriptParameter(val name: Name, val type: KotlinType)
interface ScriptHelper {
fun getScriptParameters(kotlinScriptDefinition: KotlinScriptDefinition, scriptDefinition: ScriptDescriptor): List<ScriptParameter>
fun getKotlinType(scriptDescriptor: ScriptDescriptor, kClass: KClass<out Any>): KotlinType
companion object {
private val EP_NAME = ExtensionPointName.create<ScriptHelper>("org.jetbrains.kotlin.scriptHelper")
fun getInstance(): ScriptHelper? = EP_NAME.extensions.firstOrNull()
}
}
+1
View File
@@ -37,5 +37,6 @@
<orderEntry type="library" name="idea-full" level="project" /> <orderEntry type="library" name="idea-full" level="project" />
<orderEntry type="library" name="javaslang" level="project" /> <orderEntry type="library" name="javaslang" level="project" />
<orderEntry type="library" name="kotlin-reflect" level="project" /> <orderEntry type="library" name="kotlin-reflect" level="project" />
<orderEntry type="module" module-name="frontend.script" />
</component> </component>
</module> </module>
+1
View File
@@ -17,5 +17,6 @@
<orderEntry type="module" module-name="j2k" /> <orderEntry type="module" module-name="j2k" />
<orderEntry type="library" scope="PROVIDED" name="gradle-and-groovy-plugin" level="project" /> <orderEntry type="library" scope="PROVIDED" name="gradle-and-groovy-plugin" level="project" />
<orderEntry type="library" exported="" name="kotlinx-coroutines-core" level="project" /> <orderEntry type="library" exported="" name="kotlinx-coroutines-core" level="project" />
<orderEntry type="module" module-name="frontend.script" />
</component> </component>
</module> </module>
+1
View File
@@ -64,5 +64,6 @@
<orderEntry type="module" module-name="kotlin-gradle-tooling" /> <orderEntry type="module" module-name="kotlin-gradle-tooling" />
<orderEntry type="module" module-name="build-common" /> <orderEntry type="module" module-name="build-common" />
<orderEntry type="library" name="kotlinx-coroutines-core" level="project" /> <orderEntry type="library" name="kotlinx-coroutines-core" level="project" />
<orderEntry type="module" module-name="frontend.script" />
</component> </component>
</module> </module>
+2
View File
@@ -43,5 +43,7 @@
interface="org.jetbrains.kotlin.idea.facet.KotlinVersionInfoProvider"/> interface="org.jetbrains.kotlin.idea.facet.KotlinVersionInfoProvider"/>
<extensionPoint name="platformGradleDetector" <extensionPoint name="platformGradleDetector"
interface="org.jetbrains.kotlin.idea.inspections.gradle.KotlinPlatformGradleDetector"/> interface="org.jetbrains.kotlin.idea.inspections.gradle.KotlinPlatformGradleDetector"/>
<extensionPoint name="scriptHelper"
interface="org.jetbrains.kotlin.script.ScriptHelper"/>
</extensionPoints> </extensionPoints>
</idea-plugin> </idea-plugin>
@@ -9,5 +9,7 @@
<classBuilderInterceptorExtension implementation="org.jetbrains.kotlin.annotation.AnnotationCollectorExtension"/> <classBuilderInterceptorExtension implementation="org.jetbrains.kotlin.annotation.AnnotationCollectorExtension"/>
<analyzeCompleteHandlerExtension implementation="org.jetbrains.kotlin.resolve.jvm.AnalyzeCompleteHandlerExtension"/> <analyzeCompleteHandlerExtension implementation="org.jetbrains.kotlin.resolve.jvm.AnalyzeCompleteHandlerExtension"/>
<scriptHelper implementation="org.jetbrains.kotlin.script.ScriptHelperImpl"/>
</extensions> </extensions>
</idea-plugin> </idea-plugin>
+1 -1
View File
@@ -251,7 +251,7 @@
serviceImplementation="org.jetbrains.kotlin.script.KotlinScriptDefinitionProvider"/> serviceImplementation="org.jetbrains.kotlin.script.KotlinScriptDefinitionProvider"/>
<projectService serviceInterface="org.jetbrains.kotlin.script.KotlinScriptExternalImportsProvider" <projectService serviceInterface="org.jetbrains.kotlin.script.KotlinScriptExternalImportsProvider"
serviceImplementation="org.jetbrains.kotlin.script.KotlinScriptExternalImportsProvider"/> serviceImplementation="org.jetbrains.kotlin.script.KotlinScriptExternalImportsProviderImpl"/>
<projectService serviceInterface="org.jetbrains.kotlin.idea.core.script.KotlinScriptConfigurationManager" <projectService serviceInterface="org.jetbrains.kotlin.idea.core.script.KotlinScriptConfigurationManager"
serviceImplementation="org.jetbrains.kotlin.idea.core.script.KotlinScriptConfigurationManager"/> serviceImplementation="org.jetbrains.kotlin.idea.core.script.KotlinScriptConfigurationManager"/>
+1
View File
@@ -40,5 +40,6 @@
<orderEntry type="module" module-name="sam-with-receiver-cli" scope="TEST" /> <orderEntry type="module" module-name="sam-with-receiver-cli" scope="TEST" />
<orderEntry type="module" module-name="allopen-cli" scope="TEST" /> <orderEntry type="module" module-name="allopen-cli" scope="TEST" />
<orderEntry type="module" module-name="noarg-cli" scope="TEST" /> <orderEntry type="module" module-name="noarg-cli" scope="TEST" />
<orderEntry type="module" module-name="frontend.script" />
</component> </component>
</module> </module>
+2
View File
@@ -71,6 +71,7 @@
<root url="file://$PROJECT_DIR$/../out/production/noarg-cli" /> <root url="file://$PROJECT_DIR$/../out/production/noarg-cli" />
<root url="file://$PROJECT_DIR$/../out/production/sam-with-receiver-cli" /> <root url="file://$PROJECT_DIR$/../out/production/sam-with-receiver-cli" />
<root url="file://$PROJECT_DIR$/../out/production/sam-with-receiver-ide" /> <root url="file://$PROJECT_DIR$/../out/production/sam-with-receiver-ide" />
<root url="file://$PROJECT_DIR$/../out/production/frontend.script" />
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES> <SOURCES>
@@ -104,6 +105,7 @@
<root url="file://$PROJECT_DIR$/../idea/idea-live-templates/src" /> <root url="file://$PROJECT_DIR$/../idea/idea-live-templates/src" />
<root url="file://$PROJECT_DIR$/../idea/idea-test-framework/src" /> <root url="file://$PROJECT_DIR$/../idea/idea-test-framework/src" />
<root url="file://$PROJECT_DIR$/../idea/formatter/src" /> <root url="file://$PROJECT_DIR$/../idea/formatter/src" />
<root url="file://$PROJECT_DIR$/../compiler/frontend.script/src" />
</SOURCES> </SOURCES>
</library> </library>
</component> </component>