aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2012-11-28 08:15:52 (EST)
committerzzhongwei2012-11-28 08:15:52 (EST)
commitc9c02b4b647574719591b7e2543866e54bd0b9c2 (patch)
tree32afece28143dd39eafc348032f143bd5bfc73be
parent83826dc0ae077e50237172d96cefbc9e60fa8f16 (diff)
downloadorg.eclipse.pdt-c9c02b4b647574719591b7e2543866e54bd0b9c2.zip
org.eclipse.pdt-c9c02b4b647574719591b7e2543866e54bd0b9c2.tar.gz
org.eclipse.pdt-c9c02b4b647574719591b7e2543866e54bd0b9c2.tar.bz2
395275: Studio does not make difference between "\absolute" and
"relative" class names in doc comments, it provokes wrong CA suggestion https://bugs.eclipse.org/bugs/show_bug.cgi?id=395275
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/phpdoc/PHPDocClassVariableEvaluator.java36
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/phpdoc/PHPDocMethodReturnTypeEvaluator.java20
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testClassVarHinting3.pdtt2
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testClassVarHinting4.pdtt2
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testPHPDoc1.pdtt38
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testPHPDoc2.pdtt38
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitMembers8.pdtt40
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal5.pdtt6
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal6.pdtt32
9 files changed, 207 insertions, 7 deletions
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 964662c..41972c3 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
@@ -140,6 +140,10 @@ public class PHPDocClassVariableEvaluator extends AbstractPHPGoalEvaluator {
.getFullyQualifiedName();
typeName = typeName.replace(prefix,
fullName);
+ if (typeName.charAt(0) != NamespaceReference.NAMESPACE_SEPARATOR) {
+ typeName = NamespaceReference.NAMESPACE_SEPARATOR
+ + typeName;
+ }
}
} else if (typeName.indexOf(SPLASH) < 0) {
String prefix = typeName;
@@ -153,6 +157,10 @@ public class PHPDocClassVariableEvaluator extends AbstractPHPGoalEvaluator {
.getNamespace()
.getFullyQualifiedName();
typeName = fullName;
+ if (typeName.charAt(0) != NamespaceReference.NAMESPACE_SEPARATOR) {
+ typeName = NamespaceReference.NAMESPACE_SEPARATOR
+ + typeName;
+ }
}
}
}
@@ -204,6 +212,28 @@ public class PHPDocClassVariableEvaluator extends AbstractPHPGoalEvaluator {
for (String name : typeNames) {
if (!"".equals(name)) {
+ if (name.indexOf(NamespaceReference.NAMESPACE_SEPARATOR) > 0
+ && currentNamespace != null) {
+ // check if the first part is an
+ // alias,then get the full name
+ ModuleDeclaration moduleDeclaration = SourceParserUtil
+ .getModuleDeclaration(currentNamespace
+ .getSourceModule());
+ String prefix = name.substring(0, name
+ .indexOf(NamespaceReference.NAMESPACE_SEPARATOR));
+ final Map<String, UsePart> result = PHPModelUtils
+ .getAliasToNSMap(prefix, moduleDeclaration, offset,
+ currentNamespace, true);
+ if (result.containsKey(prefix)) {
+ String fullName = result.get(prefix).getNamespace()
+ .getFullyQualifiedName();
+ name = name.replace(prefix, fullName);
+ if (name.charAt(0) != NamespaceReference.NAMESPACE_SEPARATOR) {
+ name = NamespaceReference.NAMESPACE_SEPARATOR
+ + name;
+ }
+ }
+ }
arrayType.addType(getEvaluatedType(name, currentNamespace));
}
}
@@ -214,6 +244,12 @@ public class PHPDocClassVariableEvaluator extends AbstractPHPGoalEvaluator {
IType currentNamespace) {
IEvaluatedType type = PHPSimpleTypes.fromString(typeName);
if (type == null) {
+ if (typeName.indexOf(NamespaceReference.NAMESPACE_SEPARATOR) > 0
+ && currentNamespace != null) {
+ typeName = NamespaceReference.NAMESPACE_SEPARATOR
+ + currentNamespace.getElementName()
+ + NamespaceReference.NAMESPACE_SEPARATOR + typeName;
+ }
if (typeName.indexOf(NamespaceReference.NAMESPACE_SEPARATOR) != -1
|| currentNamespace == null) {
type = new PHPClassType(typeName);
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/phpdoc/PHPDocMethodReturnTypeEvaluator.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/phpdoc/PHPDocMethodReturnTypeEvaluator.java
index 78bb326..664cb6f 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/phpdoc/PHPDocMethodReturnTypeEvaluator.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/phpdoc/PHPDocMethodReturnTypeEvaluator.java
@@ -131,7 +131,7 @@ public class PHPDocMethodReturnTypeEvaluator extends
if (docBlock == null) {
return IGoal.NO_GOALS;
}
-
+
evaluateReturnType(returnTypeList, docBlock, method);
typeNames = returnTypeList.toArray(new String[returnTypeList
.size()]);
@@ -197,6 +197,10 @@ public class PHPDocMethodReturnTypeEvaluator extends
.getFullyQualifiedName();
typeName = typeName.replace(prefix,
fullName);
+ if (typeName.charAt(0) != NamespaceReference.NAMESPACE_SEPARATOR) {
+ typeName = NamespaceReference.NAMESPACE_SEPARATOR
+ + typeName;
+ }
}
} else if (typeName
.indexOf(NamespaceReference.NAMESPACE_SEPARATOR) < 0) {
@@ -212,6 +216,10 @@ public class PHPDocMethodReturnTypeEvaluator extends
.getNamespace()
.getFullyQualifiedName();
typeName = fullName;
+ if (typeName.charAt(0) != NamespaceReference.NAMESPACE_SEPARATOR) {
+ typeName = NamespaceReference.NAMESPACE_SEPARATOR
+ + typeName;
+ }
}
}
}
@@ -269,6 +277,10 @@ public class PHPDocMethodReturnTypeEvaluator extends
String fullName = result.get(prefix).getNamespace()
.getFullyQualifiedName();
name = name.replace(prefix, fullName);
+ if (name.charAt(0) != NamespaceReference.NAMESPACE_SEPARATOR) {
+ name = NamespaceReference.NAMESPACE_SEPARATOR
+ + name;
+ }
}
}
arrayType.addType(getEvaluatedType(name, currentNamespace));
@@ -281,6 +293,12 @@ public class PHPDocMethodReturnTypeEvaluator extends
IType currentNamespace) {
IEvaluatedType type = PHPSimpleTypes.fromString(typeName);
if (type == null) {
+ if (typeName.indexOf(NamespaceReference.NAMESPACE_SEPARATOR) > 0
+ && currentNamespace != null) {
+ typeName = NamespaceReference.NAMESPACE_SEPARATOR
+ + currentNamespace.getElementName()
+ + NamespaceReference.NAMESPACE_SEPARATOR + typeName;
+ }
if (typeName.indexOf(NamespaceReference.NAMESPACE_SEPARATOR) != -1
|| currentNamespace == null) {
type = new PHPClassType(typeName);
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testClassVarHinting3.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testClassVarHinting3.pdtt
index d53d722..1fa1dcf 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testClassVarHinting3.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testClassVarHinting3.pdtt
@@ -18,7 +18,7 @@ namespace NS3 {
// use NS2;
class TestClass {
/**
- * @var NS1\If1
+ * @var \NS1\If1
*/
public $_testObject;
}
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testClassVarHinting4.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testClassVarHinting4.pdtt
index f2b810a..a0d84d3 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testClassVarHinting4.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testClassVarHinting4.pdtt
@@ -18,7 +18,7 @@ namespace NS3 {
// use NS2;
class TestClass {
/**
- * @var NS1\If1|NS2\If2
+ * @var \NS1\If1|\NS2\If2
*/
public $_testObject;
}
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testPHPDoc1.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testPHPDoc1.pdtt
new file mode 100644
index 0000000..3d5311c
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testPHPDoc1.pdtt
@@ -0,0 +1,38 @@
+--TEST--
+Should complete current namespace class defined in function
+--FILE--
+<?php
+namespace foo\bar\baz
+{
+class Target { function foo_bar_baz(); }
+}
+
+namespace bar\baz
+{
+class Target { function bar_baz(); }
+}
+
+namespace foo
+{
+class TestAbsolute
+{
+/**
+* @return \bar\baz\Target
+*/
+function test() {}
+}
+
+class TestRelative
+{
+/**
+* @return bar\baz\Target
+*/
+function test() {}
+}
+
+$testRelative = new TestRelative();
+$testRelative->test()->| // hint appears for bar_baz() again, this is WRONG. It should be foo_bar_baz()
+}
+?>
+--EXPECT--
+method(foo_bar_baz)
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testPHPDoc2.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testPHPDoc2.pdtt
new file mode 100644
index 0000000..44b91a8
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php53/testPHPDoc2.pdtt
@@ -0,0 +1,38 @@
+--TEST--
+Should complete current namespace class defined in function
+--FILE--
+<?php
+namespace foo\bar\baz
+{
+class Target { function foo_bar_baz(); }
+}
+
+namespace bar\baz
+{
+class Target { function bar_baz(); }
+}
+
+namespace foo
+{
+class TestAbsolute
+{
+/**
+* @return \bar\baz\Target
+*/
+function test() {}
+}
+
+class TestRelative
+{
+/**
+* @return bar\baz\Target
+*/
+function test() {}
+}
+
+$testAbsolute = new TestAbsolute();
+$testAbsolute->test()->| // hint appears for bar_baz(), this is CORRECT
+}
+?>
+--EXPECT--
+method(bar_baz)
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitMembers8.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitMembers8.pdtt
new file mode 100644
index 0000000..e127032
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitMembers8.pdtt
@@ -0,0 +1,40 @@
+--TEST--
+Test trait Members 8
+--PREFERENCES--
+org.eclipse.php.core/contentAssistShowStrictOptions=false
+--FILE--
+<?php
+namespace Traits; // Second line that breaks it
+
+trait singleton {
+
+ private static $oInstance;
+
+ public static function getSingleton() {
+ if(!self::$oInstance instanceof self) {
+ self::$oInstance = new self;
+ }
+ return self::$oInstance;
+ }
+}
+namespace TestNamespace;
+
+require_once '386637.php';
+
+class UnNameSpacedClass {
+
+ /**
+ * @var \UnNameSpacedClass
+ * @return \UnNameSpacedClass
+ */
+ use \Traits\singleton; // First line that breaks it
+
+ public function testFunction() {
+ echo 'Test Function';
+ }
+}
+// Test 1: Not Working
+UnNameSpacedClass::|
+?>
+--EXPECT--
+method(getSingleton) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal5.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal5.pdtt
index 30a6034..46fe2ee 100644
--- a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal5.pdtt
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal5.pdtt
@@ -28,9 +28,7 @@ class Aliased_Talker {
B::bigTalk |;
}
}
-$o= new Aliased_Talker();
-$o->|
?>
---EXPECT---
-keyword(as)-
+--EXPECT--
+keyword(as)
keyword(insteadof) \ No newline at end of file
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal6.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal6.pdtt
new file mode 100644
index 0000000..7d1b470
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsProposal6.pdtt
@@ -0,0 +1,32 @@
+--TEST--
+Test trait method conflict resolution 8
+--PREFERENCES--
+org.eclipse.php.core/contentAssistShowStrictOptions=false
+--FILE--
+<?php
+trait A {
+ public function smallTalk() {
+ echo 'a';
+ }
+ public function bigTalk() {
+ echo 'A';
+ }
+}
+
+trait B {
+ public function smallTalk() {
+ echo 'b';
+ }
+ public function bigTalk() {
+ echo 'B';
+ }
+}
+class Aliased_Talker {
+ use A, B {
+ B::|;
+ }
+}
+?>
+--EXPECT--
+method(bigTalk)
+method(smallTalk) \ No newline at end of file