This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
It is a very common need to retrieve the "main" class contained inside a SourceElement. This would be the class named according to the source file. But it is I think more work than it ought to be: - getClasses()[0] usually works, but some strange person could put a package-private class before the main class - getClasses() and search for the public one works, if there is some public one (it is an error for there to be more than one); but I guess not if they are all package-private - getClasses() and search for the one with the same name as the source file might be best; but SourceElement does not have the source name, I think, you have to getCookie(DataObject.class)... In short, all of these approaches might get you what you want but they are a lot of code and probably not 100% reliable. It would be nice if there were a simple method in SourceElement, getMainClass (?) which could return null, whose implementation would try to find what the Java compiler would consider the primary outer class in the file (possibly null in case of an erroneous source).
Version: 'Dev' -> 3.2
Changing to P-4, Enhancement. Such utility would be useful, but I dont' think it falls in OpenAPIs, better to some utility package.
Target milestone -> 3.3
Reassinging to netbeans.org mailing address.
Target milestone -> 3.3.1.
Cleaning up before 4.0 planning
Target milestone was changed from not determined to TBD
Source hierarchy is obsolete. But we should consider this for the new JMI API.
Probably still applicable to Retouche though I have not checked details.
there are some helper methods in SourceUtils