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 157760

Summary: No way to add package annotations via TreeMaker
Product: java Reporter: Jan Lahoda <jlahoda>
Component: SourceAssignee: Jan Lahoda <jlahoda>
Status: RESOLVED FIXED    
Severity: blocker CC: jglick, jlahoda, tronicek
Priority: P3 Keywords: API, API_REVIEW_FAST
Version: 5.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:
Bug Depends on: 119887    
Bug Blocks: 179543    
Attachments: Patch for review.
Updated patch (added apichanges).
Demonstration that the API works

Description Jan Lahoda 2009-02-02 11:11:31 UTC
There is no way to add package annotations to the CompilationUnitTree (of package-info.java) via the o.n.a.j.s.TreeMaker.
Comment 1 Rastislav Komara 2009-02-03 10:54:30 UTC
Overtake.
Comment 2 Rastislav Komara 2009-02-16 09:48:52 UTC
.
Comment 3 Jan Lahoda 2009-08-20 09:59:10 UTC
Reassigning all moonko's java/source bugs to myself.
Comment 4 Jan Lahoda 2009-09-15 22:31:36 UTC
*** Issue 172324 has been marked as a duplicate of this issue. ***
Comment 5 Jesse Glick 2009-09-16 00:15:57 UTC
Not sure how common this request is. If there is no existing package-info.java it would be a reasonable workaround to
just create it with complete contents as raw text, but this would not help if you need to add annotations to an existing
file, or modify or remove existing annotations, as my code might need to do:
http://hg.netbeans.org/core-main/diff/6c08609a8a8b/apisupport.project/src/org/netbeans/modules/apisupport/project/CreatedModifiedFilesFactory.java

By the way, is there a recommended way to create a new source file using api.java.source? I can't find anything in
http://wiki.netbeans.org/Java_DevelopersGuide or Javadoc. Or are you just intended to use the Filesystems API to create
a file with minimal legal contents (e.g. "package $p; class $c {}") and then parse & modify it separately?
Comment 6 Jesse Glick 2010-02-01 16:17:33 UTC
Do you plan to fix this?
Comment 7 Jan Lahoda 2010-09-16 14:55:14 UTC
Created attachment 102048 [details]
Patch for review.
Comment 8 Jan Lahoda 2010-09-16 14:58:35 UTC
Attached patch for review. To create new file call WorkingCopy.rewrite(null, new-compilation-unit-tree), but also note bug #119887.
Comment 9 Jan Lahoda 2010-09-16 15:15:19 UTC
Created attachment 102049 [details]
Updated patch (added apichanges).
Comment 10 Jesse Glick 2010-09-17 16:23:27 UTC
Bug #119887 is indeed a minor irritation here.


Note that annotations in a newly created package-info.java are placed above the initial license comment, which is against normal style.
Comment 11 Jesse Glick 2010-09-17 16:29:15 UTC
Created attachment 102062 [details]
Demonstration that the API works

I will commit this once the review has concluded. Tested both with no initial package-info.java; and with preexisting package-info.java incl. license header, Javadoc comment, and @Deprecated annotation.

(Note that this annotation has no multiple form, i.e. only one Options panel may be registered per package. The wizard does not currently let you pick the package to register in, nor does it try to stop you from readding a panel to the same module/package. However it seems very unlikely that any module would add >1 top-level container panel to the Options dialog.)
Comment 13 Quality Engineering 2010-09-29 03:11:45 UTC
Integrated into 'main-golden', will be available in build *201009290000* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/28bf1d99d434
User: Jesse Glick <jglick@netbeans.org>
Log: #179543 revisited: use proper API from #157760 to create/modify package-info.java.