aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2013-01-16 03:57:13 (EST)
committerzzhongwei2013-01-16 03:57:13 (EST)
commit106fbaaf449c9564ffe78590576e0bfa9bfd24d4 (patch)
tree82812a7f9d662ba5a843e139e8fc204a92d89d02
parent0a0be4da4b9df51d89928a9e52bce7c948c3f97a (diff)
downloadorg.eclipse.pdt-106fbaaf449c9564ffe78590576e0bfa9bfd24d4.zip
org.eclipse.pdt-106fbaaf449c9564ffe78590576e0bfa9bfd24d4.tar.gz
org.eclipse.pdt-106fbaaf449c9564ffe78590576e0bfa9bfd24d4.tar.bz2
396894: Autocomplete have a problem with recognizing array className[]
in @method tag https://bugs.eclipse.org/bugs/show_bug.cgi?id=396894
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/MethodReturnTypeEvaluator.java31
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/phpdoc/PHPDocClassVariableEvaluator.java8
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassMembers28-nonstrict.pdtt50
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassMembers28-strict.pdtt50
4 files changed, 130 insertions, 9 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/MethodReturnTypeEvaluator.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/MethodReturnTypeEvaluator.java
index bd0b2cf..1197639 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/MethodReturnTypeEvaluator.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/MethodReturnTypeEvaluator.java
@@ -13,6 +13,7 @@ package org.eclipse.php.internal.core.typeinference.evaluators;
import java.util.LinkedList;
import java.util.List;
+import java.util.regex.Matcher;
import org.eclipse.dltk.ast.ASTNode;
import org.eclipse.dltk.ast.ASTVisitor;
@@ -34,6 +35,7 @@ import org.eclipse.php.internal.core.typeinference.PHPModelUtils;
import org.eclipse.php.internal.core.typeinference.PHPSimpleTypes;
import org.eclipse.php.internal.core.typeinference.PHPTypeInferenceUtils;
import org.eclipse.php.internal.core.typeinference.context.MethodContext;
+import org.eclipse.php.internal.core.typeinference.evaluators.phpdoc.PHPDocClassVariableEvaluator;
import org.eclipse.php.internal.core.typeinference.goals.MethodElementReturnTypeGoal;
public class MethodReturnTypeEvaluator extends
@@ -119,17 +121,35 @@ public class MethodReturnTypeEvaluator extends
IType type = (IType) parent;
final PHPDocBlock docBlock = PHPModelUtils.getDocBlock(type);
if (docBlock != null) {
+ IType currentNamespace = PHPModelUtils.getCurrentNamespace(type);
for (PHPDocTag tag : docBlock.getTags()) {
final int tagKind = tag.getTagKind();
if (tagKind == PHPDocTag.METHOD) {
final String typeName = getTypeBinding(methodName, tag);
if (typeName != null) {
- IEvaluatedType resolved = PHPSimpleTypes
- .fromString(typeName);
- if (resolved == null) {
- resolved = new PHPClassType(typeName);
+ Matcher m = PHPDocClassVariableEvaluator.ARRAY_TYPE_PATTERN
+ .matcher(typeName);
+ if (m.find()) {
+ evaluated.add(PHPDocClassVariableEvaluator
+ .getArrayType(m.group(), currentNamespace,
+ tag.sourceStart()));
+ } else if (typeName
+ .endsWith(PHPDocClassVariableEvaluator.BRACKETS)
+ && typeName.length() > 2) {
+ int offset = tag.sourceStart();
+ evaluated.add(PHPDocClassVariableEvaluator
+ .getArrayType(
+ typeName.substring(0,
+ typeName.length() - 2),
+ currentNamespace, offset));
+ } else {
+ IEvaluatedType resolved = PHPSimpleTypes
+ .fromString(typeName);
+ if (resolved == null) {
+ resolved = new PHPClassType(typeName);
+ }
+ evaluated.add(resolved);
}
- evaluated.add(resolved);
}
}
}
@@ -168,4 +188,5 @@ public class MethodReturnTypeEvaluator extends
public Object produceResult() {
return PHPTypeInferenceUtils.combineTypes(evaluated);
}
+
}
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/phpdoc/PHPDocClassVariableEvaluator.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/phpdoc/PHPDocClassVariableEvaluator.java
index 41972c3..a51a998 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/phpdoc/PHPDocClassVariableEvaluator.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/phpdoc/PHPDocClassVariableEvaluator.java
@@ -46,7 +46,7 @@ public class PHPDocClassVariableEvaluator extends AbstractPHPGoalEvaluator {
private List<IEvaluatedType> evaluated = new LinkedList<IEvaluatedType>();
- private final static Pattern ARRAY_TYPE_PATTERN = Pattern
+ public final static Pattern ARRAY_TYPE_PATTERN = Pattern
.compile("array\\[.*\\]");
public PHPDocClassVariableEvaluator(IGoal goal) {
@@ -194,8 +194,8 @@ public class PHPDocClassVariableEvaluator extends AbstractPHPGoalEvaluator {
return IGoal.NO_GOALS;
}
- private MultiTypeType getArrayType(String type, IType currentNamespace,
- int offset) {
+ public static MultiTypeType getArrayType(String type,
+ IType currentNamespace, int offset) {
int beginIndex = type.indexOf("[") + 1;
int endIndex = type.lastIndexOf("]");
if (endIndex != -1) {
@@ -240,7 +240,7 @@ public class PHPDocClassVariableEvaluator extends AbstractPHPGoalEvaluator {
return arrayType;
}
- private IEvaluatedType getEvaluatedType(String typeName,
+ public static IEvaluatedType getEvaluatedType(String typeName,
IType currentNamespace) {
IEvaluatedType type = PHPSimpleTypes.fromString(typeName);
if (type == null) {
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassMembers28-nonstrict.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassMembers28-nonstrict.pdtt
new file mode 100644
index 0000000..f2d300c
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassMembers28-nonstrict.pdtt
@@ -0,0 +1,50 @@
+--TEST--
+Test class constructor
+--PREFERENCES--
+org.eclipse.php.core/contentAssistShowStrictOptions=false
+--FILE--
+<?
+
+/**
+*
+* @method Foo[] getAllWithProblem() getAllWithProblem()
+*/
+class Foo
+{
+
+/**
+*
+* @return Foo[]
+*/
+public function getAllNoProblem()
+{
+return array( new Foo() );
+}
+
+static public function testScenerios()
+{
+// scenerio 1
+$oFoo1 = $this->getOne();
+// works
+$oFoo1->autocompleteWorks();
+
+// scenerio 2
+foreach($this->getAllNoProblem() as $oFoo2)
+{
+// works
+$oFoo2->autocompleteWorks();
+}
+
+// scenerio 3
+foreach($this->getAllWithProblem() as $oFoo3)
+{
+// dosen't work
+$oFoo3->|
+}
+}
+}
+?>
+--EXPECT--
+method(getAllNoProblem)
+method(getAllWithProblem)
+method(testScenerios) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassMembers28-strict.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassMembers28-strict.pdtt
new file mode 100644
index 0000000..2866afd
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php5/testClassMembers28-strict.pdtt
@@ -0,0 +1,50 @@
+--TEST--
+Test class constructor
+--PREFERENCES--
+org.eclipse.php.core/contentAssistShowStrictOptions=true
+--FILE--
+<?
+
+/**
+*
+* @method Foo[] getAllWithProblem() getAllWithProblem()
+*/
+class Foo
+{
+
+/**
+*
+* @return Foo[]
+*/
+public function getAllNoProblem()
+{
+return array( new Foo() );
+}
+
+static public function testScenerios()
+{
+// scenerio 1
+$oFoo1 = $this->getOne();
+// works
+$oFoo1->autocompleteWorks();
+
+// scenerio 2
+foreach($this->getAllNoProblem() as $oFoo2)
+{
+// works
+$oFoo2->autocompleteWorks();
+}
+
+// scenerio 3
+foreach($this->getAllWithProblem() as $oFoo3)
+{
+// dosen't work
+$oFoo3->|
+}
+}
+}
+?>
+--EXPECT--
+method(getAllNoProblem)
+method(getAllWithProblem)
+method(testScenerios) \ No newline at end of file