Kotlin Facet: Fix facet creation with non-default JVM target
This commit is contained in:
@@ -132,14 +132,20 @@ class KotlinFacetSettings {
|
||||
}
|
||||
}
|
||||
|
||||
fun TargetPlatformKind<*>.createCompilerArguments(): CommonCompilerArguments {
|
||||
return when (this) {
|
||||
is TargetPlatformKind.Jvm -> {
|
||||
K2JVMCompilerArguments().apply { jvmTarget = this@createCompilerArguments.version.description }
|
||||
}
|
||||
fun TargetPlatformKind<*>.createCompilerArguments(init: CommonCompilerArguments.() -> Unit = {}): CommonCompilerArguments {
|
||||
val arguments = when (this) {
|
||||
is TargetPlatformKind.Jvm -> K2JVMCompilerArguments()
|
||||
is TargetPlatformKind.JavaScript -> K2JSCompilerArguments()
|
||||
is TargetPlatformKind.Common -> K2MetadataCompilerArguments()
|
||||
}
|
||||
|
||||
arguments.init()
|
||||
|
||||
if (arguments is K2JVMCompilerArguments) {
|
||||
arguments.jvmTarget = this@createCompilerArguments.version.description
|
||||
}
|
||||
|
||||
return arguments
|
||||
}
|
||||
|
||||
interface KotlinFacetSettingsProvider {
|
||||
|
||||
@@ -65,7 +65,7 @@ fun KotlinFacetSettings.initializeIfNeeded(
|
||||
|
||||
if (compilerArguments == null) {
|
||||
val targetPlatformKind = platformKind ?: getDefaultTargetPlatform(module, rootModel)
|
||||
compilerArguments = targetPlatformKind.createCompilerArguments().apply {
|
||||
compilerArguments = targetPlatformKind.createCompilerArguments {
|
||||
targetPlatformKind.getPlatformCompilerArgumentsByProject(module.project)?.let { mergeBeans(it, this) }
|
||||
mergeBeans(commonArguments, this)
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinJavaRuntime (2)" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
<entry name="!?*.java" />
|
||||
<entry name="!?*.form" />
|
||||
<entry name="!?*.class" />
|
||||
<entry name="!?*.groovy" />
|
||||
<entry name="!?*.scala" />
|
||||
<entry name="!?*.flex" />
|
||||
<entry name="!?*.kt" />
|
||||
<entry name="!?*.clj" />
|
||||
<entry name="!?*.aj" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="false">
|
||||
<processorPath useClasspath="true" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
<component name="CopyrightManager" default="" />
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/module.iml" filepath="$PROJECT_DIR$/module.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
<component name="libraryTable">
|
||||
<library name="KotlinJavaRuntime (2)">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/../mockRuntime11/kotlin-runtime.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
<component name="Kotlin2JvmCompilerArguments">
|
||||
<option name="jvmTarget" value="1.6" />
|
||||
</component>
|
||||
</project>
|
||||
Binary file not shown.
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinJavaRuntime (2)" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
<entry name="!?*.java" />
|
||||
<entry name="!?*.form" />
|
||||
<entry name="!?*.class" />
|
||||
<entry name="!?*.groovy" />
|
||||
<entry name="!?*.scala" />
|
||||
<entry name="!?*.flex" />
|
||||
<entry name="!?*.kt" />
|
||||
<entry name="!?*.clj" />
|
||||
<entry name="!?*.aj" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="false">
|
||||
<processorPath useClasspath="true" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
<component name="CopyrightManager" default="" />
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/module.iml" filepath="$PROJECT_DIR$/module.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
<component name="libraryTable">
|
||||
<library name="KotlinJavaRuntime (2)">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/../mockRuntime11/kotlin-runtime.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES>
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
<component name="Kotlin2JvmCompilerArguments">
|
||||
<option name="jvmTarget" value="1.8" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -17,12 +17,15 @@
|
||||
package org.jetbrains.kotlin.idea.configuration;
|
||||
|
||||
import com.intellij.framework.library.LibraryVersionProperties;
|
||||
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments;
|
||||
import org.jetbrains.kotlin.config.*;
|
||||
import org.jetbrains.kotlin.idea.facet.FacetUtilsKt;
|
||||
import org.jetbrains.kotlin.idea.facet.KotlinFacet;
|
||||
import org.jetbrains.kotlin.idea.framework.JSLibraryStdPresentationProvider;
|
||||
import org.jetbrains.kotlin.idea.framework.KotlinLibraryUtilKt;
|
||||
import org.jetbrains.kotlin.idea.project.PlatformKt;
|
||||
@@ -211,4 +214,34 @@ public class ConfigureKotlinTest extends AbstractConfigureKotlinTest {
|
||||
assertEquals("amd", arguments.moduleKind);
|
||||
assertEquals("-version -meta-info", settings.getCompilerSettings().additionalArguments);
|
||||
}
|
||||
|
||||
private void configureFacetAndCheckJvm(JvmTarget jvmTarget) {
|
||||
IdeModifiableModelsProviderImpl modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
|
||||
try {
|
||||
KotlinFacet facet = FacetUtilsKt.getOrCreateFacet(getModule(), modelsProvider, false);
|
||||
TargetPlatformKind.Jvm platformKind = TargetPlatformKind.Jvm.Companion.get(jvmTarget);
|
||||
FacetUtilsKt.configureFacet(
|
||||
facet,
|
||||
"1.1",
|
||||
LanguageFeature.State.ENABLED,
|
||||
platformKind,
|
||||
modelsProvider
|
||||
);
|
||||
assertEquals(platformKind, facet.getConfiguration().getSettings().getTargetPlatformKind());
|
||||
assertEquals(jvmTarget.getDescription(), ((K2JVMCompilerArguments) facet.getConfiguration().getSettings().getCompilerArguments()).jvmTarget);
|
||||
}
|
||||
finally {
|
||||
modelsProvider.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public void testJvm8InProjectJvm6InModule() {
|
||||
configureFacetAndCheckJvm(JvmTarget.JVM_1_6);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public void testJvm6InProjectJvm8InModule() {
|
||||
configureFacetAndCheckJvm(JvmTarget.JVM_1_8);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user