Kotlin Facet: Filter out API versions exceeding library version
Also drop version validator as it's not needed anymore #KT-17847 Fixed
This commit is contained in:
+10
-15
@@ -136,7 +136,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
|
|||||||
new ActionListener() {
|
new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
restrictAPIVersions();
|
restrictAPIVersions(getSelectedLanguageVersion());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -300,27 +300,22 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void restrictAPIVersions() {
|
public void restrictAPIVersions(LanguageVersion upperBound) {
|
||||||
ApiVersion selectedAPIVersion = getSelectedAPIVersion();
|
ApiVersion selectedAPIVersion = getSelectedAPIVersion();
|
||||||
final LanguageVersion selectedLanguageVersion = getSelectedLanguageVersion();
|
|
||||||
List<ApiVersion> permittedAPIVersions = ArraysKt.mapNotNull(
|
List<ApiVersion> permittedAPIVersions = ArraysKt.mapNotNull(
|
||||||
LanguageVersion.values(),
|
LanguageVersion.values(),
|
||||||
new Function1<LanguageVersion, ApiVersion>() {
|
version -> VersionComparatorUtil.compare(version.getVersionString(), upperBound.getVersionString()) <= 0 &&
|
||||||
@Override
|
VersionComparatorUtil.compare(version.getVersionString(), upperBound.getVersionString()) <= 0
|
||||||
public ApiVersion invoke(LanguageVersion version) {
|
? ApiVersion.createByLanguageVersion(version)
|
||||||
return VersionComparatorUtil.compare(version.getVersionString(), selectedLanguageVersion.getVersionString()) <= 0
|
: null
|
||||||
? ApiVersion.createByLanguageVersion(version)
|
|
||||||
: null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
apiVersionComboBox.setModel(
|
apiVersionComboBox.setModel(
|
||||||
new DefaultComboBoxModel(permittedAPIVersions.toArray())
|
new DefaultComboBoxModel(permittedAPIVersions.toArray())
|
||||||
);
|
);
|
||||||
apiVersionComboBox.setSelectedItem(
|
apiVersionComboBox.setSelectedItem(
|
||||||
VersionComparatorUtil.compare(selectedAPIVersion.getVersionString(), selectedLanguageVersion.getVersionString()) <= 0
|
VersionComparatorUtil.compare(selectedAPIVersion.getVersionString(), upperBound.getVersionString()) <= 0
|
||||||
? selectedAPIVersion
|
? selectedAPIVersion
|
||||||
: selectedLanguageVersion
|
: upperBound
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,7 +419,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private LanguageVersion getSelectedLanguageVersion() {
|
public LanguageVersion getSelectedLanguageVersion() {
|
||||||
Object item = languageVersionComboBox.getSelectedItem();
|
Object item = languageVersionComboBox.getSelectedItem();
|
||||||
return item != null ? (LanguageVersion) item : LanguageVersion.LATEST_STABLE;
|
return item != null ? (LanguageVersion) item : LanguageVersion.LATEST_STABLE;
|
||||||
}
|
}
|
||||||
@@ -520,7 +515,7 @@ public class KotlinCompilerConfigurableTab implements SearchableConfigurable, Co
|
|||||||
reportWarningsCheckBox.setSelected(!commonCompilerArguments.suppressWarnings);
|
reportWarningsCheckBox.setSelected(!commonCompilerArguments.suppressWarnings);
|
||||||
languageVersionComboBox.setSelectedItem(getLanguageVersionOrDefault(commonCompilerArguments.languageVersion));
|
languageVersionComboBox.setSelectedItem(getLanguageVersionOrDefault(commonCompilerArguments.languageVersion));
|
||||||
apiVersionComboBox.setSelectedItem(getApiVersionOrDefault(commonCompilerArguments.apiVersion));
|
apiVersionComboBox.setSelectedItem(getApiVersionOrDefault(commonCompilerArguments.apiVersion));
|
||||||
restrictAPIVersions();
|
restrictAPIVersions(getSelectedLanguageVersion());
|
||||||
coroutineSupportComboBox.setSelectedItem(CoroutineSupport.byCompilerArguments(commonCompilerArguments));
|
coroutineSupportComboBox.setSelectedItem(CoroutineSupport.byCompilerArguments(commonCompilerArguments));
|
||||||
additionalArgsOptionsField.setText(compilerSettings.additionalArguments);
|
additionalArgsOptionsField.setText(compilerSettings.additionalArguments);
|
||||||
scriptTemplatesField.setText(compilerSettings.scriptTemplates);
|
scriptTemplatesField.setText(compilerSettings.scriptTemplates);
|
||||||
|
|||||||
@@ -147,23 +147,6 @@ class KotlinFacetEditorGeneralTab(
|
|||||||
get() = targetPlatformComboBox.selectedItem as TargetPlatformKind<*>?
|
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() {
|
inner class ArgumentConsistencyValidator : FacetEditorValidator() {
|
||||||
override fun check(): ValidationResult {
|
override fun check(): ValidationResult {
|
||||||
val platform = editor.targetPlatformComboBox.selectedItem as TargetPlatformKind<*>? ?: return ValidationResult.OK
|
val platform = editor.targetPlatformComboBox.selectedItem as TargetPlatformKind<*>? ?: return ValidationResult.OK
|
||||||
@@ -221,7 +204,6 @@ class KotlinFacetEditorGeneralTab(
|
|||||||
val editor = EditorComponent(editorContext.project, configuration)
|
val editor = EditorComponent(editorContext.project, configuration)
|
||||||
|
|
||||||
private val libraryValidator: FrameworkLibraryValidator
|
private val libraryValidator: FrameworkLibraryValidator
|
||||||
private val versionValidator = VersionValidator()
|
|
||||||
private val coroutineValidator = ArgumentConsistencyValidator()
|
private val coroutineValidator = ArgumentConsistencyValidator()
|
||||||
|
|
||||||
private var enableValidation = false
|
private var enableValidation = false
|
||||||
@@ -234,7 +216,6 @@ class KotlinFacetEditorGeneralTab(
|
|||||||
) { editor.targetPlatformComboBox.selectedItem as TargetPlatformKind<*> }
|
) { editor.targetPlatformComboBox.selectedItem as TargetPlatformKind<*> }
|
||||||
|
|
||||||
validatorsManager.registerValidator(libraryValidator)
|
validatorsManager.registerValidator(libraryValidator)
|
||||||
validatorsManager.registerValidator(versionValidator)
|
|
||||||
validatorsManager.registerValidator(coroutineValidator)
|
validatorsManager.registerValidator(coroutineValidator)
|
||||||
|
|
||||||
with(editor.compilerConfigurable) {
|
with(editor.compilerConfigurable) {
|
||||||
@@ -258,6 +239,15 @@ class KotlinFacetEditorGeneralTab(
|
|||||||
editor.updateCompilerConfigurable()
|
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() {
|
private fun JTextField.validateOnChange() {
|
||||||
document.addDocumentListener(
|
document.addDocumentListener(
|
||||||
object : DocumentAdapter() {
|
object : DocumentAdapter() {
|
||||||
|
|||||||
Reference in New Issue
Block a user