aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2012-08-07 01:15:53 (EDT)
committerzzhongwei2012-08-07 01:15:53 (EDT)
commit7f10b9e54911da1b7ec220d86333eef301fc5896 (patch)
tree61f39d01ea2f6082b71159591d41d88cf1f4cfec
parentad03393790d2a2c01cfa6aa49846f6e43898ca80 (diff)
downloadorg.eclipse.pdt-7f10b9e54911da1b7ec220d86333eef301fc5896.zip
org.eclipse.pdt-7f10b9e54911da1b7ec220d86333eef301fc5896.tar.gz
org.eclipse.pdt-7f10b9e54911da1b7ec220d86333eef301fc5896.tar.bz2
Bug 385837 - Support Traits in Content-Assist
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/ClassVariableDeclarationEvaluator.java9
-rw-r--r--tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsSingleton.pdtt44
2 files changed, 53 insertions, 0 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/ClassVariableDeclarationEvaluator.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/ClassVariableDeclarationEvaluator.java
index 97d725b..75c41b7 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/ClassVariableDeclarationEvaluator.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/typeinference/evaluators/ClassVariableDeclarationEvaluator.java
@@ -273,6 +273,7 @@ public class ClassVariableDeclarationEvaluator extends AbstractPHPGoalEvaluator
*/
class ClassDeclarationSearcher extends ContextFinder {
+ private static final String NULL = "null";
private TypeDeclaration typeDeclaration;
private ASTNode result;
private IContext context;
@@ -326,6 +327,14 @@ public class ClassVariableDeclarationEvaluator extends AbstractPHPGoalEvaluator
&& phpFieldDecl.sourceEnd()
- phpFieldDecl.getDeclarationStart() == length) {
result = ((PHPFieldDeclaration) e).getVariableValue();
+ if (result instanceof Scalar) {
+ Scalar scalar = (Scalar) result;
+ if (scalar.getScalarType() == Scalar.TYPE_STRING
+ && scalar.getValue().toLowerCase()
+ .equals(NULL)) {
+ result = null;
+ }
+ }
context = contextStack.peek();
}
}
diff --git a/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsSingleton.pdtt b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsSingleton.pdtt
new file mode 100644
index 0000000..c46195f
--- /dev/null
+++ b/tests/org.eclipse.php.core.tests/workspace/codeassist/php54/testTraitsSingleton.pdtt
@@ -0,0 +1,44 @@
+--TEST--
+Test traits suggestion from CLA 1
+--PREFERENCES--
+org.eclipse.php.core/contentAssistShowStrictOptions=false
+--FILE--
+<?php
+trait singleton
+{
+ private static $oInstance = null;
+
+ public static function getSingleton() {
+ if(!self::$oInstance instanceof self) {
+ self::$oInstance = new self;
+ }
+ return self::$oInstance;
+
+ }
+}
+
+class NewClass
+{
+ /**
+ * @var NewClass
+ * @return NewClass
+ */
+ use singleton;
+
+ public function display() {
+ echo get_class($this);
+ }
+
+ protected function doSomething() {
+ // Would be nice for the definition of @var NewClass above
+ // to allow Ctrl space to show available instance methods
+ // on self::$oInstance->
+ self::$oInstance->display();
+ }
+}
+
+NewClass::getSingleton()->|
+?>
+--EXPECT--
+method(display)
+method(getSingleton) \ No newline at end of file