{"id":666,"date":"2010-01-05T09:32:01","date_gmt":"2010-01-05T08:32:01","guid":{"rendered":"http:\/\/sahits.ch\/blog\/?p=666"},"modified":"2010-01-05T11:29:04","modified_gmt":"2010-01-05T10:29:04","slug":"api-design-with-eclipse","status":"publish","type":"post","link":"http:\/\/sahits.ch\/blog\/blog\/2010\/01\/05\/api-design-with-eclipse\/","title":{"rendered":"API Design with Eclipse"},"content":{"rendered":"<p>The design of the API of a class based on the visibility of its members is in Eclipse fairly easy thanks to the Outline view. One level up (the package level) there are no such nice hints for the visibility. Therefore I created a small plug-in that decorates Java classes in the package explorer view with the visibility icons.<!--more--><br \/>\nDesigning a plug-in or framework or some other deployable Java executable, the question of which classes to hide always pop up. This decision is seldom easy, especially since you have to inspect each and every class on their own. Therefore I decided to implement an icon decorator for Java classes analogue to the methods of class. In doing so if followed the article <a href=\"http:\/\/www.eclipse.org\/articles\/Article-Decorators\/decorators.html\">Understanding Decorators in Eclipse<\/a>.<br \/>\nThere are two cases that must be distinguished:<\/p>\n<ol>\n<li>The normal case where your project is &#8222;just&#8220; a Java project, meaning some web-app, a stand alone solution, &#8230; In such a case the visibility is just as specified by the Java Language Specification.<\/li>\n<li>The special case where your project is a OSGi bundle. For easier understanding let&#8217;s assume that the bundle is a jar file. If this jar file is used like a library in a project of the first kind, the visibility restrictions of the Java Language Specification are to be applied. If the jar file is used as a bundle, it is loaded by the BundleClassloader that restricts the visibility of classes through definitions of the manifest file.<\/li>\n<\/ol>\n<p>The following icons are used to visually annotate the java files:<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2010\/01\/default_co.gif\" alt=\"\" title=\"default_co\" width=\"8\" height=\"8\" class=\"alignnone size-full wp-image-781\" \/> Default visiblity: The class is visible within the same package but not outside of it. Ideal to make functionallity of a class accessible to other classes in the same package but not in the exported API (e.g. methods to be tested by a JUnit test)<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2010\/01\/private_co.gif\" alt=\"\" title=\"private_co\" width=\"8\" height=\"8\" class=\"alignnone size-full wp-image-782\" \/>Private visibility: It is not possible to declare a top level class private, but for completeness sake&#8230;<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2010\/01\/protected_co.gif\" alt=\"\" title=\"protected_co\" width=\"8\" height=\"8\" class=\"alignnone size-full wp-image-783\" \/>Protected visibility: The class is visible to classes in the same package or subclasses of itself.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2010\/01\/public_co.gif\" alt=\"\" title=\"public_co\" width=\"8\" height=\"8\" class=\"alignnone size-full wp-image-784\" \/>Public visibility: This class is visible to the whole world.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2010\/01\/default_co_bundle.gif\" alt=\"\" title=\"default_co_bundle\" width=\"8\" height=\"8\" class=\"alignnone size-full wp-image-786\" \/>Default visibility in an OSGI bundle: Package private classes in OSGI bundles are not visible to the outside of the bundle even the same package in another bundle.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2010\/01\/default_co_noexp.gif\" alt=\"\" title=\"default_co_noexp\" width=\"8\" height=\"8\" class=\"alignnone size-full wp-image-787\" \/>Default visibility in OSGi Bundle in an non exported package: This icon is not used because package private classes are never visible outside of bundles.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2010\/01\/private_co_noexp.gif\" alt=\"\" title=\"private_co_noexp\" width=\"8\" height=\"8\" class=\"alignnone size-full wp-image-788\" \/>Private visibility in OSGi Bundle in an non exported package: The same restriction as for classes with private visibility as for non bundles apply here.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2010\/01\/protected_co_noexp.gif\" alt=\"\" title=\"protected_co_noexp\" width=\"8\" height=\"8\" class=\"alignnone size-full wp-image-789\" \/>Protected visibility in OSGi Bundle in an non exported package:The whole package is not exported and therefore all it&#8217;s classes are not accessible from another bundle.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2010\/01\/protected_co_int.gif\" alt=\"\" title=\"protected_co_int\" width=\"8\" height=\"8\" class=\"alignnone size-full wp-image-790\" \/>Protected visibility in OSGi Bundle with export restriction: The class is in an exported package but marked for restricted use.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2010\/01\/public_co_noexp.gif\" alt=\"\" title=\"public_co_noexp\" width=\"8\" height=\"8\" class=\"alignnone size-full wp-image-791\" \/>Public visibility in OSGi Bundle in an non exported package:The whole package is not exported and therefore all it&#8217;s classes are not accessible from another bundle.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sahits.ch\/blog\/wp-content\/uploads\/2010\/01\/public_co_int.gif\" alt=\"\" title=\"public_co_int\" width=\"8\" height=\"8\" class=\"alignnone size-full wp-image-792\" \/>Public visibility in OSGi Bundle with export restriction: The class is in an exported package but marked for restricted use.<br \/>\nIf none of the bundle specific patterns apply, one of the first four icons is used (e.g. public class in an exported package without restriction).<br \/>\nA normal Java project might look like this:<br \/>\n<img decoding=\"async\" src=\"https:\/\/sourceforge.net\/dbimage.php?id=245781\" alt=\"Normal Java Project annotated\" \/><br \/>\nA plug-in project may look like this:<br \/>\n<img decoding=\"async\" src=\"https:\/\/sourceforge.net\/dbimage.php?id=246155\" alt=\"Plugin-Project annotated\" \/><br \/>\nThe plugin is hosted at<br \/> <a href=\"http:\/\/sourceforge.net\/projects\/sahitseclipse\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sflogo.sourceforge.net\/sflogo.php?group_id=294097&amp;type=8\" width=\"80\" height=\"15\" alt=\"Get Sahits' Eclipse plug-ins at SourceForge.net. Fast, secure and Free Open Source software downloads\" \/><\/a><br \/>\nThe update site is located at: <a href=\"http:\/\/sahits.ch\/project\/eclipse\/update\">http:\/\/sahits.ch\/project\/eclipse\/update<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The design of the API of a class based on the visibility of its members is in Eclipse fairly easy thanks to the Outline view. One level up (the package level) there are no such nice hints for the visibility. Therefore I created a small plug-in that decorates Java classes in the package explorer view &hellip; <a href=\"http:\/\/sahits.ch\/blog\/blog\/2010\/01\/05\/api-design-with-eclipse\/\" class=\"more-link\"><span class=\"screen-reader-text\">\u201eAPI Design with Eclipse\u201c <\/span>weiterlesen<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,7,6],"tags":[304,12,300],"class_list":["post-666","post","type-post","status-publish","format-standard","hentry","category-eclipse","category-java","category-programmieren","tag-eclipse","tag-plugin","tag-programmieren"],"_links":{"self":[{"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/posts\/666","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/comments?post=666"}],"version-history":[{"count":12,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/posts\/666\/revisions"}],"predecessor-version":[{"id":798,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/posts\/666\/revisions\/798"}],"wp:attachment":[{"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/media?parent=666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/categories?post=666"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/sahits.ch\/blog\/wp-json\/wp\/v2\/tags?post=666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}