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.
Designing 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 Understanding Decorators in Eclipse.
There are two cases that must be distinguished:
- The normal case where your project is „just“ a Java project, meaning some web-app, a stand alone solution, … In such a case the visibility is just as specified by the Java Language Specification.
- The special case where your project is a OSGi bundle. For easier understanding let’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.
The following icons are used to visually annotate the java files:
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)
Private visibility: It is not possible to declare a top level class private, but for completeness sake…
Protected visibility: The class is visible to classes in the same package or subclasses of itself.
Public visibility: This class is visible to the whole world.
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.
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.
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.
Protected visibility in OSGi Bundle in an non exported package:The whole package is not exported and therefore all it’s classes are not accessible from another bundle.
Protected visibility in OSGi Bundle with export restriction: The class is in an exported package but marked for restricted use.
Public visibility in OSGi Bundle in an non exported package:The whole package is not exported and therefore all it’s classes are not accessible from another bundle.
Public visibility in OSGi Bundle with export restriction: The class is in an exported package but marked for restricted use.
If 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).
A normal Java project might look like this:
A plug-in project may look like this:
The plugin is hosted at
The update site is located at: http://sahits.ch/project/eclipse/update