Community
Participate
Working Groups
The result of ITypeHierarchy.getAllSuperTypes() does not include an IType for java.lang.Object. This is completely counterintuitive, because Object is a supertype of any other type. -Frank
It does for me. Do you have more details on how to recreate this problem?
Jerome, The problem appears in the context of the "Change Type" refactoring that I'm implementing. If you like, I can send you a ZIP file containing the entire plugin, so you can experiment with it. The offending piece of code looks as follows. If I comment out the second if statement, the behavior of the program changes (which it shouldn't, right?) -Frank /** * Returns true if and only if type1 is a direct or indirect subtype of type2. */ public boolean isSubTypeOf(IType type1, IType type2, IProgressMonitor pm) { if (type1.equals(type2)) return true; if (type2.getFullyQualifiedName().equals("java.lang.Object")) // workaround for bug #46052 return true; IType[] superTypes= fTypeHierarchy.getAllSupertypes(type1); for (int i= 0; i < superTypes.length; i++) { if (superTypes[i].equals(type2)) return true; } return false; } -Frank
Please attach the ZIP to this bug report, or if it is too big, please send it to me. BTW which Eclipse build are you using?
the problem is only visible for interfaces, see bug 23656
Created attachment 6709 [details] plugin with ChangeType refactoring Jerome, I'm attaching a plugin with the new "Change Type" refactoring. To reproduce the bug, you can run the unit tests in class ChangeTypeRefactoringTests in com.ibm.waton.refactoring.tests. These tests should all succeed. However, if you comment out the line in class ChangeTypeRefactoring with the comment, "workaround for bug #46052" a few of the tests will break. This plugin works with M4. You will need to download the appropriate versions of the tests for the jdt.ui and jdt.ui.refactoring plugins from dev.eclipse.org. Hope this helps, -Frank
Thanks for the test case Frank. But this works as designed. For an interface, only interfaces that the interface extends are returned. See the spec in ITypeHierarchy.getSupertypes(IType). Note as said in bug 23656, we had this discussion on the jdt-core-dev mailing list before. Unless you have a strong use case, we cannot change the spec and we will have to live with this inconsitency. Ok to close?
Jerome, When I look at the JavaDoc in class ITypeHierarchy, this "designed" behavior is not at all obvious to me, especially given that the name of the method is "get*All*SuperTypes". Therefore, I suggest adding the following sentence to the JavaDoc for method ITypeHierarchy.getAllSuperTypes(IType type): "Please note that java.lang.Object is NOT considered to be a supertype of any interface type." regards, -Frank
Thanks Frank. I have updated the Java doc to include your comments.
Verified.