From 76bf5b4e7cf8ed651e8c97cee59d62ef55ba3a10 Mon Sep 17 00:00:00 2001 From: Marco Stornelli Date: Sun, 2 Feb 2020 10:58:58 +0100 Subject: [PATCH] Bug 475625 - Allow user to have empty variable names When the user selects the second wizard page was forced to use a no empty variable name, however it's possible the parameter won't be used and the user wants to have a matching signature. Removed the check. The parameter name is still automatically set if the user click directly on "Finish" button. Change-Id: I665220b72d7b04b4bc89ffd5d764771cdfa8b243 Signed-off-by: Marco Stornelli --- .../dialogs/ValidatingLabeledTextField.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/ValidatingLabeledTextField.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/ValidatingLabeledTextField.java index 321eb5d1658..ab740f9a94c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/ValidatingLabeledTextField.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/dialogs/ValidatingLabeledTextField.java @@ -66,6 +66,14 @@ public class ValidatingLabeledTextField extends Composite { public void hasNoErrors() { } + /** + * Is an empty input allowed? + * @return True if empty string is allowed, false otherwise + */ + public boolean emptyAllowed() { + return true; + } + /** * @param text the new value of the field * @return whether the value is valid or not @@ -138,17 +146,18 @@ public class ValidatingLabeledTextField extends Composite { public void checkField() { String newName = textField.getText(); - boolean isEmpty = (newName.length() == 0); + boolean isEmpty = newName.length() == 0; boolean isNameAlreadyInUse = nameAlreadyInUse(textField, newName); boolean isValid = validator.isValidInput(newName); boolean isKeyword = NameHelper.isKeyword(newName); - boolean isValidName = NameHelper.isValidLocalVariableName(newName); + boolean isEmptyAllowed = validator.emptyAllowed(); + boolean isValidName = (isEmpty && isEmptyAllowed) || NameHelper.isValidLocalVariableName(newName); - boolean isOk = isValid && !isNameAlreadyInUse && !isEmpty && !isKeyword && isValidName; + boolean isOk = isValid && !isNameAlreadyInUse && !isKeyword && isValidName; if (isOk) { setErrorStatus(EMPTY_STRING); - } else if (isEmpty) { + } else if (isEmpty && !isEmptyAllowed) { setErrorStatus(validator.errorMessageForEmptyField()); } else if (!isValid || !isValidName) { setErrorStatus(validator.errorMessageForInvalidInput()); @@ -159,8 +168,8 @@ public class ValidatingLabeledTextField extends Composite { } validationStatus.put(textField, isOk); - if (validationStatus.values().contains(Boolean.FALSE) || isEmpty || isNameAlreadyInUse || isKeyword - || !isValidName) { + if (validationStatus.values().contains(Boolean.FALSE) || (isEmpty && !isEmptyAllowed) + || isNameAlreadyInUse || isKeyword || !isValidName) { validator.hasErrors(); } else { validator.hasNoErrors();