Passing compiler plugins via CompilerConfiguration.
This commit is contained in:
@@ -19,6 +19,7 @@ package org.jetbrains.jet.buildtools.core;
|
||||
import jet.modules.Module;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.cli.common.CLIConfigurationKeys;
|
||||
import org.jetbrains.jet.cli.common.CompilerPlugin;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.jet.cli.common.util.CompilerPathUtil;
|
||||
@@ -83,7 +84,7 @@ public class BytecodeCompiler {
|
||||
MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR);
|
||||
|
||||
// lets register any compiler plugins
|
||||
env.getCompilerPlugins().addAll(getCompilerPlugins());
|
||||
configuration.addAll(CLIConfigurationKeys.COMPILER_PLUGINS, getCompilerPlugins());
|
||||
|
||||
return env;
|
||||
}
|
||||
|
||||
@@ -26,9 +26,9 @@ import org.jetbrains.jet.cli.common.messages.MessageRenderer;
|
||||
import org.jetbrains.jet.cli.common.messages.PrintingMessageCollector;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentException;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentUtil;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.cli.common.ExitCode.INTERNAL_ERROR;
|
||||
import static org.jetbrains.jet.cli.common.ExitCode.OK;
|
||||
@@ -36,7 +36,7 @@ import static org.jetbrains.jet.cli.common.ExitCode.OK;
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public abstract class CLICompiler<A extends CompilerArguments, C extends CompileEnvironmentConfiguration> {
|
||||
public abstract class CLICompiler<A extends CompilerArguments> {
|
||||
|
||||
@NotNull
|
||||
public ExitCode exec(@NotNull PrintStream errStream, @NotNull String... args) {
|
||||
@@ -90,9 +90,8 @@ public abstract class CLICompiler<A extends CompilerArguments, C extends Compile
|
||||
* based tools to customise their own plugins
|
||||
*/
|
||||
//TODO: add parameter annotations when KT-1863 is resolved
|
||||
protected void configureEnvironment(@NotNull C configuration, @NotNull A arguments) {
|
||||
List<CompilerPlugin> plugins = arguments.getCompilerPlugins();
|
||||
configuration.getCompilerPlugins().addAll(plugins);
|
||||
protected void configureEnvironment(@NotNull CompilerConfiguration configuration, @NotNull A arguments) {
|
||||
configuration.addAll(CLIConfigurationKeys.COMPILER_PLUGINS, arguments.getCompilerPlugins());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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.jet.cli.common;
|
||||
|
||||
import com.intellij.openapi.util.Key;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Evgeny Gerashchenko
|
||||
* @since 7/23/12
|
||||
*/
|
||||
public class CLIConfigurationKeys {
|
||||
public static final Key<List<CompilerPlugin>> COMPILER_PLUGINS = Key.create("compiler plugins");
|
||||
|
||||
private CLIConfigurationKeys() {
|
||||
}
|
||||
}
|
||||
@@ -16,13 +16,10 @@
|
||||
|
||||
package org.jetbrains.jet.cli.common;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
@@ -30,8 +27,6 @@ public abstract class CompileEnvironmentConfiguration {
|
||||
|
||||
@NotNull
|
||||
private final MessageCollector messageCollector;
|
||||
@NotNull
|
||||
private final List<CompilerPlugin> compilerPlugins = Lists.newArrayList();
|
||||
|
||||
/**
|
||||
* NOTE: It's very important to call dispose for every object of this class or there will be memory leaks.
|
||||
@@ -46,9 +41,4 @@ public abstract class CompileEnvironmentConfiguration {
|
||||
public MessageCollector getMessageCollector() {
|
||||
return messageCollector;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<CompilerPlugin> getCompilerPlugins() {
|
||||
return compilerPlugins;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ import org.jetbrains.k2js.analyze.AnalyzerFacadeForJS;
|
||||
import org.jetbrains.k2js.config.*;
|
||||
import org.jetbrains.k2js.facade.K2JSTranslator;
|
||||
import org.jetbrains.k2js.facade.MainCallParameters;
|
||||
import org.jetbrains.k2js.utils.JetFileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
@@ -53,7 +52,7 @@ import static org.jetbrains.jet.cli.common.messages.CompilerMessageLocation.NO_L
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments, K2JSCompileEnvironmentConfiguration> {
|
||||
public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
|
||||
public static void main(String... args) {
|
||||
doMain(new K2JSCompiler(), args);
|
||||
|
||||
@@ -47,7 +47,7 @@ import static org.jetbrains.jet.cli.common.ExitCode.*;
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
||||
public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMCompileEnvironmentConfiguration> {
|
||||
public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
||||
|
||||
public static void main(String... args) {
|
||||
doMain(new K2JVMCompiler(), args);
|
||||
@@ -108,7 +108,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
|
||||
messageCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment",
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
try {
|
||||
configureEnvironment(configuration, arguments);
|
||||
configureEnvironment(compilerConfiguration, arguments);
|
||||
|
||||
File jar = arguments.jar != null ? new File(arguments.jar) : null;
|
||||
File outputDir = arguments.outputDir != null ? new File(arguments.outputDir) : null;
|
||||
@@ -157,8 +157,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
|
||||
|
||||
// TODO this method is here only to workaround KT-2498
|
||||
@Override
|
||||
protected void configureEnvironment(@NotNull K2JVMCompileEnvironmentConfiguration configuration,
|
||||
@NotNull K2JVMCompilerArguments arguments) {
|
||||
protected void configureEnvironment(@NotNull CompilerConfiguration configuration, @NotNull K2JVMCompilerArguments arguments) {
|
||||
super.configureEnvironment(configuration, arguments);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -28,6 +28,7 @@ import jet.modules.Module;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.cli.common.CLIConfigurationKeys;
|
||||
import org.jetbrains.jet.cli.common.CompilerPlugin;
|
||||
import org.jetbrains.jet.cli.common.CompilerPluginContext;
|
||||
import org.jetbrains.jet.cli.common.messages.*;
|
||||
@@ -357,9 +358,8 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
BuiltinToJavaTypesMapping.ENABLED));
|
||||
generationState.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
|
||||
|
||||
List<CompilerPlugin> plugins = configuration.getCompilerPlugins();
|
||||
CompilerPluginContext context = new CompilerPluginContext(project, exhaust.getBindingContext(), environment.getSourceFiles());
|
||||
for (CompilerPlugin plugin : plugins) {
|
||||
for (CompilerPlugin plugin : environment.getConfiguration().getList(CLIConfigurationKeys.COMPILER_PLUGINS)) {
|
||||
plugin.processFiles(context);
|
||||
}
|
||||
return generationState;
|
||||
|
||||
@@ -5,6 +5,8 @@ import org.jetbrains.jet.cli.common.CLICompiler
|
||||
import org.jetbrains.jet.cli.jvm.K2JVMCompiler
|
||||
import org.jetbrains.jet.cli.jvm.K2JVMCompilerArguments
|
||||
import org.jetbrains.jet.cli.jvm.compiler.K2JVMCompileEnvironmentConfiguration
|
||||
import org.jetbrains.jet.config.CompilerConfiguration
|
||||
import org.jetbrains.jet.cli.common.CLIConfigurationKeys
|
||||
|
||||
/**
|
||||
* Main for running the KDocCompiler
|
||||
@@ -19,14 +21,9 @@ fun main(args: Array<String?>): Unit {
|
||||
*/
|
||||
class KDocCompiler() : K2JVMCompiler() {
|
||||
|
||||
protected override fun configureEnvironment(configuration : K2JVMCompileEnvironmentConfiguration, arguments : K2JVMCompilerArguments) {
|
||||
protected override fun configureEnvironment(configuration : CompilerConfiguration, arguments : K2JVMCompilerArguments) {
|
||||
super.configureEnvironment(configuration, arguments)
|
||||
val coreEnvironment = configuration.getEnvironment()
|
||||
if (coreEnvironment != null) {
|
||||
val kdoc = KDoc(arguments as KDocArguments)
|
||||
val plugins = configuration.getCompilerPlugins()
|
||||
plugins.add(kdoc);
|
||||
}
|
||||
configuration.add(CLIConfigurationKeys.COMPILER_PLUGINS, KDoc(arguments as KDocArguments))
|
||||
}
|
||||
|
||||
protected override fun createArguments() : K2JVMCompilerArguments {
|
||||
|
||||
Reference in New Issue
Block a user