From 3075889b4020ee6771c09850f6ff9ac3251b5936 Mon Sep 17 00:00:00 2001 From: pfullbright Date: Tue, 16 Aug 2011 20:36:52 +0000 Subject: added check for type being subtype of itself, and test --- .../eclipse/jpt/common/core/internal/utility/JDTTools.java | 12 +++++++++--- .../core/tests/internal/utility/jdt/JDTToolsTests.java | 4 ++++ 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())); -- cgit v1.2.3