Community
Participate
Working Groups
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 */ }
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.
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.
Merged into master: http://git.eclipse.org/c/pdt/org.eclipse.pdt.git/commit/?id=2a5d30845ecc32513d28d5a14cb2cb0220db008a
Verified. Closing