Minor. Renamed and cleaned CompilerServices -> Services.

This commit is contained in:
Evgeny Gerashchenko
2014-08-20 13:45:52 +04:00
parent 69c31c00db
commit 487f381287
9 changed files with 33 additions and 35 deletions
@@ -26,7 +26,7 @@ import org.jetbrains.jet.cli.js.K2JSCompiler
import java.io.File import java.io.File
import org.apache.tools.ant.BuildException import org.apache.tools.ant.BuildException
import org.jetbrains.jet.cli.common.ExitCode import org.jetbrains.jet.cli.common.ExitCode
import org.jetbrains.jet.config.CompilerServices import org.jetbrains.jet.config.Services
/** /**
* Kotlin JavaScript compiler Ant task. * Kotlin JavaScript compiler Ant task.
@@ -90,7 +90,7 @@ public class Kotlin2JsCompilerTask : Task() {
log("Compiling ${arguments.freeArgs} => [${arguments.outputFile}]"); log("Compiling ${arguments.freeArgs} => [${arguments.outputFile}]");
val compiler = K2JSCompiler() 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) { if (exitCode != ExitCode.OK) {
throw BuildException("Compilation finished with exit code $exitCode") throw BuildException("Compilation finished with exit code $exitCode")
@@ -27,12 +27,10 @@ import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
import org.jetbrains.jet.cli.common.messages.*; import org.jetbrains.jet.cli.common.messages.*;
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException; import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException;
import org.jetbrains.jet.config.CompilerConfiguration; import org.jetbrains.jet.config.CompilerConfiguration;
import org.jetbrains.jet.config.CompilerServices; import org.jetbrains.jet.config.Services;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import static org.jetbrains.jet.cli.common.ExitCode.*; import static org.jetbrains.jet.cli.common.ExitCode.*;
@@ -51,12 +49,12 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
@NotNull @NotNull
public ExitCode exec(@NotNull PrintStream errStream, @NotNull String... args) { 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 @SuppressWarnings("UnusedDeclaration") // Used via reflection in CompilerRunnerUtil#invokeExecMethod
@NotNull @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); return exec(errStream, services, MessageRenderer.TAGS, args);
} }
@@ -102,7 +100,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
@NotNull @NotNull
private ExitCode exec( private ExitCode exec(
@NotNull PrintStream errStream, @NotNull PrintStream errStream,
@NotNull CompilerServices services, @NotNull Services services,
@NotNull MessageRenderer messageRenderer, @NotNull MessageRenderer messageRenderer,
@NotNull String[] args @NotNull String[] args
) { ) {
@@ -135,7 +133,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
} }
@NotNull @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); GroupingMessageCollector groupingCollector = new GroupingMessageCollector(messageCollector);
try { try {
Disposable rootDisposable = Disposer.newDisposable(); Disposable rootDisposable = Disposer.newDisposable();
@@ -161,7 +159,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
@NotNull @NotNull
protected abstract ExitCode doExecute( protected abstract ExitCode doExecute(
@NotNull A arguments, @NotNull A arguments,
@NotNull CompilerServices services, @NotNull Services services,
@NotNull MessageCollector messageCollector, @NotNull MessageCollector messageCollector,
@NotNull Disposable rootDisposable @NotNull Disposable rootDisposable
); );
@@ -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.cli.jvm.compiler.JetCoreEnvironment;
import org.jetbrains.jet.config.CommonConfigurationKeys; import org.jetbrains.jet.config.CommonConfigurationKeys;
import org.jetbrains.jet.config.CompilerConfiguration; 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.jet.lang.psi.JetFile;
import org.jetbrains.k2js.analyze.AnalyzerFacadeForJS; import org.jetbrains.k2js.analyze.AnalyzerFacadeForJS;
import org.jetbrains.k2js.config.*; import org.jetbrains.k2js.config.*;
@@ -74,7 +74,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
@Override @Override
protected ExitCode doExecute( protected ExitCode doExecute(
@NotNull K2JSCompilerArguments arguments, @NotNull K2JSCompilerArguments arguments,
@NotNull CompilerServices services, @NotNull Services services,
@NotNull MessageCollector messageCollector, @NotNull MessageCollector messageCollector,
@NotNull Disposable rootDisposable @NotNull Disposable rootDisposable
) { ) {
@@ -34,7 +34,7 @@ import org.jetbrains.jet.cli.jvm.repl.ReplFromTerminal;
import org.jetbrains.jet.codegen.CompilationException; import org.jetbrains.jet.codegen.CompilationException;
import org.jetbrains.jet.config.CommonConfigurationKeys; import org.jetbrains.jet.config.CommonConfigurationKeys;
import org.jetbrains.jet.config.CompilerConfiguration; 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.AnalyzerScriptParameter;
import org.jetbrains.jet.lang.resolve.kotlin.incremental.cache.IncrementalCacheProvider; import org.jetbrains.jet.lang.resolve.kotlin.incremental.cache.IncrementalCacheProvider;
import org.jetbrains.jet.utils.KotlinPaths; import org.jetbrains.jet.utils.KotlinPaths;
@@ -59,7 +59,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
@NotNull @NotNull
protected ExitCode doExecute( protected ExitCode doExecute(
@NotNull K2JVMCompilerArguments arguments, @NotNull K2JVMCompilerArguments arguments,
@NotNull CompilerServices services, @NotNull Services services,
@NotNull MessageCollector messageCollector, @NotNull MessageCollector messageCollector,
@NotNull Disposable rootDisposable @NotNull Disposable rootDisposable
) { ) {
@@ -18,13 +18,18 @@ package org.jetbrains.jet.config
import java.util.HashMap import java.util.HashMap
public class CompilerServices private(private val map: Map<Class<*>, Any>) { public class Services private(private val map: Map<Class<*>, Any>) {
class object {
public val EMPTY: Services = Builder().build()
}
public fun <T> get(interfaceClass: Class<T>): T { public fun <T> get(interfaceClass: Class<T>): T {
[suppress("UNCHECKED_CAST")]
return map.get(interfaceClass) as T return map.get(interfaceClass) as T
} }
public class Builder { public class Builder {
private val map = HashMap<Class<*>, Any>() private val map = HashMap<Class<*>, Any>()
public fun <T> register(interfaceClass: Class<T>, implementation: T): Builder { public fun <T> register(interfaceClass: Class<T>, implementation: T): Builder {
@@ -32,13 +37,8 @@ public class CompilerServices private(private val map: Map<Class<*>, Any>) {
return this return this
} }
public fun build(): CompilerServices { public fun build(): Services {
return CompilerServices(map) return Services(map)
} }
} }
public class object {
public val empty: CompilerServices
get() = Builder().build()
}
} }
@@ -19,7 +19,7 @@ package org.jetbrains.jet.compiler.runner;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.cli.common.messages.MessageCollector; 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.preloading.ClassCondition;
import org.jetbrains.jet.utils.KotlinPaths; import org.jetbrains.jet.utils.KotlinPaths;
import org.jetbrains.jet.utils.PathUtil; import org.jetbrains.jet.utils.PathUtil;
@@ -36,7 +36,7 @@ public final class CompilerEnvironment {
@Nullable File outputDir, @Nullable File outputDir,
@Nullable ClassLoader parentClassLoader, @Nullable ClassLoader parentClassLoader,
@NotNull ClassCondition classesToLoadByParent, @NotNull ClassCondition classesToLoadByParent,
@NotNull CompilerServices compilerServices @NotNull Services compilerServices
) { ) {
return new CompilerEnvironment(kotlinPaths, outputDir, parentClassLoader, classesToLoadByParent, compilerServices); return new CompilerEnvironment(kotlinPaths, outputDir, parentClassLoader, classesToLoadByParent, compilerServices);
} }
@@ -47,17 +47,17 @@ public final class CompilerEnvironment {
private final File output; private final File output;
@Nullable @Nullable
private final ClassLoader parentClassLoader; private final ClassLoader parentClassLoader;
@Nullable @NotNull
private final ClassCondition classesToLoadByParent; private final ClassCondition classesToLoadByParent;
@NotNull @NotNull
private final CompilerServices services; private final Services services;
private CompilerEnvironment( private CompilerEnvironment(
@NotNull KotlinPaths kotlinPaths, @NotNull KotlinPaths kotlinPaths,
@Nullable File output, @Nullable File output,
@Nullable ClassLoader parentClassLoader, @Nullable ClassLoader parentClassLoader,
@NotNull ClassCondition classesToLoadByParent, @NotNull ClassCondition classesToLoadByParent,
@NotNull CompilerServices services @NotNull Services services
) { ) {
this.kotlinPaths = kotlinPaths; this.kotlinPaths = kotlinPaths;
this.output = output; this.output = output;
@@ -86,7 +86,7 @@ public final class CompilerEnvironment {
return parentClassLoader; return parentClassLoader;
} }
@Nullable @NotNull
public ClassCondition getClassesToLoadByParent() { public ClassCondition getClassesToLoadByParent() {
return classesToLoadByParent; return classesToLoadByParent;
} }
@@ -102,7 +102,7 @@ public final class CompilerEnvironment {
} }
@NotNull @NotNull
public CompilerServices getServices() { public Services getServices() {
return services; return services;
} }
} }
@@ -37,7 +37,7 @@ import org.jetbrains.jet.compiler.runner.CompilerEnvironment;
import org.jetbrains.jet.compiler.runner.CompilerRunnerConstants; import org.jetbrains.jet.compiler.runner.CompilerRunnerConstants;
import org.jetbrains.jet.compiler.runner.OutputItemsCollectorImpl; import org.jetbrains.jet.compiler.runner.OutputItemsCollectorImpl;
import org.jetbrains.jet.compiler.runner.SimpleOutputItem; 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.config.IncrementalCompilation;
import org.jetbrains.jet.jps.JpsKotlinCompilerSettings; import org.jetbrains.jet.jps.JpsKotlinCompilerSettings;
import org.jetbrains.jet.jps.incremental.*; import org.jetbrains.jet.jps.incremental.*;
@@ -128,7 +128,7 @@ public class KotlinBuilder extends ModuleLevelBuilder {
incrementalCaches.put(target, dataManager.getStorage(target, IncrementalCacheStorageProvider.INSTANCE$)); incrementalCaches.put(target, dataManager.getStorage(target, IncrementalCacheStorageProvider.INSTANCE$));
} }
CompilerServices compilerServices = new CompilerServices.Builder() Services compilerServices = new Services.Builder()
.register(IncrementalCacheProvider.class, new IncrementalCacheProviderImpl(incrementalCaches)) .register(IncrementalCacheProvider.class, new IncrementalCacheProviderImpl(incrementalCaches))
.build(); .build();
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.doc.KDocConfig import org.jetbrains.kotlin.doc.KDocConfig
import java.util.concurrent.Callable import java.util.concurrent.Callable
import org.gradle.api.Project import org.gradle.api.Project
import org.jetbrains.jet.config.CompilerServices import org.jetbrains.jet.config.Services
public open class KotlinCompile(): AbstractCompile() { public open class KotlinCompile(): AbstractCompile() {
@@ -123,7 +123,7 @@ public open class KotlinCompile(): AbstractCompile() {
val messageCollector = GradleMessageCollector(getLogger()) val messageCollector = GradleMessageCollector(getLogger())
getLogger().debug("Calling compiler") getLogger().debug("Calling compiler")
val exitCode = compiler.exec(messageCollector, CompilerServices.empty, args) val exitCode = compiler.exec(messageCollector, Services.EMPTY, args)
when (exitCode) { when (exitCode) {
ExitCode.COMPILATION_ERROR -> throw GradleException("Compilation error. See log for more details") ExitCode.COMPILATION_ERROR -> throw GradleException("Compilation error. See log for more details")
@@ -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.CompilerMessageSeverity;
import org.jetbrains.jet.cli.common.messages.MessageCollector; import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.cli.jvm.K2JVMCompiler; 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.File;
import java.io.IOException; import java.io.IOException;
@@ -260,7 +260,7 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
@NotNull CommonCompilerArguments arguments, @NotNull CommonCompilerArguments arguments,
@NotNull MessageCollector messageCollector @NotNull MessageCollector messageCollector
) { ) {
return compiler.exec(messageCollector, CompilerServices.OBJECT$.getEmpty(), arguments); return compiler.exec(messageCollector, Services.EMPTY, arguments);
} }
/** /**