mbien commented on code in PR #9540:
URL: https://github.com/apache/netbeans/pull/9540#discussion_r3731692576


##########
ide/xml.xdm/src/org/netbeans/modules/xml/xdm/nodes/XMLSyntaxParser.java:
##########
@@ -44,22 +46,8 @@ public Document parse(BaseDocument basedoc)
             List<Token> currentTokens = new ArrayList<Token>();
             TokenHierarchy th = TokenHierarchy.get(basedoc);
             TokenSequence<XMLTokenId> tokenSequence = th.tokenSequence();
-            org.netbeans.api.lexer.Token<XMLTokenId> token = 
tokenSequence.token();
-            // Add the text token, if any, before xml decalration to document 
node
-            if(token != null && token.id() == XMLTokenId.TEXT) {
-                
currentTokens.add(Token.create(token.text().toString(),TokenType.TOKEN_CHARACTER_DATA));
-                if(tokenSequence.moveNext()) {
-                    token = tokenSequence.token();
-                }
-                // if the xml decalration is not there assign this token to 
document
-                if(token.id() != XMLTokenId.PI_START) {
-                    currentNode.setTokens(new ArrayList<Token>(currentTokens));
-                    currentTokens.clear();
-                }
-            }

Review Comment:
   I am not sure why this was there, but the tests, including your new test 
case, seem to pass with it.
   
   What was the reason you removed it?



##########
ide/xml.xdm/src/org/netbeans/modules/xml/xdm/nodes/XMLSyntaxParser.java:
##########
@@ -31,7 +31,9 @@
 import org.netbeans.api.xml.lexer.XMLTokenId;
 
 public class XMLSyntaxParser {
-            
+
+    private static final String BOM = "\uFEFF";

Review Comment:
   suggestion: rename to `BYTE_ORDER_MARK` or add comment to disambiguate from 
the common XML TLA for bill of materials.



##########
ide/xml.xdm/src/org/netbeans/modules/xml/xdm/nodes/XMLSyntaxParser.java:
##########
@@ -245,7 +233,7 @@ public Document parse(BaseDocument basedoc)
                             ((Element)parent).appendChild(currentNode, false);
                         } else {//parent is Document
                             if(token.id() != XMLTokenId.BLOCK_COMMENT &&
-                                    token.text().toString().trim().length() > 
0) {
+                                    !token.text().toString().isBlank() && 
!BOM.equals(token.text().toString().trim())) {

Review Comment:
   1) the field `image` holds the value for `token.text().toString()` and could 
be used here i think
   2) the difference between the whitespace semantics of `isBlank()` and 
`trim()` is significant here, right? I would recommend to add a comment that 
`trim()` must be kept, otherwise someone might change it to strip() or wonder 
why this code looks almost identical to the one of the top level 
`BLOCK_COMMENT` case and adjust both.
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to