Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 404031 - Using @return to override automatic Code Assist not working for array return values
Summary: Using @return to override automatic Code Assist not working for array return ...
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: PDT (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Dawid Pakula CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-21 10:27 EDT by Oliver Grätz CLA
Modified: 2020-05-14 13:28 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Grätz CLA 2013-03-21 10:27:13 EDT
My uses build to verify this problem is the current nightly:

  PHP Development Tools (PDT) 3.2.0.201303201012

and this bug is related to

  https://bugs.eclipse.org/bugs/show_bug.cgi?id=375821

which is CLOSED but not completely fixed. The syntax of return "className[]" proposed there is only working in some cases and I think the reason might be that overriding the internal assumptions of the Code Assist with explicit "@return" definitions isn't working with arrays. This leads to completion for
the wrong class in some cases and missing completion in other situations.


Example:

/**
 * Test.
 * 
 * Without the @return this would produce completion for DateTime, because
 * the code analysis does not evaluate the "if". The automatic assist is
 * currently not fixable because the intelligence of Code Assist is limited.
 * Therefore, the @return provides a manual override for this and in this
 * case it is working as expected.
 * 
 * @return DateInterval
 */
function my_single_function()
{
    if (false)
    {
        return new DateTime;
    }
    else
    {
        return new DateInterval('P2Y4DT6H8M');
    }
}

/**
 * Test.
 * 
 * Same as above, the override should work.
 * Naming the return value as "DateInterval[]" should also work
 * because that is the format agreed upon in the PHPDoc community.
 * 
 * @return multitype:DateInterval
 */
function my_array_function()
{
    if (false)
    {
        return array(new DateTime);
    }
    else
    {
        return array(new DateInterval('P2Y4DT6H8M'));
    }
}

my_single_function()-> /* completion for DateInterval as expected */

foreach(my_array_function() as $item)
{
    $item-> /* completion for DateTime, override is broken */
}
Comment 1 Oliver Grätz CLA 2013-03-21 10:43:33 EDT
I now saw upon further investigation that the completion for "my_array_function" provides completion for both classes, as in the automatically created

  @return multitype:DateTime |multitype:DateInterval

line when creating a doc comment. So the completion for "my_array_function" does contain the completion for DateInterval (in a bad way, because I think that mixing the methods of all classes together in the completion popup is the wrong way to do it).

But this bug is not about missing completion, it is about @return not working as an override!

If it says "@return DateInterval[]", then the Code Assist should honor this and not provide any other completion.

And if I do

  /**
   * @return DateTime[]
   */
  function empty_function() {}
  
  empty_function()->

then the Code Assist should provide completion for DateTime even though the function does not return anything.
Comment 2 Dawid Pakula CLA 2014-05-05 07:56:12 EDT
Patch for review.

I implemented both:
1. Support for multitype syntax
2. PHPDoc first if not contain SimpleType only (like object, bool[] ...)

Comment generator issue should be moved into another bug.
Comment 4 Sylvia Tancheva CLA 2015-06-02 07:57:18 EDT
Verified. Closing