Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrganor2009-07-01 03:28:38 -0400
committerrganor2009-07-01 03:28:38 -0400
commitc8d41d86efbf5d6eeb471b75ea6434af75214790 (patch)
treee7d75e291d5b4e4109aacc9b462c88f5ebb40f08
parent300e56c6214b1e4b36a8cab3efe6bc9b74eea736 (diff)
downloadorg.eclipse.pdt-c8d41d86efbf5d6eeb471b75ea6434af75214790.tar.gz
org.eclipse.pdt-c8d41d86efbf5d6eeb471b75ea6434af75214790.tar.xz
org.eclipse.pdt-c8d41d86efbf5d6eeb471b75ea6434af75214790.zip
isCompatible method: if one of the resolved types are not compatible with this type
<code>false</code> is returned
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/nodes/TypeBinding.java17
1 files changed, 11 insertions, 6 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/nodes/TypeBinding.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/nodes/TypeBinding.java
index b2e67f56b..4e21cd3fa 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/nodes/TypeBinding.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/ast/nodes/TypeBinding.java
@@ -546,25 +546,29 @@ public class TypeBinding implements ITypeBinding {
* @param type the type to check compatibility against
* @return <code>true</code> if this type is subtype compatible with the
* given type, and <code>false</code> otherwise
+ *
+ * NOTE: if one of the resolved types are not compatible with this type
+ * <code>false</code> is returned
*/
public boolean isSubTypeCompatible(ITypeBinding otherType) {
- if (otherType == null) {
+
+ if (otherType == null || elements == null || elements.length == 0) {
return false;
}
- boolean result = true;
+ int compatible = 0;
for (IModelElement element : elements) {
IType type = (IType) element;
try {
if (type.getSuperClasses() == null || type.getSuperClasses().length == 0) {
- continue;
+ return false;
}
ITypeHierarchy supertypeHierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
IModelElement[] otherElements = ((TypeBinding) otherType).elements;
if (otherElements != null) {
for (IModelElement modelElement : otherElements) {
- if (modelElement instanceof IType) {
- result &= supertypeHierarchy.contains((IType) modelElement);
+ if (modelElement instanceof IType && supertypeHierarchy.contains((IType) modelElement)) {
+ compatible++;
}
}
}
@@ -575,7 +579,8 @@ public class TypeBinding implements ITypeBinding {
}
}
- return result;
+ // all resolved types were compatible with this type
+ return compatible == elements.length;
}
/**

Back to the top