[inspections] OptionController#onValue: generic

GitOrigin-RevId: 73067ff85e024fd94ebdde5e78e31bbc4e5d153c
This commit is contained in:
Tagir Valeev
2023-01-12 13:41:31 +01:00
committed by intellij-monorepo-bot
parent 770833e8c1
commit 33dce802ee
6 changed files with 13 additions and 12 deletions

View File

@@ -72,7 +72,7 @@ public class OptControlTest {
return super.getOptionController()
.onPrefix("adv", bindId -> options.getOrDefault(bindId, true),
(bindId, value) -> options.put(bindId, (Boolean)value))
.onValue("valueDouble", () -> valueDouble / 2, val -> valueDouble = 2 * (int)val);
.onValue("valueDouble", () -> valueDouble / 2, val -> valueDouble = 2 * val);
}
}

View File

@@ -57,7 +57,7 @@ class JavaApiUsageInspection : AbstractBaseUastLocalInspectionTool() {
return super.getOptionController().onValue(
"effectiveLanguageLevel",
{ effectiveLanguageLevel?.name ?: "null" },
{ value -> effectiveLanguageLevel = if (value == "null") null else LanguageLevel.valueOf(value as String) }
{ value -> effectiveLanguageLevel = if (value == "null") null else LanguageLevel.valueOf(value) }
)
}

View File

@@ -67,20 +67,22 @@ public interface OptionController {
}
/**
* @param <T> type of property
* @param bindId bindId of the option value to process especially
* @param getter getter for an option with a given bindId
* @param setter setter for an option with a given bindId
* @return a new controller that processes the specified bindId with a specified getter and setter,
* and delegates to this controller for any other bindId.
*/
default @NotNull OptionController onValue(@NotNull String bindId, @NotNull Supplier<@NotNull Object> getter,
@NotNull Consumer<@NotNull Object> setter) {
default <T> @NotNull OptionController onValue(@NotNull String bindId, @NotNull Supplier<@NotNull T> getter,
@NotNull Consumer<@NotNull T> setter) {
OptionController controller = this;
return new OptionController() {
@Override
public void setOption(@NotNull String _bindId, Object value) {
if (_bindId.equals(bindId)) {
setter.accept(value);
//noinspection unchecked
setter.accept((T)value);
}
else {
controller.setOption(_bindId, value);

View File

@@ -63,10 +63,10 @@ public class NamingConventionBean {
public @NotNull OptionController getOptionController() {
return OptionController.empty()
.onValue("m_minLength", () -> m_minLength, val -> m_minLength = (int)val)
.onValue("m_maxLength", () -> m_maxLength, val -> m_maxLength = (int)val)
.onValue("m_minLength", () -> m_minLength, val -> m_minLength = val)
.onValue("m_maxLength", () -> m_maxLength, val -> m_maxLength = val)
.onValue("m_regex", () -> m_regex, val -> {
m_regex = (String)val;
m_regex = val;
try {
initPattern();
}

View File

@@ -53,6 +53,6 @@ public class NamingConventionWithFallbackBean extends NamingConventionBean {
@Override
public OptionController getOptionController() {
return super.getOptionController()
.onValue("inheritDefaultSettings", () -> !inheritDefaultSettings, val -> inheritDefaultSettings = !(boolean)val);
.onValue("inheritDefaultSettings", () -> !inheritDefaultSettings, val -> inheritDefaultSettings = !val);
}
}

View File

@@ -62,9 +62,8 @@ public class DependsOnGroupsInspection extends AbstractBaseJavaLocalInspectionTo
() -> StringUtil.join(ArrayUtilRt.toStringArray(groups), ","),
value -> {
groups.clear();
String text = (String)value;
if (!StringUtil.isEmptyOrSpaces(text)) {
ContainerUtil.addAll(groups, text.split("[, ]"));
if (!StringUtil.isEmptyOrSpaces(value)) {
ContainerUtil.addAll(groups, value.split("[, ]"));
}
});
}