From af79bbd24746e0dd0e8481c758d9aac5a8c13e33 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Fri, 9 Feb 2018 16:22:31 +0300 Subject: [PATCH] Minor: reformat code --- .../arguments/K2JVMCompilerArguments.kt | 122 +++++++++------ .../jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt | 143 ++++++++++-------- .../kotlin/config/LanguageVersionSettings.kt | 31 ++-- 3 files changed, 169 insertions(+), 127 deletions(-) diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt index 67ed3440d5b..c6275a1953d 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt @@ -23,7 +23,8 @@ import org.jetbrains.kotlin.config.JvmTarget class K2JVMCompilerArguments : CommonCompilerArguments() { companion object { - @JvmStatic private val serialVersionUID = 0L + @JvmStatic + private val serialVersionUID = 0L } @Argument(value = "-d", valueDescription = "", description = "Destination for generated class files") @@ -38,9 +39,9 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { @GradleOption(DefaultValues.StringNullDefault::class) @Argument( - value = "-jdk-home", - valueDescription = "", - description = "Path to JDK home directory to include into classpath, if differs from default JAVA_HOME" + value = "-jdk-home", + valueDescription = "", + description = "Path to JDK home directory to include into classpath, if differs from default JAVA_HOME" ) var jdkHome: String? by FreezableVar(null) @@ -60,9 +61,9 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { var script: Boolean by FreezableVar(false) @Argument( - value = "-script-templates", - valueDescription = "", - description = "Script definition template classes" + value = "-script-templates", + valueDescription = "", + description = "Script definition template classes" ) var scriptTemplates: Array? by FreezableVar(null) @@ -71,9 +72,9 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { @GradleOption(DefaultValues.JvmTargetVersions::class) @Argument( - value = "-jvm-target", - valueDescription = "", - description = "Target version of the generated JVM bytecode (1.6 or 1.8), default is 1.6" + value = "-jvm-target", + valueDescription = "", + description = "Target version of the generated JVM bytecode (1.6 or 1.8), default is 1.6" ) var jvmTarget: String? by FreezableVar(JvmTarget.DEFAULT.description) @@ -87,20 +88,26 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { var javaModulePath: String? by FreezableVar(null) @Argument( - value = "-Xadd-modules", - valueDescription = "", - description = "Root modules to resolve in addition to the initial modules,\n" + - "or all modules on the module path if is ALL-MODULE-PATH" + value = "-Xadd-modules", + valueDescription = "", + description = "Root modules to resolve in addition to the initial modules,\n" + + "or all modules on the module path if is ALL-MODULE-PATH" ) var additionalJavaModules: Array? by FreezableVar(null) @Argument(value = "-Xno-call-assertions", description = "Don't generate not-null assertions for arguments of platform types") var noCallAssertions: Boolean by FreezableVar(false) - @Argument(value = "-Xno-receiver-assertions", description = "Don't generate not-null assertion for extension receiver arguments of platform types") + @Argument( + value = "-Xno-receiver-assertions", + description = "Don't generate not-null assertion for extension receiver arguments of platform types" + ) var noReceiverAssertions: Boolean by FreezableVar(false) - @Argument(value = "-Xno-param-assertions", description = "Don't generate not-null assertions on parameters of methods accessible from Java") + @Argument( + value = "-Xno-param-assertions", + description = "Don't generate not-null assertions on parameters of methods accessible from Java" + ) var noParamAssertions: Boolean by FreezableVar(false) @Argument(value = "-Xstrict-java-nullability-assertions", description = "Generate nullability assertions for non-null Java expressions") @@ -110,51 +117,65 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { var noOptimize: Boolean by FreezableVar(false) @Argument( - value = "-Xnormalize-constructor-calls", - valueDescription = "{disable|enable}", - description = "Normalize constructor calls (disable: don't normalize; enable: normalize), default is disable" + value = "-Xnormalize-constructor-calls", + valueDescription = "{disable|enable}", + description = "Normalize constructor calls (disable: don't normalize; enable: normalize), default is disable" ) var constructorCallNormalizationMode: String? by FreezableVar(JVMConstructorCallNormalizationMode.DEFAULT.description) @Argument(value = "-Xreport-perf", description = "Report detailed performance statistics") var reportPerf: Boolean by FreezableVar(false) - @Argument(value = "-Xbuild-file", deprecatedName = "-module", valueDescription = "", description = "Path to the .xml build file to compile") + @Argument( + value = "-Xbuild-file", + deprecatedName = "-module", + valueDescription = "", + description = "Path to the .xml build file to compile" + ) var buildFile: String? by FreezableVar(null) @Argument(value = "-Xmultifile-parts-inherit", description = "Compile multifile classes as a hierarchy of parts and facade") var inheritMultifileParts: Boolean by FreezableVar(false) - @Argument(value = "-Xskip-runtime-version-check", description = "Allow Kotlin runtime libraries of incompatible versions in the classpath") + @Argument( + value = "-Xskip-runtime-version-check", + description = "Allow Kotlin runtime libraries of incompatible versions in the classpath" + ) var skipRuntimeVersionCheck: Boolean by FreezableVar(false) @Argument( - value = "-Xuse-old-class-files-reading", - description = "Use old class files reading implementation " + - "(may slow down the build and should be used in case of problems with the new implementation)" + value = "-Xuse-old-class-files-reading", + description = "Use old class files reading implementation " + + "(may slow down the build and should be used in case of problems with the new implementation)" ) var useOldClassFilesReading: Boolean by FreezableVar(false) @Argument( - value = "-Xdump-declarations-to", - valueDescription = "", - description = "Path to JSON file to dump Java to Kotlin declaration mappings" + value = "-Xdump-declarations-to", + valueDescription = "", + description = "Path to JSON file to dump Java to Kotlin declaration mappings" ) var declarationsOutputPath: String? by FreezableVar(null) @Argument(value = "-Xsingle-module", description = "Combine modules for source files and binary dependencies into a single module") var singleModule: Boolean by FreezableVar(false) - @Argument(value = "-Xadd-compiler-builtins", description = "Add definitions of built-in declarations to the compilation classpath (useful with -no-stdlib)") + @Argument( + value = "-Xadd-compiler-builtins", + description = "Add definitions of built-in declarations to the compilation classpath (useful with -no-stdlib)" + ) var addCompilerBuiltIns: Boolean by FreezableVar(false) - @Argument(value = "-Xload-builtins-from-dependencies", description = "Load definitions of built-in declarations from module dependencies, instead of from the compiler") + @Argument( + value = "-Xload-builtins-from-dependencies", + description = "Load definitions of built-in declarations from module dependencies, instead of from the compiler" + ) var loadBuiltInsFromDependencies: Boolean by FreezableVar(false) @Argument( - value = "-Xscript-resolver-environment", - valueDescription = "", - description = "Script resolver environment in key-value pairs (the value could be quoted and escaped)" + value = "-Xscript-resolver-environment", + valueDescription = "", + description = "Script resolver environment in key-value pairs (the value could be quoted and escaped)" ) var scriptResolverEnvironment: Array? by FreezableVar(null) @@ -166,25 +187,26 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { var compileJava by FreezableVar(false) @Argument( - value = "-Xjavac-arguments", - valueDescription = "", - description = "Java compiler arguments") + value = "-Xjavac-arguments", + valueDescription = "", + description = "Java compiler arguments" + ) var javacArguments: Array? by FreezableVar(null) @Argument( - value = "-Xjsr305", - deprecatedName = "-Xjsr305-annotations", - valueDescription = "{ignore/strict/warn}" + - "|under-migration:{ignore/strict/warn}" + - "|@:{ignore/strict/warn}", - description = "Specify behavior for JSR-305 nullability annotations:\n" + - "-Xjsr305={ignore/strict/warn} globally (all non-@UnderMigration annotations)\n" + - "-Xjsr305=under-migration:{ignore/strict/warn} all @UnderMigration annotations\n" + - "-Xjsr305=@:{ignore/strict/warn} annotation with the given fully qualified class name\n" + - "Modes:\n" + - " * ignore\n" + - " * strict (experimental; treat as other supported nullability annotations)\n" + - " * warn (report a warning)" + value = "-Xjsr305", + deprecatedName = "-Xjsr305-annotations", + valueDescription = "{ignore/strict/warn}" + + "|under-migration:{ignore/strict/warn}" + + "|@:{ignore/strict/warn}", + description = "Specify behavior for JSR-305 nullability annotations:\n" + + "-Xjsr305={ignore/strict/warn} globally (all non-@UnderMigration annotations)\n" + + "-Xjsr305=under-migration:{ignore/strict/warn} all @UnderMigration annotations\n" + + "-Xjsr305=@:{ignore/strict/warn} annotation with the given fully qualified class name\n" + + "Modes:\n" + + " * ignore\n" + + " * strict (experimental; treat as other supported nullability annotations)\n" + + " * warn (report a warning)" ) var jsr305: Array? by FreezableVar(null) @@ -197,8 +219,8 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { var supportCompatqualCheckerFrameworkAnnotations: String? by FreezableVar(null) @Argument( - value = "-Xno-exception-on-explicit-equals-for-boxed-null", - description = "Do not throw NPE on explicit 'equals' call for null receiver of platform boxed primitive type" + value = "-Xno-exception-on-explicit-equals-for-boxed-null", + description = "Do not throw NPE on explicit 'equals' call for null receiver of platform boxed primitive type" ) var noExceptionOnExplicitEqualsForBoxedNull by FreezableVar(false) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt index c351a6ede67..32c33540b0d 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt @@ -62,10 +62,10 @@ import java.util.concurrent.TimeUnit class K2JVMCompiler : CLICompiler() { override fun doExecute( - arguments: K2JVMCompilerArguments, - configuration: CompilerConfiguration, - rootDisposable: Disposable, - paths: KotlinPaths? + arguments: K2JVMCompilerArguments, + configuration: CompilerConfiguration, + rootDisposable: Disposable, + paths: KotlinPaths? ): ExitCode { PerformanceCounter.setTimeCounterEnabled(arguments.reportPerf) @@ -83,8 +83,7 @@ class K2JVMCompiler : CLICompiler() { val file = File(arg) if (file.extension == JavaFileType.DEFAULT_EXTENSION) { configuration.addJavaSourceRoot(file) - } - else { + } else { configuration.addKotlinSourceRoot(arg) if (file.isDirectory) { configuration.addJavaSourceRoot(file) @@ -120,10 +119,11 @@ class K2JVMCompiler : CLICompiler() { val jvmTarget = JvmTarget.fromString(arguments.jvmTarget!!) if (jvmTarget != null) { configuration.put(JVMConfigurationKeys.JVM_TARGET, jvmTarget) - } - else { - messageCollector.report(ERROR, "Unknown JVM target version: ${arguments.jvmTarget}\n" + - "Supported versions: ${JvmTarget.values().joinToString { it.description }}") + } else { + messageCollector.report( + ERROR, "Unknown JVM target version: ${arguments.jvmTarget}\n" + + "Supported versions: ${JvmTarget.values().joinToString { it.description }}" + ) } } @@ -138,8 +138,8 @@ class K2JVMCompiler : CLICompiler() { if (arguments.buildFile != null) { if (destination != null) { messageCollector.report( - STRONG_WARNING, - "The '-d' option with a directory destination is ignored because '-Xbuild-file' is specified" + STRONG_WARNING, + "The '-d' option with a directory destination is ignored because '-Xbuild-file' is specified" ) } @@ -152,48 +152,45 @@ class K2JVMCompiler : CLICompiler() { KotlinToJVMBytecodeCompiler.configureSourceRoots(configuration, moduleChunk.modules, buildFile) val environment = createCoreEnvironment(rootDisposable, configuration, arguments, messageCollector) - ?: return COMPILATION_ERROR + ?: return COMPILATION_ERROR registerJavacIfNeeded(environment, arguments).let { if (!it) return COMPILATION_ERROR } KotlinToJVMBytecodeCompiler.compileModules(environment, buildFile, moduleChunk.modules) - } - else if (arguments.script) { + } else if (arguments.script) { val sourcePath = arguments.freeArgs.first() configuration.addKotlinSourceRoot(sourcePath) configuration.put(JVMConfigurationKeys.RETAIN_OUTPUT_IN_MEMORY, true) val environment = createCoreEnvironment(rootDisposable, configuration, arguments, messageCollector) - ?: return COMPILATION_ERROR + ?: return COMPILATION_ERROR val scriptDefinitionProvider = ScriptDefinitionProvider.getInstance(environment.project) val scriptFile = File(sourcePath) if (scriptFile.isDirectory || !scriptDefinitionProvider.isScript(scriptFile.name)) { val extensionHint = - if (configuration.get(JVMConfigurationKeys.SCRIPT_DEFINITIONS) == listOf(StandardScriptDefinition)) " (.kts)" - else "" + if (configuration.get(JVMConfigurationKeys.SCRIPT_DEFINITIONS) == listOf(StandardScriptDefinition)) " (.kts)" + else "" messageCollector.report(ERROR, "Specify path to the script file$extensionHint as the first argument") return COMPILATION_ERROR } val scriptArgs = arguments.freeArgs.subList(1, arguments.freeArgs.size) return KotlinToJVMBytecodeCompiler.compileAndExecuteScript(environment, scriptArgs) - } - else { + } else { if (destination != null) { if (destination.endsWith(".jar")) { configuration.put(JVMConfigurationKeys.OUTPUT_JAR, File(destination)) - } - else { + } else { configuration.put(JVMConfigurationKeys.OUTPUT_DIRECTORY, File(destination)) } } val environment = createCoreEnvironment(rootDisposable, configuration, arguments, messageCollector) - ?: return COMPILATION_ERROR + ?: return COMPILATION_ERROR registerJavacIfNeeded(environment, arguments).let { if (!it) return COMPILATION_ERROR @@ -220,20 +217,19 @@ class K2JVMCompiler : CLICompiler() { PerformanceCounter.report { s -> reportPerf(configuration, s) } } return OK - } - catch (e: CompilationException) { + } catch (e: CompilationException) { messageCollector.report( - EXCEPTION, - OutputMessageUtil.renderException(e), - MessageUtil.psiElementToMessageLocation(e.element) + EXCEPTION, + OutputMessageUtil.renderException(e), + MessageUtil.psiElementToMessageLocation(e.element) ) return INTERNAL_ERROR } } override fun setupPlatformSpecificLanguageFeatureSettings( - extraLanguageFeatures: MutableMap, - commandLineArguments: K2JVMCompilerArguments + extraLanguageFeatures: MutableMap, + commandLineArguments: K2JVMCompilerArguments ) { if (commandLineArguments.strictJavaNullabilityAssertions) { extraLanguageFeatures[LanguageFeature.StrictJavaNullabilityAssertions] = LanguageFeature.State.ENABLED @@ -242,8 +238,10 @@ class K2JVMCompiler : CLICompiler() { super.setupPlatformSpecificLanguageFeatureSettings(extraLanguageFeatures, commandLineArguments) } - private fun registerJavacIfNeeded(environment: KotlinCoreEnvironment, - arguments: K2JVMCompilerArguments): Boolean { + private fun registerJavacIfNeeded( + environment: KotlinCoreEnvironment, + arguments: K2JVMCompilerArguments + ): Boolean { if (arguments.useJavac) { environment.configuration.put(JVMConfigurationKeys.USE_JAVAC, true) if (arguments.compileJava) { @@ -255,8 +253,10 @@ class K2JVMCompiler : CLICompiler() { return true } - private fun compileJavaFilesIfNeeded(environment: KotlinCoreEnvironment, - arguments: K2JVMCompilerArguments): Boolean { + private fun compileJavaFilesIfNeeded( + environment: KotlinCoreEnvironment, + arguments: K2JVMCompilerArguments + ): Boolean { if (arguments.compileJava) { return JavacWrapper.getInstance(environment.project).use { it.compile() } } @@ -264,10 +264,10 @@ class K2JVMCompiler : CLICompiler() { } private fun createCoreEnvironment( - rootDisposable: Disposable, - configuration: CompilerConfiguration, - arguments: K2JVMCompilerArguments, - messageCollector: MessageCollector + rootDisposable: Disposable, + configuration: CompilerConfiguration, + arguments: K2JVMCompilerArguments, + messageCollector: MessageCollector ): KotlinCoreEnvironment? { val scriptResolverEnv = createScriptResolverEnvironment(arguments, messageCollector) ?: return null configureScriptDefinitions(arguments.scriptTemplates, configuration, messageCollector, scriptResolverEnv) @@ -290,7 +290,7 @@ class K2JVMCompiler : CLICompiler() { } override fun setupPlatformSpecificArgumentsAndServices( - configuration: CompilerConfiguration, arguments: K2JVMCompilerArguments, services: Services + configuration: CompilerConfiguration, arguments: K2JVMCompilerArguments, services: Services ) { if (IncrementalCompilation.isEnabled()) { services.get(LookupTracker::class.java)?.let { @@ -335,7 +335,8 @@ class K2JVMCompiler : CLICompiler() { } } - @JvmStatic fun main(args: Array) { + @JvmStatic + fun main(args: Array) { CLITool.doMain(K2JVMCompiler(), args) } @@ -366,17 +367,25 @@ class K2JVMCompiler : CLICompiler() { configuration.put(JVMConfigurationKeys.DISABLE_CALL_ASSERTIONS, arguments.noCallAssertions) configuration.put(JVMConfigurationKeys.DISABLE_RECEIVER_ASSERTIONS, arguments.noReceiverAssertions) configuration.put(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS, arguments.noParamAssertions) - configuration.put(JVMConfigurationKeys.NO_EXCEPTION_ON_EXPLICIT_EQUALS_FOR_BOXED_NULL, arguments.noExceptionOnExplicitEqualsForBoxedNull) + configuration.put( + JVMConfigurationKeys.NO_EXCEPTION_ON_EXPLICIT_EQUALS_FOR_BOXED_NULL, + arguments.noExceptionOnExplicitEqualsForBoxedNull + ) configuration.put(JVMConfigurationKeys.DISABLE_OPTIMIZATION, arguments.noOptimize) - val constructorCallNormalizationMode = JVMConstructorCallNormalizationMode.fromStringOrNull(arguments.constructorCallNormalizationMode) + val constructorCallNormalizationMode = + JVMConstructorCallNormalizationMode.fromStringOrNull(arguments.constructorCallNormalizationMode) if (constructorCallNormalizationMode == null) { - configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY) - .report(ERROR, "Unknown constructor call normalization mode: ${arguments.constructorCallNormalizationMode}, " + - "supported modes: ${JVMConstructorCallNormalizationMode.values().map { it.description }}") + configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report( + ERROR, + "Unknown constructor call normalization mode: ${arguments.constructorCallNormalizationMode}, " + + "supported modes: ${JVMConstructorCallNormalizationMode.values().map { it.description }}" + ) } - configuration.put(JVMConfigurationKeys.CONSTRUCTOR_CALL_NORMALIZATION_MODE, - constructorCallNormalizationMode ?: JVMConstructorCallNormalizationMode.DEFAULT) + configuration.put( + JVMConfigurationKeys.CONSTRUCTOR_CALL_NORMALIZATION_MODE, + constructorCallNormalizationMode ?: JVMConstructorCallNormalizationMode.DEFAULT + ) configuration.put(JVMConfigurationKeys.INHERIT_MULTIFILE_PARTS, arguments.inheritMultifileParts) configuration.put(JVMConfigurationKeys.SKIP_RUNTIME_VERSION_CHECK, arguments.skipRuntimeVersionCheck) @@ -384,7 +393,7 @@ class K2JVMCompiler : CLICompiler() { if (arguments.useOldClassFilesReading) { configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY) - .report(INFO, "Using the old java class files reading implementation") + .report(INFO, "Using the old java class files reading implementation") } configuration.put(CLIConfigurationKeys.ALLOW_KOTLIN_PACKAGE, arguments.allowKotlinPackage) @@ -412,8 +421,7 @@ class K2JVMCompiler : CLICompiler() { if (isModularJava) { configuration.add(JVMConfigurationKeys.CONTENT_ROOTS, JvmModulePathRoot(file)) configuration.add(JVMConfigurationKeys.ADDITIONAL_JAVA_MODULES, moduleName) - } - else { + } else { configuration.add(JVMConfigurationKeys.CONTENT_ROOTS, JvmClasspathRoot(file)) } } @@ -429,7 +437,11 @@ class K2JVMCompiler : CLICompiler() { } } - private fun configureJdkHome(arguments: K2JVMCompilerArguments, configuration: CompilerConfiguration, messageCollector: MessageCollector): ExitCode { + private fun configureJdkHome( + arguments: K2JVMCompilerArguments, + configuration: CompilerConfiguration, + messageCollector: MessageCollector + ): ExitCode { if (arguments.noJdk) { configuration.put(JVMConfigurationKeys.NO_JDK, true) @@ -454,14 +466,17 @@ class K2JVMCompiler : CLICompiler() { return OK } - fun configureScriptDefinitions(scriptTemplates: Array?, - configuration: CompilerConfiguration, - messageCollector: MessageCollector, - scriptResolverEnv: HashMap) { + fun configureScriptDefinitions( + scriptTemplates: Array?, + configuration: CompilerConfiguration, + messageCollector: MessageCollector, + scriptResolverEnv: HashMap + ) { val classpath = configuration.jvmClasspathRoots // TODO: consider using escaping to allow kotlin escaped names in class names if (scriptTemplates != null && scriptTemplates.isNotEmpty()) { - val classloader = URLClassLoader(classpath.map { it.toURI().toURL() }.toTypedArray(), Thread.currentThread().contextClassLoader) + val classloader = + URLClassLoader(classpath.map { it.toURI().toURL() }.toTypedArray(), Thread.currentThread().contextClassLoader) var hasErrors = false for (template in scriptTemplates) { try { @@ -469,16 +484,14 @@ class K2JVMCompiler : CLICompiler() { val def = KotlinScriptDefinitionFromAnnotatedTemplate(cls.kotlin, scriptResolverEnv) configuration.add(JVMConfigurationKeys.SCRIPT_DEFINITIONS, def) messageCollector.report( - INFO, - "Added script definition $template to configuration: files pattern = \"${def.scriptFilePattern}\", " + - "resolver = ${def.dependencyResolver.javaClass.name}" + INFO, + "Added script definition $template to configuration: files pattern = \"${def.scriptFilePattern}\", " + + "resolver = ${def.dependencyResolver.javaClass.name}" ) - } - catch (ex: ClassNotFoundException) { + } catch (ex: ClassNotFoundException) { messageCollector.report(ERROR, "Cannot find script definition template class $template") hasErrors = true - } - catch (ex: Exception) { + } catch (ex: Exception) { messageCollector.report(ERROR, "Error processing script definition template $template: ${ex.message}") hasErrors = true break @@ -507,7 +520,9 @@ class K2JVMCompiler : CLICompiler() { messageCollector.report(ERROR, "Unable to parse script-resolver-environment argument $envParam") return null } - scriptResolverEnv.put(match.groupValues[1], match.groupValues.drop(2).firstOrNull { it.isNotEmpty() }?.let { unescapeRe.replace(it, "\$1") }) + scriptResolverEnv.put( + match.groupValues[1], + match.groupValues.drop(2).firstOrNull { it.isNotEmpty() }?.let { unescapeRe.replace(it, "\$1") }) } } return scriptResolverEnv diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index a7f1ac8baf4..03056a3e3a3 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -10,10 +10,10 @@ import org.jetbrains.kotlin.utils.DescriptionAware import java.util.* enum class LanguageFeature( - val sinceVersion: LanguageVersion?, - val sinceApiVersion: ApiVersion = ApiVersion.KOTLIN_1_0, - val hintUrl: String? = null, - val defaultState: State = State.ENABLED + val sinceVersion: LanguageVersion?, + val sinceApiVersion: ApiVersion = ApiVersion.KOTLIN_1_0, + val hintUrl: String? = null, + val defaultState: State = State.ENABLED ) { // Note: names of these entries are also used in diagnostic tests and in user-visible messages (see presentableText below) TypeAliases(KOTLIN_1_1), @@ -77,7 +77,11 @@ enum class LanguageFeature( // Experimental features - Coroutines(KOTLIN_1_1, ApiVersion.KOTLIN_1_1, "https://kotlinlang.org/docs/diagnostics/experimental-coroutines", State.ENABLED_WITH_WARNING), + Coroutines( + KOTLIN_1_1, ApiVersion.KOTLIN_1_1, + "https://kotlinlang.org/docs/diagnostics/experimental-coroutines", + State.ENABLED_WITH_WARNING + ), MultiPlatformProjects(sinceVersion = null, defaultState = State.DISABLED), @@ -86,7 +90,7 @@ enum class LanguageFeature( ; val presentableName: String - // E.g. "DestructuringLambdaParameters" -> ["Destructuring", "Lambda", "Parameters"] -> "destructuring lambda parameters" + // E.g. "DestructuringLambdaParameters" -> ["Destructuring", "Lambda", "Parameters"] -> "destructuring lambda parameters" get() = name.split("(?= 2) fromVersionString("${it[0]}.${it[1]}") else null } + fun fromFullVersionString(str: String) = + str.split(".", "-").let { if (it.size >= 2) fromVersionString("${it[0]}.${it[1]}") else null } @JvmField val LATEST_STABLE = KOTLIN_1_2 @@ -137,7 +142,7 @@ interface LanguageVersionSettings { fun getFeatureSupport(feature: LanguageFeature): LanguageFeature.State fun supportsFeature(feature: LanguageFeature): Boolean = - getFeatureSupport(feature).let { it == LanguageFeature.State.ENABLED || it == LanguageFeature.State.ENABLED_WITH_WARNING } + getFeatureSupport(feature).let { it == LanguageFeature.State.ENABLED || it == LanguageFeature.State.ENABLED_WITH_WARNING } fun getFlag(flag: AnalysisFlag): T @@ -148,10 +153,10 @@ interface LanguageVersionSettings { } class LanguageVersionSettingsImpl @JvmOverloads constructor( - override val languageVersion: LanguageVersion, - override val apiVersion: ApiVersion, - analysisFlags: Map, Any?> = emptyMap(), - specificFeatures: Map = emptyMap() + override val languageVersion: LanguageVersion, + override val apiVersion: ApiVersion, + analysisFlags: Map, Any?> = emptyMap(), + specificFeatures: Map = emptyMap() ) : LanguageVersionSettings { private val analysisFlags: Map, *> = Collections.unmodifiableMap(analysisFlags) private val specificFeatures: Map = Collections.unmodifiableMap(specificFeatures) @@ -189,7 +194,7 @@ class LanguageVersionSettingsImpl @JvmOverloads constructor( } fun LanguageVersionSettings.isPreRelease(): Boolean = - languageVersion.isPreRelease() + languageVersion.isPreRelease() fun LanguageVersion.isPreRelease(): Boolean { if (!isStable) return true