This is an automated email from the ASF dual-hosted git repository. junichi11 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push: new e71087302b [GH-5355] PHP: Corrects the display of the guessed return type for a function or method in the documentation new 7c9c4bcfb0 Merge pull request #5779 from troizet/fix_gh_5355 e71087302b is described below commit e71087302b58795b7d8af53afb9763da756305ce Author: Alexey Borokhvostov <troi...@gmail.com> AuthorDate: Wed Apr 5 22:50:37 2023 +0700 [GH-5355] PHP: Corrects the display of the guessed return type for a function or method in the documentation --- .../modules/php/editor/completion/DocRenderer.java | 12 +++++-- .../completion/documentation/issueGH5355.php | 42 ++++++++++++++++++++++ .../issueGH5355.php.testIssueGH5355_01.html | 13 +++++++ .../issueGH5355.php.testIssueGH5355_02.html | 13 +++++++ .../editor/completion/PHPCCDocumentationTest.java | 8 +++++ 5 files changed, 85 insertions(+), 3 deletions(-) diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/completion/DocRenderer.java b/php/php.editor/src/org/netbeans/modules/php/editor/completion/DocRenderer.java index a42ed5c4ab..c16340c68a 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/completion/DocRenderer.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/completion/DocRenderer.java @@ -608,9 +608,15 @@ final class DocRenderer { if (type.isResolved()) { QualifiedName typeName = type.getTypeName(true); if (typeName != null) { - if (sb.length() > 0 - && (typeKind == Type.Kind.UNION || typeKind == Type.Kind.INTERSECTION)) { - sb.append(" ").append(typeKind.getSign()).append(" "); // NOI18N + if (sb.length() > 0) { + if (typeKind == Type.Kind.INTERSECTION) { + sb.append(" ").append(typeKind.getSign()).append(" "); // NOI18N + } else { + //GH-5355: If a function returns multiple types + //and doesn't have a declared return type, + //it's always a union type. + sb.append(" ").append(Type.Kind.UNION.getSign()).append(" "); // NOI18N + } } if (type.isNullableType()) { sb.append(CodeUtils.NULLABLE_TYPE_PREFIX); diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/issueGH5355.php b/php/php.editor/test/unit/data/testfiles/completion/documentation/issueGH5355.php new file mode 100644 index 0000000000..82833f80aa --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/issueGH5355.php @@ -0,0 +1,42 @@ +<?php +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +class ClassName { + + public function testMethod($a) { + if ($a) { + return 1; + } + return 'str'; + } + + public function test() { + $this->testMethod(null); + } +} + +function testFunction($a) { + if ($a) { + return 1; + } + return 'str'; +} + +testFunction(null); diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/issueGH5355.php.testIssueGH5355_01.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/issueGH5355.php.testIssueGH5355_01.html new file mode 100644 index 0000000000..527c6112c4 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/issueGH5355.php.testIssueGH5355_01.html @@ -0,0 +1,13 @@ +<html><body> +<pre>Code completion result for source line: +$this->testMetho|d(null); +(QueryType=COMPLETION, prefixSearch=false, caseSensitive=true) +METHOD testMethod($a) [PUBLIC] ClassName +</pre><h2>Documentation:</h2><div align="right"><font size=-1></font></div><b>testMethod</b><br/><br/><br /> +<h3>Parameters:</h3> +<table cellspacing=0 style="border: 0px; width: 100%;"> +<tr><td> </td><td valign="top" style="text-aling:left; border-width: 0px;padding: 1px;padding:3px;" ><nobr></nobr></td><td valign="top" style="text-aling:left; border-width: 0px;padding: 1px;padding:3px;" ><nobr><b>$a</b></nobr></td><td valign="top" style="text-aling:left; border-width: 0px;padding: 1px;padding:3px;width:80%;" >PHPDoc not found</td></tr> +</table> +<h3>Returns:</h3> +<table> +<tr><th align="left">Type:</th><td>string | int</td></tr></table></body></html> diff --git a/php/php.editor/test/unit/data/testfiles/completion/documentation/issueGH5355.php.testIssueGH5355_02.html b/php/php.editor/test/unit/data/testfiles/completion/documentation/issueGH5355.php.testIssueGH5355_02.html new file mode 100644 index 0000000000..ad2f8cf126 --- /dev/null +++ b/php/php.editor/test/unit/data/testfiles/completion/documentation/issueGH5355.php.testIssueGH5355_02.html @@ -0,0 +1,13 @@ +<html><body> +<pre>Code completion result for source line: +testFunctio|n(null); +(QueryType=COMPLETION, prefixSearch=false, caseSensitive=true) +METHOD testFunction($a) [PUBLIC] issueGH5355.php +</pre><h2>Documentation:</h2><div align="right"><font size=-1></font></div><b>testFunction</b><br/><br/><br /> +<h3>Parameters:</h3> +<table cellspacing=0 style="border: 0px; width: 100%;"> +<tr><td> </td><td valign="top" style="text-aling:left; border-width: 0px;padding: 1px;padding:3px;" ><nobr></nobr></td><td valign="top" style="text-aling:left; border-width: 0px;padding: 1px;padding:3px;" ><nobr><b>$a</b></nobr></td><td valign="top" style="text-aling:left; border-width: 0px;padding: 1px;padding:3px;width:80%;" >PHPDoc not found</td></tr> +</table> +<h3>Returns:</h3> +<table> +<tr><th align="left">Type:</th><td>string | int</td></tr></table></body></html> diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCCDocumentationTest.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCCDocumentationTest.java index f577a537d1..5408e1ca84 100644 --- a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCCDocumentationTest.java +++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCCDocumentationTest.java @@ -338,6 +338,14 @@ public class PHPCCDocumentationTest extends PHPCodeCompletionTestBase { checkCompletionOnlyDocumentation("testfiles/completion/documentation/issueGH5347.php", "un^defined();", true); } + public void testIssueGH5355_01() throws Exception { + checkCompletionDocumentation("testfiles/completion/documentation/issueGH5355.php", "$this->testMetho^d(null);", false, ""); + } + + public void testIssueGH5355_02() throws Exception { + checkCompletionDocumentation("testfiles/completion/documentation/issueGH5355.php", "testFunctio^n(null);", false, ""); + } + @Override protected String alterDocumentationForTest(String documentation) { int start = documentation.indexOf("file:"); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists