tmysik closed pull request #1002: [NETBEANS-1576] PHP autocompletion partially
broken
URL: https://github.com/apache/incubator-netbeans/pull/1002
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/model/impl/ModelVisitor.java
b/php/php.editor/src/org/netbeans/modules/php/editor/model/impl/ModelVisitor.java
index 6af4682c17..573a66089a 100644
---
a/php/php.editor/src/org/netbeans/modules/php/editor/model/impl/ModelVisitor.java
+++
b/php/php.editor/src/org/netbeans/modules/php/editor/model/impl/ModelVisitor.java
@@ -894,14 +894,47 @@ public void visit(Assignment node) {
}
} else {
ASTNode conditionalNode =
findConditionalStatement(getPath());
- VarAssignmentImpl varAssignment = varN.createAssignment(
- scope,
- conditionalNode != null,
- getBlockRange(conditionalNode, scope),
- new OffsetRange(var.getStartOffset(),
var.getEndOffset()),
- node,
- allAssignments);
- varN.addElement(varAssignment);
+ boolean vardocAdded = false;
+ // DO NOT check varN.findVarAssignment(varN.getOffset())
+ // because there is a performance problem if VariableName
has many assignments
+ // (some unit tests fail because of a timeout)
+ if (varN.getElements().isEmpty()) {
+ // NETBEANS-1576
+ // add vardoc info instead of current assignment info
+ List<PhpDocTypeTagInfo> vardocComments =
varTypeComments.get(varN.getName());
+ if (vardocComments != null) {
+ for (PhpDocTypeTagInfo vardocComment :
vardocComments) {
+ if (vardocComment.getRange().getEnd() >
varN.getOffset()
+ ||
!scope.equals(getVariableScope(vardocComment.getRange().getStart()))) {
+ continue;
+ }
+ VarAssignmentImpl varAssignment =
varN.createAssignment(
+ scope,
+ conditionalNode != null,
+ getBlockRange(conditionalNode, scope),
+ new OffsetRange(var.getStartOffset(),
var.getEndOffset()),
+ vardocComment.getTypeName());
+ varN.addElement(varAssignment);
+ vardocAdded = true;
+ }
+ }
+ }
+ if (!vardocAdded) {
+ VarAssignmentImpl varAssignment =
varN.createAssignment(
+ scope,
+ conditionalNode != null,
+ getBlockRange(conditionalNode, scope),
+ new OffsetRange(var.getStartOffset(),
var.getEndOffset()),
+ node,
+ allAssignments);
+ varN.addElement(varAssignment);
+ if (varN.getElements().isEmpty()) {
+ // e.g.
+ // $variable = ...
+ // /* @var $variable TypeName */
+ processVarComment(varN.getName(), scope);
+ }
+ }
}
// #269672 also check the scope if the variable is added
diff --git
a/php/php.editor/test/unit/data/testfiles/completion/lib/_base/varTypeComment.php.testVarTypeCommentVariable02.completion
b/php/php.editor/test/unit/data/testfiles/completion/lib/_base/varTypeComment.php.testVarTypeCommentVariable02.completion
index ec0b8700a0..6e9e0bd51a 100644
---
a/php/php.editor/test/unit/data/testfiles/completion/lib/_base/varTypeComment.php.testVarTypeCommentVariable02.completion
+++
b/php/php.editor/test/unit/data/testfiles/completion/lib/_base/varTypeComment.php.testVarTypeCommentVariable02.completion
@@ -1,4 +1,4 @@
Code completion result for source line:
/*second comment*//* @var $hello|2 type */
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
-VARIABLE mixed $hello [PUBLIC] varTypeComment.php
+VARIABLE VarTypeCommentTest $hello [PUBLIC] varTypeComment.php
diff --git
a/php/php.editor/test/unit/data/testfiles/completion/lib/nb1576/nb1576.php
b/php/php.editor/test/unit/data/testfiles/completion/lib/nb1576/nb1576.php
new file mode 100644
index 0000000000..c686167ef0
--- /dev/null
+++ b/php/php.editor/test/unit/data/testfiles/completion/lib/nb1576/nb1576.php
@@ -0,0 +1,82 @@
+<?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.
+ */
+
+namespace Entity;
+
+class EntityClass {
+
+ public function method1()
+ {
+
+ }
+
+ public function method2()
+ {
+
+ }
+
+ public function method3()
+ {
+
+ }
+
+}
+
+namespace Repo;
+
+use Entity\EntityClass;
+
+/**
+ * @method EntityClass[] getAll()
+ */
+class RepoClass {
+
+ /**
+ *
+ * @param array $params
+ * @return EntityClass
+ */
+ public function findOrCreate(array $params): EntityClass
+ {
+ return new EntityClass();
+ }
+
+}
+
+namespace App;
+
+class App {
+
+ public function exec()
+ {
+ /* @var $repo \Repo\RepoClass */
+ $repo = $magick->getRepo();
+ $obj = $repo->findOrCreate($params);
+ $obj->method1();
+
+ $repo2 = $magick->getRepo();
+ /* @var $repo2 \Repo\RepoClass */
+ $obj2 = $repo2->findOrCreate($params);
+ $obj2->method2();
+ }
+
+}
+
diff --git
a/php/php.editor/test/unit/data/testfiles/completion/lib/nb1576/nb1576.php.testNb1576_01.completion
b/php/php.editor/test/unit/data/testfiles/completion/lib/nb1576/nb1576.php.testNb1576_01.completion
new file mode 100644
index 0000000000..8a8b78c39e
--- /dev/null
+++
b/php/php.editor/test/unit/data/testfiles/completion/lib/nb1576/nb1576.php.testNb1576_01.completion
@@ -0,0 +1,6 @@
+Code completion result for source line:
+$obj->|method1();
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+METHOD method1() [PUBLIC] \Entity\EntityClass
+METHOD method2() [PUBLIC] \Entity\EntityClass
+METHOD method3() [PUBLIC] \Entity\EntityClass
diff --git
a/php/php.editor/test/unit/data/testfiles/completion/lib/nb1576/nb1576.php.testNb1576_02.completion
b/php/php.editor/test/unit/data/testfiles/completion/lib/nb1576/nb1576.php.testNb1576_02.completion
new file mode 100644
index 0000000000..32415549b3
--- /dev/null
+++
b/php/php.editor/test/unit/data/testfiles/completion/lib/nb1576/nb1576.php.testNb1576_02.completion
@@ -0,0 +1,5 @@
+Code completion result for source line:
+$obj = $repo->|findOrCreate($params);
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+METHOD findOrCreate(array $params) [PUBLIC] \Repo\RepoClass
+METHOD getAll() [PUBLIC] \Repo\RepoClass
diff --git
a/php/php.editor/test/unit/data/testfiles/completion/lib/nb1576/nb1576.php.testNb1576_03.completion
b/php/php.editor/test/unit/data/testfiles/completion/lib/nb1576/nb1576.php.testNb1576_03.completion
new file mode 100644
index 0000000000..7e185b5b99
--- /dev/null
+++
b/php/php.editor/test/unit/data/testfiles/completion/lib/nb1576/nb1576.php.testNb1576_03.completion
@@ -0,0 +1,6 @@
+Code completion result for source line:
+$obj2->|method2();
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+METHOD method1() [PUBLIC] \Entity\EntityClass
+METHOD method2() [PUBLIC] \Entity\EntityClass
+METHOD method3() [PUBLIC] \Entity\EntityClass
diff --git
a/php/php.editor/test/unit/data/testfiles/completion/lib/nb1576/nb1576.php.testNb1576_04.completion
b/php/php.editor/test/unit/data/testfiles/completion/lib/nb1576/nb1576.php.testNb1576_04.completion
new file mode 100644
index 0000000000..fd4b922670
--- /dev/null
+++
b/php/php.editor/test/unit/data/testfiles/completion/lib/nb1576/nb1576.php.testNb1576_04.completion
@@ -0,0 +1,5 @@
+Code completion result for source line:
+$obj2 = $repo2->|findOrCreate($params);
+(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
+METHOD findOrCreate(array $params) [PUBLIC] \Repo\RepoClass
+METHOD getAll() [PUBLIC] \Repo\RepoClass
diff --git
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletionNb1576Test.java
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletionNb1576Test.java
new file mode 100644
index 0000000000..be1b515ba2
--- /dev/null
+++
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/completion/PHPCodeCompletionNb1576Test.java
@@ -0,0 +1,62 @@
+/*
+ * 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 PHPCodeCompletionNb1576Test extends PHPCodeCompletionTestBase {
+
+ public PHPCodeCompletionNb1576Test(String testName) {
+ super(testName);
+ }
+
+ public void testNb1576_01() throws Exception {
+ checkCompletion("testfiles/completion/lib/nb1576/nb1576.php",
"$obj->^", false);
+ }
+
+ public void testNb1576_02() throws Exception {
+ checkCompletion("testfiles/completion/lib/nb1576/nb1576.php", "$obj =
$repo->^findOrCreate($params);", false);
+ }
+
+ public void testNb1576_03() throws Exception {
+ checkCompletion("testfiles/completion/lib/nb1576/nb1576.php",
"$obj2->^", false);
+ }
+
+ public void testNb1576_04() throws Exception {
+ checkCompletion("testfiles/completion/lib/nb1576/nb1576.php", "$obj2 =
$repo2->^findOrCreate($params);", 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/nb1576"))
+ })
+ );
+ }
+}
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists