refactoring of script definition api
This commit is contained in:
@@ -38,6 +38,7 @@ import org.jetbrains.jet.config.CommonConfigurationKeys;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.parsing.JetParser;
|
||||
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
|
||||
import org.jetbrains.jet.lang.parsing.JetScriptDefinitionProvider;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
|
||||
import org.jetbrains.jet.lang.resolve.java.extAnnotations.CoreAnnotationsProvider;
|
||||
@@ -89,6 +90,7 @@ public class JetCoreEnvironment {
|
||||
projectEnvironment = new JavaCoreProjectEnvironment(parentDisposable, applicationEnvironment);
|
||||
|
||||
MockProject project = projectEnvironment.getProject();
|
||||
project.registerService(JetScriptDefinitionProvider.class, new JetScriptDefinitionProvider());
|
||||
project.registerService(JetFilesProvider.class, new CliJetFilesProvider(this));
|
||||
project.registerService(CoreJavaFileManager.class, (CoreJavaFileManager) ServiceManager.getService(project, JavaFileManager.class));
|
||||
Extensions.getArea(project)
|
||||
@@ -108,6 +110,8 @@ public class JetCoreEnvironment {
|
||||
addSources(path);
|
||||
}
|
||||
|
||||
JetScriptDefinitionProvider.getInstance(project).addScriptDefinitions(configuration.getList(CommonConfigurationKeys.SCRIPT_DEFINITIONS_KEY));
|
||||
|
||||
JetStandardLibrary.initialize(project);
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
+11
-3
@@ -37,6 +37,9 @@ import org.jetbrains.jet.codegen.*;
|
||||
import org.jetbrains.jet.config.CommonConfigurationKeys;
|
||||
import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.BuiltinsScopeExtensionMode;
|
||||
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
|
||||
import org.jetbrains.jet.lang.parsing.JetScriptDefinition;
|
||||
import org.jetbrains.jet.lang.parsing.JetScriptDefinitionProvider;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
||||
@@ -361,24 +364,29 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
public static Class compileScript(
|
||||
ClassLoader parentLoader,
|
||||
String scriptPath,
|
||||
List<AnalyzerScriptParameter> scriptParameters) {
|
||||
@Nullable List<AnalyzerScriptParameter> scriptParameters,
|
||||
@Nullable List<JetScriptDefinition> scriptDefinitions) {
|
||||
final MessageRenderer messageRenderer = MessageRenderer.PLAIN;
|
||||
PrintingMessageCollector messageCollector = new PrintingMessageCollector(System.err, messageRenderer, false);
|
||||
Disposable rootDisposable = CompileEnvironmentUtil.createMockDisposable();
|
||||
try {
|
||||
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
|
||||
compilerConfiguration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, getClasspath(parentLoader));
|
||||
compilerConfiguration.addAll(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, Collections.singletonList(CompilerPathUtil.getJdkAnnotationsPath()));
|
||||
compilerConfiguration.addAll(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, Collections.singletonList(
|
||||
CompilerPathUtil.getJdkAnnotationsPath()));
|
||||
compilerConfiguration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, scriptPath);
|
||||
compilerConfiguration.addAll(CommonConfigurationKeys.SCRIPT_DEFINITIONS_KEY,
|
||||
scriptDefinitions != null ? scriptDefinitions : Collections.<JetScriptDefinition>emptyList());
|
||||
|
||||
JetCoreEnvironment environment = JetCoreEnvironment.createCoreEnvironmentForJVM(rootDisposable, compilerConfiguration);
|
||||
K2JVMCompileEnvironmentConfiguration configuration = new K2JVMCompileEnvironmentConfiguration(
|
||||
environment, messageCollector, scriptParameters,
|
||||
environment, messageCollector, scriptParameters != null ? scriptParameters : Collections.<AnalyzerScriptParameter>emptyList(),
|
||||
BuiltinsScopeExtensionMode.ALL,
|
||||
false,
|
||||
BuiltinToJavaTypesMapping.ENABLED);
|
||||
|
||||
try {
|
||||
JetScriptDefinitionProvider.getInstance(environment.getProject()).markFileAsScript(environment.getSourceFiles().get(0));
|
||||
return compileScript(configuration, parentLoader);
|
||||
}
|
||||
catch (CompilationException e) {
|
||||
|
||||
Reference in New Issue
Block a user