I’d like to be able to annotate a public class/interface in Java as @NonPublic, which would mean This interface is only to be used within this project, it is not part of the public API that this project exports.
This is common for projects that are composed of several jar files. Not all public classes/interfaces are meant to really be public outside of your jar.
Do you know of any tool/framework/plugin that does this?
IMHO the package system in Java is one of the most broken things that exist.
I’m not familiar with any standard Java-level mechanism to do that, although it is probably easy to write a tool or compiler extension that will enforce it.
However, if you are using OSGi (Eclipse is written that way), one of its advantages is a system for specifying better package and module level restrictions.