You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "rossluk (via GitHub)" <gi...@apache.org> on 2023/02/28 15:45:00 UTC

[GitHub] [netbeans] rossluk opened a new pull request, #5579: Fix #5578 namespaces/use placement

rossluk opened a new pull request, #5579:
URL: https://github.com/apache/netbeans/pull/5579

   Fix "Fix Import" namespaces/uses placement in multiple php open tag files, when first line of php file is not empty or it is a block element, after declare statements in different scope
   
   
   ---
   **^Add meaningful description above**
   
   By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -
   
    - are all your own work, and you have the right to contribute them.
    - are contributed solely under the terms and conditions of the Apache License 2.0 (see section 5 of the license for more information).
   
   Please make sure (eg. `git log`) that all commits have a valid name and email address for you in the Author field.
   
   If you're a first time contributor, see the Contributing guidelines for more information.
   
   If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.
   


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


[GitHub] [netbeans] junichi11 commented on a diff in pull request #5579: Fix #5578 namespaces/use placement

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #5579:
URL: https://github.com/apache/netbeans/pull/5579#discussion_r1120912501


##########
php/php.editor/src/org/netbeans/modules/php/editor/actions/FixUsesPerformer.java:
##########
@@ -527,7 +519,15 @@ public void visit(DeclareStatement node) {
             if (CancelSupport.getDefault().isCancelled()) {
                 return;
             }
-            declareStatements.add(node);
+            for (Identifier i : node.getDirectiveNames()) {
+                // only - declare (strict_types=1) - should go before a namespace
+                // and such a declare can't be a block {} element or can't be in a global
+                // namespace, but - declare(ticks=1) could be anywhere.
+                if (i.getName().equals("strict_types")) {

Review Comment:
   Please add `// NOI18N`



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


[GitHub] [netbeans] junichi11 commented on pull request #5579: Fix #5578 namespaces/use placement

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on PR #5579:
URL: https://github.com/apache/netbeans/pull/5579#issuecomment-1449065836

   Could you add unit tests?


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


[GitHub] [netbeans] junichi11 commented on pull request #5579: Fix #5578 namespaces/use placement

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on PR #5579:
URL: https://github.com/apache/netbeans/pull/5579#issuecomment-1451699202

   Please rename `testNB5578` to `testGH5578`.
   Please add issue number to the commit message.


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


[GitHub] [netbeans] junichi11 commented on a diff in pull request #5579: Fix #5578 namespaces/use placement

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #5579:
URL: https://github.com/apache/netbeans/pull/5579#discussion_r1123766250


##########
php/php.editor/src/org/netbeans/modules/php/editor/actions/FixUsesPerformer.java:
##########
@@ -522,12 +544,29 @@ public List<NamespaceDeclaration> getGlobalNamespaceDeclarations() {
             return Collections.unmodifiableList(globalNamespaceDeclarations);
         }
 
+        public List<OffsetRange> getUsedRanges() {
+            return Collections.unmodifiableList(usedRanges);
+        }
+
+        @Override
+        public void visit(UseStatement node) {
+            usedRanges.add(new OffsetRange(node.getStartOffset(), node.getEndOffset()));

Review Comment:
   Please add 
   ```java
               if (CancelSupport.getDefault().isCancelled()) {
                   return;
               }
   ```



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


[GitHub] [netbeans] junichi11 commented on a diff in pull request #5579: Fix #5578 namespaces/use placement

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #5579:
URL: https://github.com/apache/netbeans/pull/5579#discussion_r1120911892


##########
php/php.editor/src/org/netbeans/modules/php/editor/actions/FixUsesPerformer.java:
##########
@@ -148,14 +146,24 @@ private void processSelections() {
             }
         }
         replaceUnimportedItems();
-        String insertString = createInsertString(useParts);
+        String insertString = createInsertString(useParts, shouldAppendLineAfter(startOffset));
         // avoid being recognized as a modified file
         if (insertString.isEmpty()) {
             StatusDisplayer.getDefault().setStatusText(Bundle.FixUsesPerformer_noChanges());
         } else {
             editList.replace(startOffset, 0, insertString, false, 0);
         }
     }
+    
+    private boolean shouldAppendLineAfter(int lineOffset)
+    {

Review Comment:
   Formatting: Please move "{" to the end of the previous line.



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


[GitHub] [netbeans] junichi11 commented on a diff in pull request #5579: Fix #5578 namespaces/use placement

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 commented on code in PR #5579:
URL: https://github.com/apache/netbeans/pull/5579#discussion_r1123783096


##########
php/php.editor/test/unit/data/testfiles/actions/testGH5578/01/testGH5578_01.php.fixUses:
##########
@@ -0,0 +1,39 @@
+<?php 
+
+use NS1\B;
+declare (ticks=1) {
+    
+    
+}

Review Comment:
   We should add use statements below the declare statement if possible.
   see: https://www.php-fig.org/psr/psr-12/#3-declare-statements-namespace-and-import-statements
   
   Please add a test case that has also `namespace` (`declare` and `namespace`).



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


[GitHub] [netbeans] rossluk commented on a diff in pull request #5579: Fix #5578 namespaces/use placement

Posted by "rossluk (via GitHub)" <gi...@apache.org>.
rossluk commented on code in PR #5579:
URL: https://github.com/apache/netbeans/pull/5579#discussion_r1124346203


##########
php/php.editor/test/unit/data/testfiles/actions/testGH5578/01/testGH5578_01.php.fixUses:
##########
@@ -0,0 +1,39 @@
+<?php 
+
+use NS1\B;
+declare (ticks=1) {
+    
+    
+}

Review Comment:
   Updated logic due to it, added new tests, also added a check for USE placing after phpDoc if there is no namespace in file (if namespace and phpDoc are there it will be placed after namespace). 



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


[GitHub] [netbeans] tmysik commented on pull request #5579: Fix #5578 namespaces/use placement

Posted by "tmysik (via GitHub)" <gi...@apache.org>.
tmysik commented on PR #5579:
URL: https://github.com/apache/netbeans/pull/5579#issuecomment-1452445901

   @rossluk Please, wait for approval from @junichi11. Thank you.
   


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


[GitHub] [netbeans] rossluk commented on pull request #5579: Fix #5578 namespaces/use placement

Posted by "rossluk (via GitHub)" <gi...@apache.org>.
rossluk commented on PR #5579:
URL: https://github.com/apache/netbeans/pull/5579#issuecomment-1450149693

   Added tests and fixes.


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


[GitHub] [netbeans] rossluk commented on pull request #5579: Fix #5578 namespaces/use placement

Posted by "rossluk (via GitHub)" <gi...@apache.org>.
rossluk commented on PR #5579:
URL: https://github.com/apache/netbeans/pull/5579#issuecomment-1450676258

   I've found more issues related to use placement, will do force push when have it fixed


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


[GitHub] [netbeans] rossluk commented on a diff in pull request #5579: Fix #5578 namespaces/use placement

Posted by "rossluk (via GitHub)" <gi...@apache.org>.
rossluk commented on code in PR #5579:
URL: https://github.com/apache/netbeans/pull/5579#discussion_r1120810326


##########
php/php.editor/src/org/netbeans/modules/php/editor/actions/FixUsesPerformer.java:
##########
@@ -148,14 +146,24 @@ private void processSelections() {
             }
         }
         replaceUnimportedItems();
-        String insertString = createInsertString(useParts);
+        String insertString = createInsertString(useParts, shouldAppendLineAfter(startOffset));
         // avoid being recognized as a modified file
         if (insertString.isEmpty()) {
             StatusDisplayer.getDefault().setStatusText(Bundle.FixUsesPerformer_noChanges());
         } else {
             editList.replace(startOffset, 0, insertString, false, 0);
         }
     }
+    
+    private boolean shouldAppendLineAfter(int lineOffset)
+    {
+        try {
+            return LineDocumentUtils.getNextNonWhitespace(baseDocument, lineOffset, LineDocumentUtils.getLineEnd(baseDocument, lineOffset)) != -1;
+        }  catch (BadLocationException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+        return false;

Review Comment:
   i am not a java developer, if it would be better i am willing to make changes, but just checked few files with similar logic and there is usually return outside



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


[GitHub] [netbeans] lbownik commented on a diff in pull request #5579: Fix #5578 namespaces/use placement

Posted by "lbownik (via GitHub)" <gi...@apache.org>.
lbownik commented on code in PR #5579:
URL: https://github.com/apache/netbeans/pull/5579#discussion_r1120664338


##########
php/php.editor/src/org/netbeans/modules/php/editor/actions/FixUsesPerformer.java:
##########
@@ -148,14 +146,24 @@ private void processSelections() {
             }
         }
         replaceUnimportedItems();
-        String insertString = createInsertString(useParts);
+        String insertString = createInsertString(useParts, shouldAppendLineAfter(startOffset));
         // avoid being recognized as a modified file
         if (insertString.isEmpty()) {
             StatusDisplayer.getDefault().setStatusText(Bundle.FixUsesPerformer_noChanges());
         } else {
             editList.replace(startOffset, 0, insertString, false, 0);
         }
     }
+    
+    private boolean shouldAppendLineAfter(int lineOffset)
+    {
+        try {
+            return LineDocumentUtils.getNextNonWhitespace(baseDocument, lineOffset, LineDocumentUtils.getLineEnd(baseDocument, lineOffset)) != -1;
+        }  catch (BadLocationException ex) {
+            Exceptions.printStackTrace(ex);
+        }
+        return false;

Review Comment:
   would return in catch block read better?



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


[GitHub] [netbeans] rossluk commented on pull request #5579: Fix #5578 namespaces/use placement

Posted by "rossluk (via GitHub)" <gi...@apache.org>.
rossluk commented on PR #5579:
URL: https://github.com/apache/netbeans/pull/5579#issuecomment-1451053226

   Added new test case and refactored some code. There is still a problem with multiple global namespaces, but problem is not related to Fix Import and I suppose should be fixed by other PR.


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


[GitHub] [netbeans] rossluk commented on a diff in pull request #5579: Fix #5578 namespaces/use placement

Posted by "rossluk (via GitHub)" <gi...@apache.org>.
rossluk commented on code in PR #5579:
URL: https://github.com/apache/netbeans/pull/5579#discussion_r1124346610


##########
php/php.editor/src/org/netbeans/modules/php/editor/actions/FixUsesPerformer.java:
##########
@@ -522,12 +544,29 @@ public List<NamespaceDeclaration> getGlobalNamespaceDeclarations() {
             return Collections.unmodifiableList(globalNamespaceDeclarations);
         }
 
+        public List<OffsetRange> getUsedRanges() {
+            return Collections.unmodifiableList(usedRanges);
+        }
+
+        @Override
+        public void visit(UseStatement node) {
+            usedRanges.add(new OffsetRange(node.getStartOffset(), node.getEndOffset()));

Review Comment:
   Done



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


[GitHub] [netbeans] junichi11 merged pull request #5579: Fix #5578 namespaces/use placement

Posted by "junichi11 (via GitHub)" <gi...@apache.org>.
junichi11 merged PR #5579:
URL: https://github.com/apache/netbeans/pull/5579


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