Script IDE API: remove <TF: Any>
This commit is contained in:
@@ -43,7 +43,7 @@ public class KotlinParser implements PsiParser {
|
||||
@NotNull
|
||||
public ASTNode parse(IElementType iElementType, PsiBuilder psiBuilder, PsiFile psiFile) {
|
||||
KotlinParsing ktParsing = KotlinParsing.createForTopLevel(new SemanticWhitespaceAwarePsiBuilderImpl(psiBuilder));
|
||||
if (scriptDefinitionProvider != null && scriptDefinitionProvider.isScript(psiFile)
|
||||
if (scriptDefinitionProvider != null && scriptDefinitionProvider.isScript(psiFile.getName())
|
||||
|| psiFile.getName().endsWith(KotlinParserDefinition.STD_SCRIPT_EXT)) {
|
||||
ktParsing.parseScript();
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.script
|
||||
|
||||
import com.intellij.openapi.fileTypes.LanguageFileType
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.NameUtils
|
||||
@@ -38,14 +39,14 @@ open class KotlinScriptDefinition(val template: KClass<out Any>) {
|
||||
open val annotationsForSamWithReceivers: List<String>
|
||||
get() = emptyList()
|
||||
|
||||
open fun <TF : Any> isScript(file: TF): Boolean =
|
||||
getFileName(file).endsWith(KotlinParserDefinition.STD_SCRIPT_EXT)
|
||||
open fun isScript(fileName: String): Boolean =
|
||||
fileName.endsWith(KotlinParserDefinition.STD_SCRIPT_EXT)
|
||||
|
||||
open fun getScriptName(script: KtScript): Name =
|
||||
NameUtils.getScriptNameForFile(script.containingKtFile.name)
|
||||
|
||||
@Deprecated("Use dependencyResolver instead", level = DeprecationLevel.ERROR)
|
||||
open fun <TF : Any> getDependenciesFor(file: TF, project: Project, previousDependencies: KotlinScriptExternalDependencies?): KotlinScriptExternalDependencies? = null
|
||||
open fun getDependenciesFor(file: VirtualFile, project: Project, previousDependencies: KotlinScriptExternalDependencies?): KotlinScriptExternalDependencies? = null
|
||||
|
||||
open val dependencyResolver: ScriptDependenciesResolver = EmptyDependencyResolver
|
||||
|
||||
|
||||
@@ -43,11 +43,15 @@ class KotlinScriptDefinitionProvider {
|
||||
return changed
|
||||
}
|
||||
|
||||
fun<TF: Any> findScriptDefinition(file: TF): KotlinScriptDefinition? = definitionsLock.read {
|
||||
definitions.firstOrNull { it.isScript(file) }
|
||||
fun findScriptDefinition(file: VirtualFile): KotlinScriptDefinition? = findScriptDefinition(file.name)
|
||||
|
||||
fun findScriptDefinition(fileName: String): KotlinScriptDefinition? = definitionsLock.read {
|
||||
definitions.firstOrNull { it.isScript(fileName) }
|
||||
}
|
||||
|
||||
fun<TF: Any> isScript(file: TF): Boolean = findScriptDefinition(file) != null
|
||||
fun isScript(fileName: String): Boolean = definitionsLock.read {
|
||||
definitions.any { it.isScript(fileName) }
|
||||
}
|
||||
|
||||
fun addScriptDefinition(scriptDefinition: KotlinScriptDefinition) {
|
||||
definitionsLock.write {
|
||||
@@ -76,4 +80,4 @@ fun getScriptDefinition(file: VirtualFile, project: Project): KotlinScriptDefini
|
||||
KotlinScriptDefinitionProvider.getInstance(project)?.findScriptDefinition(file)
|
||||
|
||||
fun getScriptDefinition(psiFile: PsiFile): KotlinScriptDefinition? =
|
||||
KotlinScriptDefinitionProvider.getInstance(psiFile.project)?.findScriptDefinition(psiFile)
|
||||
KotlinScriptDefinitionProvider.getInstance(psiFile.project)?.findScriptDefinition(psiFile.name)
|
||||
|
||||
+3
-1
@@ -19,10 +19,12 @@ package org.jetbrains.kotlin.script
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiFile
|
||||
import kotlin.script.dependencies.KotlinScriptExternalDependencies
|
||||
|
||||
interface KotlinScriptExternalImportsProvider {
|
||||
fun <TF: Any> getScriptDependencies(file: TF): KotlinScriptExternalDependencies?
|
||||
fun getScriptDependencies(file: VirtualFile): KotlinScriptExternalDependencies?
|
||||
fun getScriptDependencies(file: PsiFile) = getScriptDependencies(file.virtualFile)
|
||||
|
||||
companion object {
|
||||
fun getInstance(project: Project): KotlinScriptExternalImportsProvider =
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* 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.script
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.psi.PsiFile
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
|
||||
fun <TF: Any> getFileName(file: TF): String = when (file) {
|
||||
is PsiFile -> file.originalFile.name
|
||||
is VirtualFile -> file.name
|
||||
is File -> file.name
|
||||
else -> throw IllegalArgumentException("Unsupported file type $file")
|
||||
}
|
||||
|
||||
fun <TF: Any> getFilePath(file: TF): String = when (file) {
|
||||
is PsiFile -> file.originalFile.run { virtualFile?.path ?: name } // TODO: replace name with path of PSI elements
|
||||
is VirtualFile -> file.path
|
||||
is File -> file.canonicalPath
|
||||
else -> throw IllegalArgumentException("Unsupported file type $file")
|
||||
}
|
||||
|
||||
fun <TF: Any> isValidFile(file: TF): Boolean = when (file) {
|
||||
is PsiFile -> file.isValid
|
||||
is VirtualFile -> file.isValid
|
||||
is File -> file.exists() && file.isFile
|
||||
else -> throw IllegalArgumentException("Unsupported file type $file")
|
||||
}
|
||||
|
||||
fun <TF: Any> getFile(file: TF): File? = when (file) {
|
||||
is PsiFile -> file.originalFile.run { File(virtualFile?.path) }
|
||||
is VirtualFile -> File(file.path)
|
||||
is File -> file
|
||||
else -> throw IllegalArgumentException("Unsupported file type $file")
|
||||
}
|
||||
|
||||
fun <TF: Any> getFileContents(file: TF): CharSequence = when (file) {
|
||||
is PsiFile -> file.viewProvider.contents
|
||||
is VirtualFile -> file.inputStream.reader(charset = file.charset).readText()
|
||||
is File -> file.readText()
|
||||
else -> throw IllegalArgumentException("Unsupported file type $file")
|
||||
}
|
||||
|
||||
fun <TF: Any> getFileContentsStream(file: TF): InputStream = when (file) {
|
||||
is PsiFile -> file.viewProvider.contents.toString().byteInputStream()
|
||||
is VirtualFile -> file.inputStream
|
||||
is File -> file.inputStream()
|
||||
else -> throw IllegalArgumentException("Unsupported file type $file")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user