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

   What was done in this PR:
   - Changed the way interface methods and abstract methods are parsed
   - Fixed generation of the return type in phpDoc comments for abstract 
methods with an explicitly specified return type
   - For an interface method with a body, a hint `Interface method can not 
contain body` is now displayed instead of a syntax error
   - Fixed tests `ASTPHP5ParserTest` and `SanitizeSourceTest`
   - Fixed hints: `IncorrectNonAbstractMethodIntError`, 
`InitializeFieldSuggestion`, `ModifiersCheckHintError`, `UnusedVariableHint`
   - Added new tests for `PhpCommentGenerator` and `ModifiersCheckHintError`
   
   
   
   Fixed generation of the return type in phpDoc comments for abstract methods 
with an explicitly specified return type:
   Example:
   ```php
   <?php
   
   abstract class ClassExample
   {
   
       abstract public function test(): int;
   }
   ```
   Before:
   
   
https://github.com/user-attachments/assets/3da62022-c51f-4def-b66d-60cc1e24ed1e
   
   After:
   
   
https://github.com/user-attachments/assets/d41f518d-f005-4aae-b522-9ec3563da830
   
   
   
   For an interface method with a body, a hint `Interface method can not 
contain body` is now displayed instead of a syntax error:
   Example:
   ```php
   <?php
   
   interface InterfaceExample
   {
   
       public function test();
   }
   ```
   
   Before:
   <img width="479" height="227" alt="interface_method_before" 
src="https://github.com/user-attachments/assets/b6c2df54-2a83-4f6b-a450-a394007b373a";
 />
   
   After:
   <img width="600" height="196" alt="interface_method_after" 
src="https://github.com/user-attachments/assets/0dd63503-1994-46f5-824b-8033f2077cc6";
 />
   
   
   
https://github.com/user-attachments/assets/a443821f-2b4f-496d-8e14-d2b8494a88c3
   
   
   
   
   
   
   While working on tests for pull request #8340, I noticed that for an 
abstract method with an explicit return type, the return type is not generated 
in the phpDoc comment. I also noticed that for an interface method with an 
explicit return type, the correct phpDoc comment is generated.
   The reason for the difference in return type generation between abstract 
methods and interface methods in phpDoc comments lay in the parsing process. 
For abstract methods, an empty body block was not identified during parsing, 
unlike for interface methods.
   And because of this, the Scope of the method was incorrectly determined for 
the abstract method: `ClassScope` was determined instead of `MethodScope`.
   
https://github.com/apache/netbeans/blob/53e88660baa36f81497808b11aa39f4efc072c26/php/php.editor/src/org/netbeans/modules/php/editor/typinghooks/PhpCommentGenerator.java#L227-L246
   
   Due to an improperly defined scope, the analysis to determine whether the 
method has a return type is blocked.
   
https://github.com/apache/netbeans/blob/53e88660baa36f81497808b11aa39f4efc072c26/php/php.editor/src/org/netbeans/modules/php/editor/typinghooks/PhpCommentGenerator.java#L273-L278
   
   
https://github.com/apache/netbeans/blob/53e88660baa36f81497808b11aa39f4efc072c26/php/php.editor/src/org/netbeans/modules/php/editor/typinghooks/PhpCommentGenerator.java#L439-L449
   
   As a result, the method for retrieving the method's return type is not 
called.
   
https://github.com/apache/netbeans/blob/53e88660baa36f81497808b11aa39f4efc072c26/php/php.editor/src/org/netbeans/modules/php/editor/typinghooks/PhpCommentGenerator.java#L115-L117
   
   I decided to bring the parsing of the abstract method and the interface 
method to a single form. As a result, the issue with phpDoc comment return type 
generation was resolved, the syntax error for interface methods with a body was 
eliminated, 
   and the 'Interface method cannot contain body' hint began functioning 
correctly.
   
   ---
   **^Add meaningful description above**
   
   <details open>
   <summary>Click to collapse/expand PR instructions</summary>
   
   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.
   
   ### PR approval and merge checklist:
   
   1. [ ] Was this PR [correctly 
labeled](https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=240884239#PRsandYouAreviewerGuide-PRtriggeredCIJobs(conditionalCIpipeline)),
 did the right tests run? When did they run?
   2. [ ] Is this PR 
[squashed](https://cwiki.apache.org/confluence/display/NETBEANS/git%3A+squash+and+merge)?
   3. [ ] Are author name / email address correct? Are 
[co-authors](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors#creating-co-authored-commits-on-the-command-line)
 correctly listed? Do the commit messages need updates?
   3. [ ] Does the PR title and description still fit after the Nth iteration? 
Is the description sufficient to appear in the release notes?
   
   If this PR targets the delivery branch: [don't 
merge](https://cwiki.apache.org/confluence/display/NETBEANS/Pull+requests+for+delivery).
 ([full wiki 
article](https://cwiki.apache.org/confluence/display/NETBEANS/PRs+and+You+-+A+reviewer+Guide))
   
   </details>


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