You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "matthiasblaesing (via GitHub)" <gi...@apache.org> on 2026/07/27 19:51:44 UTC
[PR] PHP: Fix formatting of enums with names that are keywords (unset, if,case, ...) [netbeans]
matthiasblaesing opened a new pull request, #9535:
URL: https://github.com/apache/netbeans/pull/9535
Trying to format an enum like this:
```php
enum Type {
case UNSET;
}
```
Results in a deformed case:
```php
enum Type {
case UNSET;
}
```
with assertions enabled, it causes an error like this:
```
SEVERE [org.openide.util.RequestProcessor]: Error in RequestProcessor org.netbeans.modules.progress.ui.RunOffEDTImpl$1
java.lang.AssertionError: The same token (index: 14 - WHITESPACE, format tokens: 25, offset: 33) was precessed before.
Please report this to help fix issue 188809.
<?php
enum Type {
case UNSET;
}
at org.netbeans.modules.php.editor.indent.FormatVisitor.addFormatToken(FormatVisitor.java:2755)
at org.netbeans.modules.php.editor.indent.FormatVisitor.visit(FormatVisitor.java:1224)
at org.netbeans.modules.php.editor.parser.astnodes.CaseDeclaration.accept(CaseDeclaration.java:82)
```
Replacing `UNSET` with `XNSET` results in a valid result.
The problem is located in the `FormatVisitor`, which scans the `case` expression and loops until the first string is found. That works for the normal cases, but not for cases, where the enum name is also a keyword.
The grammar explicitly declares, that everything after the `case` is considered an identifier (ignoring whitespace and comments). The NetBeans lexer however yields an PHP_UNSET for the UNSET case.
Instead of relying on the token ids when scanning the `case` expression, the position of the name of the `case` expression is extracted from the AST and used as a terminator for the scanning sequence.
Closes: #9533
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] PHP: Fix formatting of enums with names that are keywords (unset, if,case, ...) [netbeans]
Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on PR #9535:
URL: https://github.com/apache/netbeans/pull/9535#issuecomment-5134393548
@tmysik @junichi11 thank you both for review.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] PHP: Fix formatting of enums with names that are keywords (unset, if,case, ...) [netbeans]
Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing merged PR #9535:
URL: https://github.com/apache/netbeans/pull/9535
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
Re: [PR] PHP: Fix formatting of enums with names that are keywords (unset, if,case, ...) [netbeans]
Posted by "matthiasblaesing (via GitHub)" <gi...@apache.org>.
matthiasblaesing commented on PR #9535:
URL: https://github.com/apache/netbeans/pull/9535#issuecomment-5106331730
The assertion that an identifier is always expected after the `case` expression comes from here:
https://github.com/php/php-src/blob/a5e34c6030acc6f482a8d4a0d12544a94438117a/Zend/zend_language_parser.y#L659-L662
I read this as `T_CASE` (`case`) may be followed by comments alternatively an identifier is expected.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists