提交 23c0e6fc 编写于 作者: A Alexey Sedunov

Kotlin Facet: Filter out API versions exceeding library version

Also drop version validator as it's not needed anymore
 #KT-17847 Fixed
上级 d288c684
......@@ -136,7 +136,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
restrictAPIVersions();
restrictAPIVersions(getSelectedLanguageVersion());
}
}
);
......@@ -300,27 +300,22 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
}
@SuppressWarnings("unchecked")
public void restrictAPIVersions() {
public void restrictAPIVersions(LanguageVersion upperBound) {
ApiVersion selectedAPIVersion = getSelectedAPIVersion();
final LanguageVersion selectedLanguageVersion = getSelectedLanguageVersion();
List<ApiVersion> permittedAPIVersions = ArraysKt.mapNotNull(
LanguageVersion.values(),
new Function1<LanguageVersion, ApiVersion>() {
@Override
public ApiVersion invoke(LanguageVersion version) {
return VersionComparatorUtil.compare(version.getVersionString(), selectedLanguageVersion.getVersionString()) <= 0
? ApiVersion.createByLanguageVersion(version)
: null;
}
}
version -> VersionComparatorUtil.compare(version.getVersionString(), upperBound.getVersionString()) <= 0 &&
VersionComparatorUtil.compare(version.getVersionString(), upperBound.getVersionString()) <= 0
? ApiVersion.createByLanguageVersion(version)
: null
);
apiVersionComboBox.setModel(
new DefaultComboBoxModel(permittedAPIVersions.toArray())
);
apiVersionComboBox.setSelectedItem(
VersionComparatorUtil.compare(selectedAPIVersion.getVersionString(), selectedLanguageVersion.getVersionString()) <= 0
VersionComparatorUtil.compare(selectedAPIVersion.getVersionString(), upperBound.getVersionString()) <= 0
? selectedAPIVersion
: selectedLanguageVersion
: upperBound
);
}
......@@ -424,7 +419,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
}
@NotNull
private LanguageVersion getSelectedLanguageVersion() {
public LanguageVersion getSelectedLanguageVersion() {
Object item = languageVersionComboBox.getSelectedItem();
return item != null ? (LanguageVersion) item : LanguageVersion.LATEST_STABLE;
}
......@@ -520,7 +515,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
reportWarningsCheckBox.setSelected(!commonCompilerArguments.suppressWarnings);
languageVersionComboBox.setSelectedItem(getLanguageVersionOrDefault(commonCompilerArguments.languageVersion));
apiVersionComboBox.setSelectedItem(getApiVersionOrDefault(commonCompilerArguments.apiVersion));
restrictAPIVersions();
restrictAPIVersions(getSelectedLanguageVersion());
coroutineSupportComboBox.setSelectedItem(CoroutineSupport.byCompilerArguments(commonCompilerArguments));
additionalArgsOptionsField.setText(compilerSettings.additionalArguments);
scriptTemplatesField.setText(compilerSettings.scriptTemplates);
......
......@@ -147,23 +147,6 @@ class KotlinFacetEditorGeneralTab(
get() = targetPlatformComboBox.selectedItem as TargetPlatformKind<*>?
}
inner class VersionValidator : FacetEditorValidator() {
override fun check(): ValidationResult {
val apiLevel = editor.compilerConfigurable.apiVersionComboBox.selectedItem as? ApiVersion?
?: return ValidationResult.OK
val languageLevel = editor.compilerConfigurable.languageVersionComboBox.selectedItem as? LanguageVersion?
?: return ValidationResult.OK
val targetPlatform = editor.targetPlatformComboBox.selectedItem as TargetPlatformKind<*>?
val libraryLevel = getLibraryLanguageLevel(editorContext.module, editorContext.rootModel, targetPlatform)
val apiLevelVersion = LanguageVersion.fromVersionString(apiLevel.versionString) ?: return ValidationResult.OK
if (languageLevel < apiLevelVersion || libraryLevel < apiLevelVersion) {
return ValidationResult("Language version/Runtime version may not be less than API version", null)
}
return ValidationResult.OK
}
}
inner class ArgumentConsistencyValidator : FacetEditorValidator() {
override fun check(): ValidationResult {
val platform = editor.targetPlatformComboBox.selectedItem as TargetPlatformKind<*>? ?: return ValidationResult.OK
......@@ -221,7 +204,6 @@ class KotlinFacetEditorGeneralTab(
val editor = EditorComponent(editorContext.project, configuration)
private val libraryValidator: FrameworkLibraryValidator
private val versionValidator = VersionValidator()
private val coroutineValidator = ArgumentConsistencyValidator()
private var enableValidation = false
......@@ -234,7 +216,6 @@ class KotlinFacetEditorGeneralTab(
) { editor.targetPlatformComboBox.selectedItem as TargetPlatformKind<*> }
validatorsManager.registerValidator(libraryValidator)
validatorsManager.registerValidator(versionValidator)
validatorsManager.registerValidator(coroutineValidator)
with(editor.compilerConfigurable) {
......@@ -258,6 +239,15 @@ class KotlinFacetEditorGeneralTab(
editor.updateCompilerConfigurable()
}
private fun restrictAPIVersions() {
with(editor.compilerConfigurable) {
val targetPlatform = editor.targetPlatformComboBox.selectedItem as TargetPlatformKind<*>?
val libraryLevel = getLibraryLanguageLevel(editorContext.module, editorContext.rootModel, targetPlatform)
val versionUpperBound = minOf(selectedLanguageVersion, libraryLevel)
restrictAPIVersions(versionUpperBound)
}
}
private fun JTextField.validateOnChange() {
document.addDocumentListener(
object : DocumentAdapter() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册