From 487f3812879fd8bc6d7484fb0fa6142189c3fc71 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Wed, 20 Aug 2014 13:45:52 +0400 Subject: [PATCH] Minor. Renamed and cleaned CompilerServices -> Services. --- .../jet/buildtools/ant/Kotlin2JsCompilerTask.kt | 4 ++-- .../jetbrains/jet/cli/common/CLICompiler.java | 14 ++++++-------- .../org/jetbrains/jet/cli/js/K2JSCompiler.java | 4 ++-- .../org/jetbrains/jet/cli/jvm/K2JVMCompiler.java | 4 ++-- .../config/{CompilerServices.kt => Services.kt} | 16 ++++++++-------- .../jet/compiler/runner/CompilerEnvironment.java | 14 +++++++------- .../jetbrains/jet/jps/build/KotlinBuilder.java | 4 ++-- .../org/jetbrains/kotlin/gradle/tasks/Tasks.kt | 4 ++-- .../kotlin/maven/KotlinCompileMojoBase.java | 4 ++-- 9 files changed, 33 insertions(+), 35 deletions(-) rename compiler/util/src/org/jetbrains/jet/config/{CompilerServices.kt => Services.kt} (79%) diff --git a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsCompilerTask.kt b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsCompilerTask.kt index 17e80ed281b..4801456d017 100644 --- a/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsCompilerTask.kt +++ b/build-tools/ant/src/org/jetbrains/jet/buildtools/ant/Kotlin2JsCompilerTask.kt @@ -26,7 +26,7 @@ import org.jetbrains.jet.cli.js.K2JSCompiler import java.io.File import org.apache.tools.ant.BuildException import org.jetbrains.jet.cli.common.ExitCode -import org.jetbrains.jet.config.CompilerServices +import org.jetbrains.jet.config.Services /** * Kotlin JavaScript compiler Ant task. @@ -90,7 +90,7 @@ public class Kotlin2JsCompilerTask : Task() { log("Compiling ${arguments.freeArgs} => [${arguments.outputFile}]"); val compiler = K2JSCompiler() - val exitCode = compiler.exec(MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR, CompilerServices.empty, arguments) + val exitCode = compiler.exec(MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR, Services.EMPTY, arguments) if (exitCode != ExitCode.OK) { throw BuildException("Compilation finished with exit code $exitCode") diff --git a/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java index 6401b6043e8..893322b1732 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/common/CLICompiler.java @@ -27,12 +27,10 @@ import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments; import org.jetbrains.jet.cli.common.messages.*; import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException; import org.jetbrains.jet.config.CompilerConfiguration; -import org.jetbrains.jet.config.CompilerServices; +import org.jetbrains.jet.config.Services; import java.io.PrintStream; -import java.util.Collections; import java.util.List; -import java.util.Map; import static org.jetbrains.jet.cli.common.ExitCode.*; @@ -51,12 +49,12 @@ public abstract class CLICompiler { @NotNull public ExitCode exec(@NotNull PrintStream errStream, @NotNull String... args) { - return exec(errStream, new CompilerServices.Builder().build(), MessageRenderer.PLAIN_WITH_RELATIVE_PATH, args); + return exec(errStream, Services.EMPTY, MessageRenderer.PLAIN_WITH_RELATIVE_PATH, args); } @SuppressWarnings("UnusedDeclaration") // Used via reflection in CompilerRunnerUtil#invokeExecMethod @NotNull - public ExitCode execAndOutputHtml(@NotNull PrintStream errStream, @NotNull CompilerServices services, @NotNull String... args) { + public ExitCode execAndOutputHtml(@NotNull PrintStream errStream, @NotNull Services services, @NotNull String... args) { return exec(errStream, services, MessageRenderer.TAGS, args); } @@ -102,7 +100,7 @@ public abstract class CLICompiler { @NotNull private ExitCode exec( @NotNull PrintStream errStream, - @NotNull CompilerServices services, + @NotNull Services services, @NotNull MessageRenderer messageRenderer, @NotNull String[] args ) { @@ -135,7 +133,7 @@ public abstract class CLICompiler { } @NotNull - public ExitCode exec(@NotNull MessageCollector messageCollector, @NotNull CompilerServices services, @NotNull A arguments) { + public ExitCode exec(@NotNull MessageCollector messageCollector, @NotNull Services services, @NotNull A arguments) { GroupingMessageCollector groupingCollector = new GroupingMessageCollector(messageCollector); try { Disposable rootDisposable = Disposer.newDisposable(); @@ -161,7 +159,7 @@ public abstract class CLICompiler { @NotNull protected abstract ExitCode doExecute( @NotNull A arguments, - @NotNull CompilerServices services, + @NotNull Services services, @NotNull MessageCollector messageCollector, @NotNull Disposable rootDisposable ); diff --git a/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java index 2c906af07fb..7e035b3c5b4 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java @@ -42,7 +42,7 @@ import org.jetbrains.jet.cli.common.output.outputUtils.OutputUtilsPackage; import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment; import org.jetbrains.jet.config.CommonConfigurationKeys; import org.jetbrains.jet.config.CompilerConfiguration; -import org.jetbrains.jet.config.CompilerServices; +import org.jetbrains.jet.config.Services; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.k2js.analyze.AnalyzerFacadeForJS; import org.jetbrains.k2js.config.*; @@ -74,7 +74,7 @@ public class K2JSCompiler extends CLICompiler { @Override protected ExitCode doExecute( @NotNull K2JSCompilerArguments arguments, - @NotNull CompilerServices services, + @NotNull Services services, @NotNull MessageCollector messageCollector, @NotNull Disposable rootDisposable ) { diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java index 2b17ea79307..17c10f5fb0d 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java @@ -34,7 +34,7 @@ import org.jetbrains.jet.cli.jvm.repl.ReplFromTerminal; import org.jetbrains.jet.codegen.CompilationException; import org.jetbrains.jet.config.CommonConfigurationKeys; import org.jetbrains.jet.config.CompilerConfiguration; -import org.jetbrains.jet.config.CompilerServices; +import org.jetbrains.jet.config.Services; import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter; import org.jetbrains.jet.lang.resolve.kotlin.incremental.cache.IncrementalCacheProvider; import org.jetbrains.jet.utils.KotlinPaths; @@ -59,7 +59,7 @@ public class K2JVMCompiler extends CLICompiler { @NotNull protected ExitCode doExecute( @NotNull K2JVMCompilerArguments arguments, - @NotNull CompilerServices services, + @NotNull Services services, @NotNull MessageCollector messageCollector, @NotNull Disposable rootDisposable ) { diff --git a/compiler/util/src/org/jetbrains/jet/config/CompilerServices.kt b/compiler/util/src/org/jetbrains/jet/config/Services.kt similarity index 79% rename from compiler/util/src/org/jetbrains/jet/config/CompilerServices.kt rename to compiler/util/src/org/jetbrains/jet/config/Services.kt index 45c24b15966..e9cedad57ea 100644 --- a/compiler/util/src/org/jetbrains/jet/config/CompilerServices.kt +++ b/compiler/util/src/org/jetbrains/jet/config/Services.kt @@ -18,13 +18,18 @@ package org.jetbrains.jet.config import java.util.HashMap -public class CompilerServices private(private val map: Map, Any>) { +public class Services private(private val map: Map, Any>) { + class object { + public val EMPTY: Services = Builder().build() + } public fun get(interfaceClass: Class): T { + [suppress("UNCHECKED_CAST")] return map.get(interfaceClass) as T } public class Builder { + private val map = HashMap, Any>() public fun register(interfaceClass: Class, implementation: T): Builder { @@ -32,13 +37,8 @@ public class CompilerServices private(private val map: Map, Any>) { return this } - public fun build(): CompilerServices { - return CompilerServices(map) + public fun build(): Services { + return Services(map) } } - - public class object { - public val empty: CompilerServices - get() = Builder().build() - } } diff --git a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerEnvironment.java b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerEnvironment.java index 1cfba633832..ba3ebc58346 100644 --- a/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerEnvironment.java +++ b/ide-compiler-runner/src/org/jetbrains/jet/compiler/runner/CompilerEnvironment.java @@ -19,7 +19,7 @@ package org.jetbrains.jet.compiler.runner; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.cli.common.messages.MessageCollector; -import org.jetbrains.jet.config.CompilerServices; +import org.jetbrains.jet.config.Services; import org.jetbrains.jet.preloading.ClassCondition; import org.jetbrains.jet.utils.KotlinPaths; import org.jetbrains.jet.utils.PathUtil; @@ -36,7 +36,7 @@ public final class CompilerEnvironment { @Nullable File outputDir, @Nullable ClassLoader parentClassLoader, @NotNull ClassCondition classesToLoadByParent, - @NotNull CompilerServices compilerServices + @NotNull Services compilerServices ) { return new CompilerEnvironment(kotlinPaths, outputDir, parentClassLoader, classesToLoadByParent, compilerServices); } @@ -47,17 +47,17 @@ public final class CompilerEnvironment { private final File output; @Nullable private final ClassLoader parentClassLoader; - @Nullable + @NotNull private final ClassCondition classesToLoadByParent; @NotNull - private final CompilerServices services; + private final Services services; private CompilerEnvironment( @NotNull KotlinPaths kotlinPaths, @Nullable File output, @Nullable ClassLoader parentClassLoader, @NotNull ClassCondition classesToLoadByParent, - @NotNull CompilerServices services + @NotNull Services services ) { this.kotlinPaths = kotlinPaths; this.output = output; @@ -86,7 +86,7 @@ public final class CompilerEnvironment { return parentClassLoader; } - @Nullable + @NotNull public ClassCondition getClassesToLoadByParent() { return classesToLoadByParent; } @@ -102,7 +102,7 @@ public final class CompilerEnvironment { } @NotNull - public CompilerServices getServices() { + public Services getServices() { return services; } } diff --git a/jps-plugin/src/org/jetbrains/jet/jps/build/KotlinBuilder.java b/jps-plugin/src/org/jetbrains/jet/jps/build/KotlinBuilder.java index ba809168e2f..44e9152c20f 100644 --- a/jps-plugin/src/org/jetbrains/jet/jps/build/KotlinBuilder.java +++ b/jps-plugin/src/org/jetbrains/jet/jps/build/KotlinBuilder.java @@ -37,7 +37,7 @@ import org.jetbrains.jet.compiler.runner.CompilerEnvironment; import org.jetbrains.jet.compiler.runner.CompilerRunnerConstants; import org.jetbrains.jet.compiler.runner.OutputItemsCollectorImpl; import org.jetbrains.jet.compiler.runner.SimpleOutputItem; -import org.jetbrains.jet.config.CompilerServices; +import org.jetbrains.jet.config.Services; import org.jetbrains.jet.config.IncrementalCompilation; import org.jetbrains.jet.jps.JpsKotlinCompilerSettings; import org.jetbrains.jet.jps.incremental.*; @@ -128,7 +128,7 @@ public class KotlinBuilder extends ModuleLevelBuilder { incrementalCaches.put(target, dataManager.getStorage(target, IncrementalCacheStorageProvider.INSTANCE$)); } - CompilerServices compilerServices = new CompilerServices.Builder() + Services compilerServices = new Services.Builder() .register(IncrementalCacheProvider.class, new IncrementalCacheProviderImpl(incrementalCaches)) .build(); diff --git a/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt b/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt index 6e677f32bf9..f9723d40ad2 100644 --- a/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt +++ b/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt @@ -28,7 +28,7 @@ import org.jetbrains.kotlin.gradle.plugin.* import org.jetbrains.kotlin.doc.KDocConfig import java.util.concurrent.Callable import org.gradle.api.Project -import org.jetbrains.jet.config.CompilerServices +import org.jetbrains.jet.config.Services public open class KotlinCompile(): AbstractCompile() { @@ -123,7 +123,7 @@ public open class KotlinCompile(): AbstractCompile() { val messageCollector = GradleMessageCollector(getLogger()) getLogger().debug("Calling compiler") - val exitCode = compiler.exec(messageCollector, CompilerServices.empty, args) + val exitCode = compiler.exec(messageCollector, Services.EMPTY, args) when (exitCode) { ExitCode.COMPILATION_ERROR -> throw GradleException("Compilation error. See log for more details") diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java index 7c168f9fa90..6c0a47e64c9 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java @@ -35,7 +35,7 @@ import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation; import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity; import org.jetbrains.jet.cli.common.messages.MessageCollector; import org.jetbrains.jet.cli.jvm.K2JVMCompiler; -import org.jetbrains.jet.config.CompilerServices; +import org.jetbrains.jet.config.Services; import java.io.File; import java.io.IOException; @@ -260,7 +260,7 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo { @NotNull CommonCompilerArguments arguments, @NotNull MessageCollector messageCollector ) { - return compiler.exec(messageCollector, CompilerServices.OBJECT$.getEmpty(), arguments); + return compiler.exec(messageCollector, Services.EMPTY, arguments); } /**