{"id":75,"date":"2009-10-28T21:24:02","date_gmt":"2009-10-28T13:24:02","guid":{"rendered":"http:\/\/www.gemchen.cn\/?p=75"},"modified":"2009-10-28T21:24:02","modified_gmt":"2009-10-28T13:24:02","slug":"%e7%94%b1compilationunit%e5%be%97%e5%88%b0superclass%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/gemchen.cn\/?p=75","title":{"rendered":"\u7531CompilationUnit\u5f97\u5230SuperClass\u7684\u65b9\u6cd5"},"content":{"rendered":"<p>\u505aBTF\u9879\u76ee\u7684\u65f6\u5019, \u8981\u5224\u65ad\u4e00\u4e2a\u7c7b\u662f\u5426\u7ee7\u627f\u4e86\u67d0\u4e2a\u6307\u5b9a\u7c7b.<\/p>\n<p>\u7531\u4e8e\u7c7b\u8fd8\u662f\u5728Eclipse\u7684JDT\u4e2d, \u6ca1\u6709\u88abLoad, \u6240\u4ee5java.lang.Class.getSuperclass()\u4e0d\u4e2d\u4e86.<\/p>\n<p>\u67e5\u627e\u4e00\u756a\u539f\u6765\u53ef\u4ee5\u901a\u8fc7CompilationUnit\u83b7\u53d6org.eclipse.jdt.core.IType, <\/p>\n<p>\u7136\u540eIType.newSupertypeHierarchy(*)\u5f97\u5230ITypeHierarchy, \u7ee7\u800c\u5c31\u80fd\u7528ITypeHierarchy.getSuperclass(IType)\u5f97\u5230\u5176\u8d85\u7c7b\u4e86.<\/p>\n<blockquote>\n<p>IType[] types = ((ICompilationUnit)javaElement).getTypes();     <br \/>&#160;&#160;&#160; if(null != types &amp;&amp; types.length &gt; 0){      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ITypeHierarchy typeHierarchy = types[0].newSupertypeHierarchy(null);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; IType superclass = typeHierarchy.getSuperclass(types[0]);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if(superclass instanceof ResolvedBinaryType){      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8230;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br \/>}<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u505aBTF\u9879\u76ee\u7684\u65f6\u5019, \u8981\u5224\u65ad\u4e00\u4e2a\u7c7b\u662f\u5426\u7ee7\u627f\u4e86\u67d0\u4e2a\u6307\u5b9a\u7c7b. \u7531\u4e8e\u7c7b\u8fd8\u662f\u5728Eclipse\u7684JDT\u4e2d, \u6ca1\u6709\u88abLoad, \u6240\u4ee5java.lang.Class.getSuperclass()\u4e0d\u4e2d\u4e86. \u67e5\u627e\u4e00\u756a&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,1],"tags":[15,25],"class_list":["post-75","post","type-post","status-publish","format-standard","hentry","category-dev","category-uncategorized","tag-eclipse","tag-java"],"_links":{"self":[{"href":"https:\/\/gemchen.cn\/index.php?rest_route=\/wp\/v2\/posts\/75","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gemchen.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gemchen.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gemchen.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gemchen.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=75"}],"version-history":[{"count":0,"href":"https:\/\/gemchen.cn\/index.php?rest_route=\/wp\/v2\/posts\/75\/revisions"}],"wp:attachment":[{"href":"https:\/\/gemchen.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gemchen.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gemchen.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}