org.jetbrains.kotlin.config.CompilerConfiguration Java Examples

The following examples show how to use org.jetbrains.kotlin.config.CompilerConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KotlinCompiler.java    From dynkt with GNU Affero General Public License v3.0 6 votes vote down vote up
private CompilerConfiguration createCompilerConfig(File file) {
	CompilerConfiguration config = new CompilerConfiguration();
	config.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, this);
	// Put arguments as field
	MemoryScriptDefinition memDef = new MemoryScriptDefinition();
	memDef.inject(StandardScriptDefinition.INSTANCE);
	// Bundle injection
	List<ScriptParameter> scriptParams = new LinkedList<ScriptParameter>();
	KotlinType type = DefaultBuiltIns.getInstance().getMutableMap().getDefaultType();
	Name ctxName = Name.identifier("ctx");
	scriptParams.add(new ScriptParameter(ctxName, type));
	memDef.inject(scriptParams);
	// Set definitions
	List<KotlinScriptDefinition> scriptDefs = new LinkedList<KotlinScriptDefinition>();
	scriptDefs.add(memDef);
	// Finish configuration
	config.put(JVMConfigurationKeys.MODULE_NAME, "dynamic");
	config.put(CommonConfigurationKeys.SCRIPT_DEFINITIONS_KEY, scriptDefs);
	addJvmClasspathRoots(config, PathUtil.getJdkClassesRoots());
	addKotlinSourceRoot(config, file.getAbsolutePath());
	return config;
}
 
Example #2
Source File: KotlinSdkAliasReader.java    From jig with Apache License 2.0 5 votes vote down vote up
private KtFile sourceToKtFile(KotlinSource kotlinSource, String source) {
    CompilerConfiguration configuration = new CompilerConfiguration();
    configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.Companion.getNONE());
    KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForProduction(() -> {
    }, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
    Project project = environment.getProject();
    LightVirtualFile virtualFile = new LightVirtualFile(kotlinSource.sourceFilePath().fineName(), KotlinFileType.INSTANCE, source);
    return (KtFile) PsiManager.getInstance(project).findFile(virtualFile);
}
 
Example #3
Source File: KotlinCompiler.java    From dynkt with GNU Affero General Public License v3.0 5 votes vote down vote up
public Class<?> compileScript(File file) {
	log.info("Compiling '{}'...", file);
	CompilerConfiguration config = createCompilerConfig(file);
	config = addCurrentClassPath(config);
	KotlinCoreEnvironment env = KotlinCoreEnvironment.createForProduction(this, config, configPaths);
	return KotlinToJVMBytecodeCompiler.INSTANCE.compileScript(config, paths, env);
}
 
Example #4
Source File: KotlinCompiler.java    From dynkt with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private CompilerConfiguration addCurrentClassPath(CompilerConfiguration config) {
	K2JVMCompilerArguments cmpArgs = new K2JVMCompilerArguments();
	cmpArgs.classpath = System.getProperty("java.class.path");
	cmpArgs.noStdlib = true;
	addJvmClasspathRoots(config, (List<File>) ReflUtils.invoke(K2JVMCompiler.Companion.class, null,
			"access$getClasspath", K2JVMCompiler.Companion, paths, cmpArgs));
	return config;
}
 
Example #5
Source File: ReplWithClassLoaderFactory.java    From beakerx with Apache License 2.0 5 votes vote down vote up
public static ReplInterpreter createReplWithReplClassLoader(KotlinEvaluator kotlinEvaluator, ReplClassLoader classLoader) {
  CompilerConfiguration compilerConfiguration = getCompilerConfiguration(getClasspath(), kotlinEvaluator);
  ReplInterpreter replInterpreter = new ReplInterpreter(newDisposable(), compilerConfiguration, new ConsoleReplConfiguration());
  setupReplClassLoader(classLoader, replInterpreter);
  replInterpreter.eval(getImportString(kotlinEvaluator.getImports().getImportPaths()));
  return replInterpreter;
}
 
Example #6
Source File: ReplWithClassLoaderFactory.java    From beakerx with Apache License 2.0 5 votes vote down vote up
private static ReplWithClassLoader createReplInterpreter(String[] classpathEntries, ClassLoader parent, KotlinEvaluator kotlinEvaluator) {
  CompilerConfiguration compilerConfiguration = getCompilerConfiguration(classpathEntries, kotlinEvaluator);
  ReplInterpreter replInterpreter = new ReplInterpreter(newDisposable(), compilerConfiguration, new ConsoleReplConfiguration());
  ReplClassLoader loader = getReplClassLoader(parent, replInterpreter);
  replInterpreter.eval(getImportString(kotlinEvaluator.getImports().getImportPaths()));
  return new ReplWithClassLoader(replInterpreter, loader);
}
 
Example #7
Source File: ReplWithClassLoaderFactory.java    From beakerx with Apache License 2.0 5 votes vote down vote up
@NotNull
private static CompilerConfiguration getCompilerConfiguration(String[] classpathEntries, KotlinEvaluator kotlinEvaluator) {
  CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
  compilerConfiguration.put(CommonConfigurationKeys.MODULE_NAME, "kotlinModule" + System.currentTimeMillis());
  compilerConfiguration.put(JVMConfigurationKeys.RETAIN_OUTPUT_IN_MEMORY, true);
  addJvmClasspathRoots(compilerConfiguration, PathUtil.getJdkClassesRootsFromCurrentJre());
  Arrays.stream(classpathEntries).forEach(x -> addJvmClasspathRoot(compilerConfiguration, new File(x)));
  kotlinEvaluator.getClasspath().getPathsAsStrings().forEach(x -> addJvmClasspathRoot(compilerConfiguration, new File(x)));
  return compilerConfiguration;
}