Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jdt-dev] Figuring out a Type is forbidden or not

it depends on which rule defines "forbidden"

In the olden days, we only had our own access rules defined as patterns attached to classpath entries. The key abstraction here is org.eclipse.jdt.core.IAccessRule. I'm not aware of any API that actually interprets these rules for a given type.

In a modular world (JRE 9+), classes are "forbidden", when their package is not exported from the enclosing module, or exported with restrictions. This information can be accessed similar to this snippet:

IType type ...
IPackageFragmentRoot pfr = type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT)
IModuleDescription mod = pfr.getModuleDescription();
String[] exported = mod.getExportedPackageNames(null); // exported to all
String given = type.getPackageFragment().getElementName();
// does exported contain given?

HTH,
Stephan


On 03.03.20 19:52, Gayan Perera wrote:
Hi All,

On a plugin i'm working on i want to check if the given type is forbidden or not, like a class from com.sun package. Is there a JDT API for this ?

Br
Gayan.

_______________________________________________
jdt-dev mailing list
jdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/jdt-dev




Back to the top