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.

Bug 8725 - Javac helper API could have a method to get the top-level class
Summary: Javac helper API could have a method to get the top-level class
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 3.x
Hardware: PC Linux
: P4 minor (vote)
Assignee: issues@java
URL:
Keywords:
Depends on:
Blocks: 51708
  Show dependency tree
 
Reported: 2000-12-01 18:24 UTC by Jesse Glick
Modified: 2007-09-19 17:10 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2000-12-01 18:24:22 UTC
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).
Comment 1 Jan Chalupa 2001-03-12 12:09:05 UTC
Version: 'Dev' -> 3.2
Comment 2 Svata Dedic 2001-03-13 15:11:35 UTC
Changing to P-4, Enhancement. Such utility would be useful, but I dont' think 
it falls in OpenAPIs, better to some utility package.
Comment 3 Jan Chalupa 2001-05-05 23:20:34 UTC
Target milestone -> 3.3
Comment 4 Svata Dedic 2001-07-09 15:51:06 UTC
Reassinging to netbeans.org mailing address.
Comment 5 Jan Chalupa 2001-11-27 12:49:59 UTC
Target milestone -> 3.3.1.
Comment 6 Svata Dedic 2002-05-21 17:47:37 UTC
Cleaning up before 4.0 planning
Comment 7 Marek Grummich 2002-07-19 17:14:46 UTC
Target milestone was changed from not determined to TBD
Comment 8 Martin Matula 2004-11-13 23:45:07 UTC
Source hierarchy is obsolete. But we should consider this for the new
JMI API.
Comment 9 Jesse Glick 2006-12-04 20:02:03 UTC
Probably still applicable to Retouche though I have not checked details.
Comment 10 Jan Becicka 2007-09-19 17:10:08 UTC
there are some helper methods in SourceUtils