Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfullbright2011-08-16 16:36:52 -0400
committerpfullbright2011-08-16 16:36:52 -0400
commit3075889b4020ee6771c09850f6ff9ac3251b5936 (patch)
tree9d2b4d618557620089451d31c50c8fdbe6e8c0ae
parent7d081ecb74e70bb3dc842351ab3756841d26ef6e (diff)
downloadwebtools.dali-3075889b4020ee6771c09850f6ff9ac3251b5936.tar.gz
webtools.dali-3075889b4020ee6771c09850f6ff9ac3251b5936.tar.xz
webtools.dali-3075889b4020ee6771c09850f6ff9ac3251b5936.zip
added check for type being subtype of itself, and test
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JDTTools.java12
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/JDTToolsTests.java4
2 files changed, 13 insertions, 3 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JDTTools.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JDTTools.java
index fe1f94bbb0..e42b16a310 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JDTTools.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JDTTools.java
@@ -75,7 +75,8 @@ public final class JDTTools {
public static boolean typeIsSubType(IJavaProject javaProject, String potentialSubType, String potentialSuperType) {
try {
return typeIsSubType(javaProject, javaProject.findType(potentialSubType), javaProject.findType(potentialSuperType));
- } catch (JavaModelException ex) {
+ }
+ catch (JavaModelException ex) {
JptCommonCorePlugin.log(ex);
return false;
}
@@ -90,8 +91,13 @@ public final class JDTTools {
return false;
}
- // short cut if potential supertype is "java.lang.Object"
- if (Object.class.getName().equals(potentialSuperType)) {
+ // short cut if types are the same
+ if (potentialSubType.equals(potentialSuperType)) {
+ return true;
+ }
+
+ // short cut if potential supertype is java.lang.Object
+ if (javaProject.findType(Object.class.getName()).equals(potentialSuperType)) {
return true;
}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/JDTToolsTests.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/JDTToolsTests.java
index 4f63291a31..0fddcce6f7 100644
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/JDTToolsTests.java
+++ b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/JDTToolsTests.java
@@ -34,6 +34,10 @@ public class JDTToolsTests
public void testTypeIsSubtype() throws Exception {
IJavaProject jProj = getJavaProject().getJavaProject();
+ // same type
+ assertTrue(JDTTools.typeIsSubType(jProj, ArrayList.class.getName(), ArrayList.class.getName()));
+ assertTrue(JDTTools.typeIsSubType(jProj, List.class.getName(), List.class.getName()));
+
// concrete type is subtype of interface
assertTrue(JDTTools.typeIsSubType(jProj, ArrayList.class.getName(), List.class.getName()));
assertTrue(JDTTools.typeIsSubType(jProj, TreeSet.class.getName(), Iterable.class.getName()));

Back to the top