Bug 209798 - New API to create CompilationUnitTree from a template
New API to create CompilationUnitTree from a template
Status: RESOLVED FIXED
Product: java
Classification: Unclassified
Component: Source
7.2
All All
: P2 (vote)
: 7.2
Assigned To: Ralph Ruijs
issues@java
: API, API_REVIEW_FAST
Depends on:
Blocks: 208438
  Show dependency treegraph
 
Reported: 2012-03-20 15:42 UTC by Ralph Ruijs
Modified: 2012-04-08 09:54 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
:


Attachments
API change (14.97 KB, patch)
2012-03-20 15:45 UTC, Ralph Ruijs
Details | Diff
Updated patch (19.05 KB, patch)
2012-03-27 12:38 UTC, Ralph Ruijs
Details | Diff
Update patch, added javadoc (20.69 KB, patch)
2012-04-04 11:20 UTC, Ralph Ruijs
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ralph Ruijs 2012-03-20 15:42:18 UTC
When writing a new compilation unit through WorkingCopy it is not possible to change comments supplied by the template, as the comments are not imported.

To fix this, two changes are necessary:
 - a new API is needed to create a CompilationUnitTree from a template
 - the current implementation of WorkingCopy needs to import comments


See related bug 208438.
Comment 1 Ralph Ruijs 2012-03-20 15:45:23 UTC
Created attachment 116936 [details]
API change

Please review.
Comment 2 Jesse Glick 2012-03-20 18:40:54 UTC
[JG01] The test does not seem to check creation of a package-info.java, which is a special case that deserves explicit testing.


[JG02] Since java.source APIs now rely even more on the existence of standard templates with particular names under Classes/, perhaps these core templates should simply be moved into java.source? Currently they are registered on NewJavaFileWizardIterator in java.project, and java.source just seems to assume that they are there.

Would however mean a java.source > java.project dep, since JavaTemplates.createJavaTemplateIterator must be used for interactive purposes. (Might be possible to define the contents of the template in java.source and just the wizard attribute in java.project, though this would be a bit too clever for my taste.)

Could simplify testNewCompilationUnitFromTemplate a bit - no need to create emptyJava or classJava.


[JG03] apisupport.project.ui.wizard.common.CreatedModifiedFiles.PackageInfo.run currently uses the APIs from bug #119887 and bug #157760. Would this new API be more appropriate than #119887? There needs to be a clearly documented "right way" to create new source files.
Comment 3 Ralph Ruijs 2012-03-27 12:38:55 UTC
Created attachment 117323 [details]
Updated patch

I updated the patch with;

[JG01] added to the test.
[JG02] I do not think it is good to move this to java.source. The logic is currently clearly in one place, and moving it will not guarantee they will exist (the user can still delete them). The added method in GeneratorUtilities is aware the template could not be there, but I added a missing null-check to FileObjects.

[JG03] using workingcopy.rewrite(null, CompilationUnitTree) is still correct. This api gives more control if the new compilation unit needs to be created from the templates. I will add documentation to the JavaDevelopersFAQ.
Comment 4 Jesse Glick 2012-03-27 19:54:25 UTC
(In reply to comment #3)
> moving it will not guarantee they will exist (the user can still delete them)

Hmm, probably TemplatesPanel should disable deleteButton when !node.lookup.lookup(FileObject).canRevert()?

> I will add documentation to the JavaDevelopersFAQ.

Javadoc is more discoverable.
Comment 5 Ralph Ruijs 2012-04-04 11:20:23 UTC
Created attachment 117804 [details]
Update patch, added javadoc

[JG03] added/changed the javadoc.


If everything is ok, I will integrate tomorrow.
Comment 6 Ralph Ruijs 2012-04-05 12:17:30 UTC
Changeset: 3da87450f3c5
Author:    Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
Date:      2012-04-05 14:04
Message:   Issue #209798 - New API to create CompilationUnitTree from a template
Comment 7 Quality Engineering 2012-04-08 09:54:22 UTC
Integrated into 'main-golden', will be available in build *201204080400* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/3da87450f3c5
User: Ralph Benjamin Ruijs <ralphbenjamin@netbeans.org>
Log: Issue #209798 - New API to create CompilationUnitTree from a template


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo