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 138082 - Add new FreeMarker attributes to support java source-level sensitive templates
Summary: Add new FreeMarker attributes to support java source-level sensitive templates
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: pslechta
URL:
Keywords: API, API_REVIEW_FAST
Depends on:
Blocks:
 
Reported: 2008-06-24 13:16 UTC by pslechta
Modified: 2008-07-02 16:25 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Diff -- proposed changes (5.17 KB, text/plain)
2008-06-24 13:18 UTC, pslechta
Details
Diff -- code changes based on advices from JG (4.85 KB, text/plain)
2008-07-01 15:55 UTC, pslechta
Details

Note You need to log in before you can comment on or make changes to this bug.
Description pslechta 2008-06-24 13:16:22 UTC
There are several requests for java source-level sensitive templates (users complain that generated code contains
unchecked warnings, does not contain annotations, ...). Issue 77936 illustrates the problem. Today, many of templates
generate code that is targeted for Java 1.4 only. There is no way to specify that some code lines in template should be
generated only for Java 1.5.

The solution to this problem is very simple. java.project attribute provider may be extended to provide also
source-level information that can be later used in templates to improve generated code. Attached diff shows the change
and also contains change of Servlet template to illustrate usage of this enhancement. The solution was tested and it works.

This change is not real API change, it is more new contract for template writers (new attributes can be used in
templates for conditional code generation).

The change should not affect any existing code or API.

Reviewers, please review the propesed change.
Comment 1 pslechta 2008-06-24 13:18:10 UTC
Created attachment 63331 [details]
Diff -- proposed changes
Comment 2 pslechta 2008-06-24 13:30:49 UTC
Also one note on new attribute names javaSourceLevel and java15style:

(1) The intention was to make usage of these attributes in templates as simple as possible. This is the reason why
attributes are not more "structured" (like "project.javac.source" instead of "javaSourceLevel"). Proper usage of simple
attributes is less complicated than usage of "structured" ones:

<#if javaSourceLavel?? && javaSourceLavel != "1.5">

is simpler than

<#if project?? && project.javac?? && project.javac.source?? && project.javac.source!= "1.5">

(2) Attribute "java15style" is defined only if Java source-level is 1.5 or later. So it can be used very easily to add
for example annotations into the code:

<#if java15style??>
    @Override
</#if>

(3) New attributes cannot be under "project" collection because this collection is provided by another attribute
provider so it would be overridden.
Comment 3 Jesse Glick 2008-06-24 20:27:11 UTC
[JG01] JavaTemplateAttributesProvider should likely be in java.project; wherever it is, the attributes it provides
should be documented in the module's Javadoc (e.g. overview.html).


[JG02] org.openide.modules.SpecificationVersion may be useful for implementing isJava15orLater.
Comment 4 pslechta 2008-07-01 15:53:19 UTC
Re [JG01]: new attributes are now documented in arch.xml
Re [JG02]: SpecificationVersion class is used now (instead of regexp)

Please see new attachment.
Comment 5 pslechta 2008-07-01 15:55:08 UTC
Created attachment 63763 [details]
Diff -- code changes based on advices from JG
Comment 6 pslechta 2008-07-01 15:58:38 UTC
This is last call before this change will be incorporated into trunk!
If anyone has any objections, please state them now!
Comment 7 pslechta 2008-07-02 16:25:31 UTC
http://hg.netbeans.org/main/rev/f072248a57ef