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


##########
java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java:
##########
@@ -2565,7 +2565,39 @@ public Boolean visitIf(final IfTree node, Void p) {
             StatementTree elseStat = node.getElseStatement();
             CodeStyle.BracesGenerationStyle redundantIfBraces = 
cs.redundantIfBraces();
             int eoln = findNewlineAfterStatement(node);
-            if ((elseStat != null && redundantIfBraces == 
CodeStyle.BracesGenerationStyle.ELIMINATE && 
danglingElseChecker.hasDanglingElse(node.getThenStatement())) ||
+            Boolean hasErrThenStatement = 
Optional.ofNullable(node.getThenStatement())
+                    .filter(it-> it instanceof ExpressionStatementTree)
+                    .map(it -> ((ExpressionStatementTree)it).getExpression())
+                    .map(it->  (it instanceof ErroneousTree))
+                    .orElse(false);

Review Comment:
   ```java
               boolean hasErrThenStatement = node.getThenStatement() instanceof 
ExpressionStatementTree tree
                                          && tree.getExpression() instanceof 
ErroneousTree;
   ```
   easier to read and probably less overhead too
   



##########
java/java.source.base/src/org/netbeans/modules/java/source/save/Reformatter.java:
##########
@@ -2565,7 +2565,39 @@ public Boolean visitIf(final IfTree node, Void p) {
             StatementTree elseStat = node.getElseStatement();
             CodeStyle.BracesGenerationStyle redundantIfBraces = 
cs.redundantIfBraces();
             int eoln = findNewlineAfterStatement(node);
-            if ((elseStat != null && redundantIfBraces == 
CodeStyle.BracesGenerationStyle.ELIMINATE && 
danglingElseChecker.hasDanglingElse(node.getThenStatement())) ||
+            Boolean hasErrThenStatement = 
Optional.ofNullable(node.getThenStatement())
+                    .filter(it-> it instanceof ExpressionStatementTree)
+                    .map(it -> ((ExpressionStatementTree)it).getExpression())
+                    .map(it->  (it instanceof ErroneousTree))
+                    .orElse(false);
+            if (hasErrThenStatement) {
+                if (getCurrentPath().getParentPath().getLeaf() instanceof 
BlockTree parentStTree) {
+                    var isPreviousIfTree = false;
+                    var endPositionOfErrThenStatement = endPos;
+                    for (var statment : parentStTree.getStatements()) {
+                        if (isPreviousIfTree) {
+                            var startPositionOfNextErrorStatement = (int) 
sp.getStartPosition(getCurrentPath().getCompilationUnit(), statment);

Review Comment:
   lets not use `var` here. `int` has 3 chars too - no need for extra 
obfuscation just to make the IDE draw the type as inline hint wasting space ;)
   
   Makes it also easier to review without checking this out in NetBeans.
   
   `var` is more interesting for collections with complex generics signatures 
etc.



-- 
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-unsubscr...@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org
For additional commands, e-mail: notifications-h...@netbeans.apache.org

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

Reply via email to