arusinha commented on a change in pull request #519: [NETBEANS-481] JDK10-LVTI: 
Added new ErrorRule to fix compiler error on initialization of var type 
variable with array
URL: https://github.com/apache/incubator-netbeans/pull/519#discussion_r187920753
 
 

 ##########
 File path: 
java.source.base/src/org/netbeans/modules/java/source/save/CasualDiff.java
 ##########
 @@ -1477,27 +1477,26 @@ private int diffVarDef(JCVariableDecl oldT, 
JCVariableDecl newT, int[] bounds) {
                     int modsUpperBound = getCommentCorrectedEndPos(oldT.mods);
                     if (modsUpperBound > -1) {
                         tokenSequence.move(modsUpperBound);
-                        tokenSequence.moveNext();
 
                         // copying modifiers from oldTree
-                        if (JavaTokenId.WHITESPACE == 
tokenSequence.token().id()) {
-                            int offset = tokenSequence.offset();
-                            copyTo(localPointer, localPointer = offset);
-                        } else {
+                        if (tokenSequence.moveNext()) {
 
 Review comment:
   check for JavaTokenId.WHITESPACE at modsUpperBound was removed in subsequent 
commit as check was not required after the code refactoring.
   
   Plz consider below scenario.
   
   Scenario1:
   /*comment1*/var/*comment2*/ a = {2,3.1f};
   
   For above  case  getCommentCorrectedEndPos(oldT.mods) will be -1 .
   So  Netbeans will not run code  inside the check (modsUpperBound > -1) 
present at line 1478
   In that case it will loop at line 1492 to add all the whitespaces/comments.
   
   Scenario2:
   @NotNull var j = {new Object(),new Object()};
   
   in this case code inside getCommentCorrectedEndPos(oldT.mods) >1 check 
   will add '@NotNull' to the final statement string.
   
   But we need to add the whitespace present after '@NotNull' to the final 
string.
   For that reason while loop at line 1492 is required. 
   it loops at line 1492 to add back the whitespace.
   
   Scenario3:
   final/*comment1*/var /*comment2*/ a = {2,3.1f};
   
   check (modsUpperBound > -1) at line 1478 will add 'final/*comment1*/' to the 
final string. 
   In this scenario modsUpperBound offset is pointing to VAR token.
   As we want to skip adding VAR token in final String 
tokenSequence.move(localPointer) is required at line 1489.
   Otherwise it will add wrongly 'var /*comment2*/' to the final string after 
looping at line 1492

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
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