Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry BLIND2019-08-12 11:50:46 -0400
committerThierry BLIND2019-08-12 11:50:46 -0400
commit4777cefa2bfb5ec19d757583dbf20e41dd1613a3 (patch)
tree0eea67842820f29538fc950289c9d7c1a221a796
parent5ea982b350d7546e949fe89641d1e3074fd6a165 (diff)
downloadorg.eclipse.pdt-4777cefa2bfb5ec19d757583dbf20e41dd1613a3.tar.gz
org.eclipse.pdt-4777cefa2bfb5ec19d757583dbf20e41dd1613a3.tar.xz
org.eclipse.pdt-4777cefa2bfb5ec19d757583dbf20e41dd1613a3.zip
Bug 549957 - Deprecated class highlighting doesn't work on class
instantiation Also tweak the static member accesses Change-Id: I9d167dba850169caec5a771de9bac93b441700e5 Signed-off-by: Thierry BLIND <thierryblind@msn.com>
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/highlighters/ClassHighlighting.java4
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/highlighters/DeprecatedHighlighting.java52
-rw-r--r--tests/org.eclipse.php.ui.tests/workspace/semantic_highlighting/php53/deprecated.06.pdtt78
3 files changed, 119 insertions, 15 deletions
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/highlighters/ClassHighlighting.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/highlighters/ClassHighlighting.java
index 7bd4cc7e9..dbe46ab5f 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/highlighters/ClassHighlighting.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/highlighters/ClassHighlighting.java
@@ -195,6 +195,9 @@ public class ClassHighlighting extends AbstractSemanticHighlighting {
return true;
}
+ /**
+ * @see DeprecatedHighlighting#highlightStatic(StaticDispatch)
+ */
private void highlightStatic(StaticDispatch dispatch) {
Expression className = dispatch.getClassName();
if (className instanceof NamespaceName) {
@@ -212,7 +215,6 @@ public class ClassHighlighting extends AbstractSemanticHighlighting {
}
/**
- *
* @see DeprecatedHighlighting#highlightLastNamespaceSegment(NamespaceName)
*/
private void highlightNamespaceType(NamespaceName name, boolean excludeSelf) {
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/highlighters/DeprecatedHighlighting.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/highlighters/DeprecatedHighlighting.java
index 76bed5f6b..4b0c1d950 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/highlighters/DeprecatedHighlighting.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/highlighters/DeprecatedHighlighting.java
@@ -58,14 +58,14 @@ public class DeprecatedHighlighting extends AbstractSemanticHighlighting {
}
@Override
- public boolean visit(ClassName classConst) {
- Expression classNode = classConst.getName();
+ public boolean visit(ClassName className) {
+ Expression classNode = className.getName();
if (classNode instanceof Identifier) {
- String className = ((Identifier) classNode).getName();
- IModelAccessCache cache = classConst.getAST().getBindingResolver().getModelAccessCache();
+ String typeName = ((Identifier) classNode).getName();
+ IModelAccessCache cache = className.getAST().getBindingResolver().getModelAccessCache();
try {
- IType[] types = PHPModelUtils.getTypes(className, getSourceModule(), classConst.getStart(), cache,
+ IType[] types = PHPModelUtils.getTypes(typeName, getSourceModule(), className.getStart(), cache,
new NullProgressMonitor());
if (types != null) {
for (IType type : types) {
@@ -81,16 +81,22 @@ public class DeprecatedHighlighting extends AbstractSemanticHighlighting {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=549957
// See also
// ClassHighlighting#visit(ClassInstanceCreation)
- if (!(ClassHighlighting.SELF.equalsIgnoreCase(className)
- || ClassHighlighting.CLASS.equalsIgnoreCase(className)
- || ClassHighlighting.PARENT.equalsIgnoreCase(className))) {
- highlight(classConst);
+ // and
+ // DeprecatedHighlighting#highlightStatic(StaticDispatch).
+ if (!(ClassHighlighting.SELF.equalsIgnoreCase(typeName)
+ || ClassHighlighting.CLASS.equalsIgnoreCase(typeName)
+ || ClassHighlighting.PARENT.equalsIgnoreCase(typeName))) {
+ // We want to highlight all NamespaceName
+ // segments, so don't do
+ // highlight(classNode) that will only
+ // highlight last NamespaceName segment.
+ highlight(className);
}
if (classNode instanceof NamespaceName) {
// ...so we must render again the class
// name "Deprecated Highlighting"
// on top of the class name
- // "Class Highlighting"
+ // "Class Highlighting".
highlightLastNamespaceSegment((NamespaceName) classNode);
}
break;
@@ -110,7 +116,7 @@ public class DeprecatedHighlighting extends AbstractSemanticHighlighting {
ITypeBinding type = staticConstantAccess.getClassName().resolveTypeBinding();
if (type != null && ModelUtils.isDeprecated(type.getPHPElement())) {
- highlight(staticConstantAccess.getClassName());
+ highlightStatic(staticConstantAccess);
}
String fieldName = staticConstantAccess.getConstant().getName();
@@ -145,7 +151,7 @@ public class DeprecatedHighlighting extends AbstractSemanticHighlighting {
ITypeBinding type = staticFieldAccess.getClassName().resolveTypeBinding();
if (type != null && ModelUtils.isDeprecated(type.getPHPElement())) {
- highlight(staticFieldAccess.getClassName());
+ highlightStatic(staticFieldAccess);
}
String fieldName = null;
@@ -197,7 +203,7 @@ public class DeprecatedHighlighting extends AbstractSemanticHighlighting {
ITypeBinding type = methodInvocation.getClassName().resolveTypeBinding();
if (type != null && ModelUtils.isDeprecated(type.getPHPElement())) {
- highlight(methodInvocation.getClassName());
+ highlightStatic(methodInvocation);
}
IMethod method = ModelUtils.getMethod(methodInvocation);
@@ -249,7 +255,25 @@ public class DeprecatedHighlighting extends AbstractSemanticHighlighting {
}
/**
- *
+ * @see ClassApply#highlightStatic(StaticDispatch)
+ */
+ private void highlightStatic(StaticDispatch dispatch) {
+ Expression className = dispatch.getClassName();
+ if (className instanceof Identifier) {
+ if (!ClassHighlighting.SELF.equalsIgnoreCase(((Identifier) className).getName())
+ && !ClassHighlighting.PARENT.equalsIgnoreCase(((Identifier) className).getName())) {
+ // We want to highlight all NamespaceName segments,
+ // so don't use this.highlight(className) that will only
+ // highlight last NamespaceName segment.
+ super.highlight(className);
+ }
+ }
+ if (className instanceof NamespaceName) {
+ highlightLastNamespaceSegment((NamespaceName) className);
+ }
+ }
+
+ /**
* @see ClassApply#highlightNamespaceType(NamespaceName, boolean)
*/
private void highlightLastNamespaceSegment(NamespaceName name) {
diff --git a/tests/org.eclipse.php.ui.tests/workspace/semantic_highlighting/php53/deprecated.06.pdtt b/tests/org.eclipse.php.ui.tests/workspace/semantic_highlighting/php53/deprecated.06.pdtt
new file mode 100644
index 000000000..d143a6ab0
--- /dev/null
+++ b/tests/org.eclipse.php.ui.tests/workspace/semantic_highlighting/php53/deprecated.06.pdtt
@@ -0,0 +1,78 @@
+--TEST--
+Bug 549957 - Deprecated class highlighting doesn't work on class instantiation
+--FILE--
+<?php
+namespace A\B;
+
+/**
+ *
+ * @deprecated
+ */
+class myClass3
+{
+
+ /**
+ *
+ * @return integer
+ * @deprecated
+ */
+ public function foo1()
+ {
+ return 1;
+ }
+}
+
+/**
+ *
+ * @deprecated
+ */
+class myClass4 extends myClass3
+{
+
+ /**
+ *
+ * @var integer
+ * @deprecated
+ */
+ public static $a = 1;
+
+ /**
+ *
+ * @return integer
+ * @deprecated
+ */
+ public function foo1()
+ {
+ return self::$a;
+ }
+
+ /**
+ *
+ * @return integer
+ * @deprecated
+ */
+ public function foo2()
+ {
+ new parent();
+ myClass3::foo1();
+ \A\B\myClass3::foo1();
+ parent::foo1();
+ return self::foo1();
+ }
+}
+--EXPECT--
+org.eclipse.php.internal.ui.editor.highlighters.DeprecatedHighlighting:
+highlight(myClass3)
+highlight(foo1)
+highlight(myClass4)
+highlight($a)
+highlight(foo1)
+highlight(foo2)
+highlight($a)
+highlight(myClass3)
+highlight(foo1)
+highlight(\A\B\myClass3)
+highlight(myClass3)
+highlight(foo1)
+highlight(foo1)
+highlight(foo1) \ No newline at end of file

Back to the top