You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/11/10 06:25:27 UTC

[GitHub] tmysik closed pull request #1018: [NETBEANS-792] Return type CC does not work correctly when arguments have a default value

tmysik closed pull request #1018: [NETBEANS-792] Return type CC does not work correctly when arguments have a default value
URL: https://github.com/apache/incubator-netbeans/pull/1018
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/completion/CompletionContextFinder.java b/php/php.editor/src/org/netbeans/modules/php/editor/completion/CompletionContextFinder.java
index 74e5652307..2ae678915a 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/completion/CompletionContextFinder.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/completion/CompletionContextFinder.java
@@ -826,7 +826,8 @@ private static CompletionContext getParamaterContext(Token<PHPTokenId> token, in
                 // check reference character (&) [unfortunately, cannot distinguish & as a operator and as a reference mark]
                 // check "..." (is it really operator?)
                 if (!isReference(cToken)
-                        && !isVariadic(cToken)) {
+                        && !isVariadic(cToken)
+                        && !isInitilizerToken(cToken)) { // ($param = '')
                     break;
                 }
             }
@@ -943,6 +944,16 @@ private static boolean isNullableTypesPrefix(Token<PHPTokenId> token) {
                 && TokenUtilities.textEquals(token.text(), "?"); // NOI18N
     }
 
+    private static boolean isMinus(Token<PHPTokenId> token) {
+        return token.id().equals(PHPTokenId.PHP_OPERATOR)
+                && TokenUtilities.textEquals(token.text(), "-"); // NOI18N
+    }
+
+    private static boolean isQuoteString(Token<PHPTokenId> token) {
+        return token.id() == PHPTokenId.PHP_CONSTANT_ENCAPSED_STRING
+                && (TokenUtilities.startsWith(token.text(), "'") || (TokenUtilities.startsWith(token.text(), "\""))); // NOI18N
+    }
+
     private static boolean isArray(Token<PHPTokenId> token) {
         return token.id().equals(PHPTokenId.PHP_ARRAY);
     }
@@ -984,6 +995,12 @@ private static boolean isString(Token<PHPTokenId> token) {
         return token.id().equals(PHPTokenId.PHP_STRING);
     }
 
+    private static boolean isInitilizerToken(Token<PHPTokenId> token) {
+        return isQuoteString(token)
+                || isEqualSign(token)
+                || isMinus(token);
+    }
+
     static boolean lineContainsAny(Token<PHPTokenId> token, int tokenOffset, TokenSequence<PHPTokenId> tokenSequence, List<PHPTokenId> ids) {
         List<? extends Token<PHPTokenId>> preceedingLineTokens = getPreceedingLineTokens(token, tokenOffset, tokenSequence);
         for (Token<PHPTokenId> t : preceedingLineTokens) {
diff --git a/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php
new file mode 100644
index 0000000000..1023298c3c
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.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.
+ */
+
+function something1($arg):a {}
+
+function something2($arg = ''):a {}
+
+function something3($arg = "test"):a {}
+
+function something4($arg = array("test")):a {}
+
+function something5($arg = ["test"]):a {}
+
+function something6($arg = 10):a {}
+
+function something7($arg = -10):a {}
+
+function something8($arg = -1.0):a {}
+
+function something9($arg = true):a {}
+
+function something10($arg = false):a {}
+
+function something11($arg = null):a {}
diff --git a/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_01.completion b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_01.completion
new file mode 100644
index 0000000000..d72701192b
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_01.completion
@@ -0,0 +1,5 @@
+Code completion result for source line:
+function something1($arg):a| {}
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+------------------------------------
+KEYWORD    array                                      null
diff --git a/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_02.completion b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_02.completion
new file mode 100644
index 0000000000..2f74bc9716
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_02.completion
@@ -0,0 +1,5 @@
+Code completion result for source line:
+function something2($arg = ''):a| {}
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+------------------------------------
+KEYWORD    array                                      null
diff --git a/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_03.completion b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_03.completion
new file mode 100644
index 0000000000..4f4bd57bba
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_03.completion
@@ -0,0 +1,5 @@
+Code completion result for source line:
+function something3($arg = "test"):a| {}
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+------------------------------------
+KEYWORD    array                                      null
diff --git a/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_04.completion b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_04.completion
new file mode 100644
index 0000000000..4b505b6bc8
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_04.completion
@@ -0,0 +1,5 @@
+Code completion result for source line:
+function something4($arg = array("test")):a| {}
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+------------------------------------
+KEYWORD    array                                      null
diff --git a/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_05.completion b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_05.completion
new file mode 100644
index 0000000000..dde2ae57d2
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_05.completion
@@ -0,0 +1,5 @@
+Code completion result for source line:
+function something5($arg = ["test"]):a| {}
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+------------------------------------
+KEYWORD    array                                      null
diff --git a/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_06.completion b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_06.completion
new file mode 100644
index 0000000000..cdf30ebbf4
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_06.completion
@@ -0,0 +1,5 @@
+Code completion result for source line:
+function something6($arg = 10):a| {}
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+------------------------------------
+KEYWORD    array                                      null
diff --git a/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_07.completion b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_07.completion
new file mode 100644
index 0000000000..96e1cee129
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_07.completion
@@ -0,0 +1,5 @@
+Code completion result for source line:
+function something7($arg = -10):a| {}
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+------------------------------------
+KEYWORD    array                                      null
diff --git a/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_08.completion b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_08.completion
new file mode 100644
index 0000000000..d8b0a6e21f
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_08.completion
@@ -0,0 +1,5 @@
+Code completion result for source line:
+function something8($arg = -1.0):a| {}
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+------------------------------------
+KEYWORD    array                                      null
diff --git a/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_09.completion b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_09.completion
new file mode 100644
index 0000000000..0f529305c5
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_09.completion
@@ -0,0 +1,5 @@
+Code completion result for source line:
+function something9($arg = true):a| {}
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+------------------------------------
+KEYWORD    array                                      null
diff --git a/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_10.completion b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_10.completion
new file mode 100644
index 0000000000..b932ab34cb
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_10.completion
@@ -0,0 +1,5 @@
+Code completion result for source line:
+function something10($arg = false):a| {}
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+------------------------------------
+KEYWORD    array                                      null
diff --git a/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_11.completion b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_11.completion
new file mode 100644
index 0000000000..668fb9f301
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/completion/lib/nb792/nb792.php.testNb792_11.completion
@@ -0,0 +1,5 @@
+Code completion result for source line:
+function something11($arg = null):a| {}
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+------------------------------------
+KEYWORD    array                                      null
diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletionNb792Test.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletionNb792Test.java
new file mode 100644
index 0000000000..c00f5c2d6e
--- /dev/null
+++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletionNb792Test.java
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+package org.netbeans.modules.php.editor.completion;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.Map;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.modules.php.project.api.PhpSourcePath;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+
+public class PHPCodeCompletionNb792Test extends PHPCodeCompletionTestBase {
+
+    public PHPCodeCompletionNb792Test(String testName) {
+        super(testName);
+    }
+
+    public void testNb792_01() throws Exception {
+        checkCompletion("testfiles/completion/lib/nb792/nb792.php", "function something1($arg):a^ {}", false);
+    }
+
+    public void testNb792_02() throws Exception {
+        checkCompletion("testfiles/completion/lib/nb792/nb792.php", "function something2($arg = ''):a^ {}", false);
+    }
+
+    public void testNb792_03() throws Exception {
+        checkCompletion("testfiles/completion/lib/nb792/nb792.php", "function something3($arg = \"test\"):a^ {}", false);
+    }
+
+    public void testNb792_04() throws Exception {
+        checkCompletion("testfiles/completion/lib/nb792/nb792.php", "function something4($arg = array(\"test\")):a^ {}", false);
+    }
+
+    public void testNb792_05() throws Exception {
+        checkCompletion("testfiles/completion/lib/nb792/nb792.php", "function something5($arg = [\"test\"]):a^ {}", false);
+    }
+
+    public void testNb792_06() throws Exception {
+        checkCompletion("testfiles/completion/lib/nb792/nb792.php", "function something6($arg = 10):a^ {}", false);
+    }
+
+    public void testNb792_07() throws Exception {
+        checkCompletion("testfiles/completion/lib/nb792/nb792.php", "function something7($arg = -10):a^ {}", false);
+    }
+
+    public void testNb792_08() throws Exception {
+        checkCompletion("testfiles/completion/lib/nb792/nb792.php", "function something8($arg = -1.0):a^ {}", false);
+    }
+
+    public void testNb792_09() throws Exception {
+        checkCompletion("testfiles/completion/lib/nb792/nb792.php", "function something9($arg = true):a^ {}", false);
+    }
+
+    public void testNb792_10() throws Exception {
+        checkCompletion("testfiles/completion/lib/nb792/nb792.php", "function something10($arg = false):a^ {}", false);
+    }
+
+    public void testNb792_11() throws Exception {
+        checkCompletion("testfiles/completion/lib/nb792/nb792.php", "function something11($arg = null):a^ {}", false);
+    }
+
+    @Override
+    protected Map<String, ClassPath> createClassPathsForTest() {
+        return Collections.singletonMap(
+            PhpSourcePath.SOURCE_CP,
+            ClassPathSupport.createClassPath(new FileObject[] {
+                FileUtil.toFileObject(new File(getDataDir(), "/testfiles/completion/lib/nb792"))
+            })
+        );
+    }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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