Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename-variable dialog doesn't allow 1st-char underscore #5828

Closed
digimeas opened this issue Mar 29, 2019 · 3 comments · Fixed by #5906
Closed

rename-variable dialog doesn't allow 1st-char underscore #5828

digimeas opened this issue Mar 29, 2019 · 3 comments · Fixed by #5906

Comments

@digimeas
Copy link

digimeas commented Mar 29, 2019

Hi!

When using the right-click rename variable function, trying to use an underscore as first character results in a "Barbie" message of "Naming is Hard"/"_xxx is not a valid name"

Processing 3.5.2

Thanks
Doug

Edit:
It seems that in java/src/processing/mode/java/pdex/Rename.java

   JButton renameButton = new JButton("Rename");
    renameButton.addActionListener(e -> {
      final String newName = textField.getText().trim();
      if (!newName.isEmpty()) {
        if (newName.length() >= 1 &&
-            newName.chars().limit(1).allMatch(Character::isUnicodeIdentifierStart) &&
-            newName.chars().skip(1).allMatch(Character::isUnicodeIdentifierPart)) {
+            newName.chars().limit(1).allMatch(Character::isJavaIdentifierStart) &&
+            newName.chars().skip(1).allMatch(Character::isJavaIdentifierPart)) {
          rename(ps, binding, newName);
          window.setVisible(false);
        } else {
          String msg = String.format("'%s' is not a valid name", newName);
          JOptionPane.showMessageDialog(editor, msg, "Naming is Hard",
                                        JOptionPane.PLAIN_MESSAGE);
        }
      }
    });
      rootPane.setDefaultButton(renameButton);

substituting "isJavaIdentifierStart/Part" for "isUnicodeIdentifierStart/Part" might solve the problem?

@jeremydouglass
Copy link
Contributor

isUnicodeIdentifierStart

https://www.tutorialspoint.com/java/lang/character_isunicodeidentifierstart.htm

_ may start a Unicode identifier is false

@digimeas
Copy link
Author

@jeremydouglass
That does seem to be the problem, alright.
https://www.tutorialspoint.com/java/lang/character_isjavaidentifierstart.htm
_ may start a Java identifier is true

jeremydouglass added a commit to jeremydouglass/processing that referenced this issue Aug 12, 2019
Previously it was limited to unicode identifiers--for example a beginning with _ was  forbidden; not so in Java.

Closes processing#5828  "rename-variable dialog doesn't allow 1st-char underscore"
benfry added a commit that referenced this issue Jan 17, 2020
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants