1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 14:12:10 +02:00

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 <marco.stornelli@gmail.com>
This commit is contained in:
Marco Stornelli 2020-02-02 10:58:58 +01:00
parent 244c43f414
commit 76bf5b4e7c

View file

@ -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();