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.
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.
Created attachment 63331 [details] Diff -- proposed changes
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.
[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.
Re [JG01]: new attributes are now documented in arch.xml Re [JG02]: SpecificationVersion class is used now (instead of regexp) Please see new attachment.
Created attachment 63763 [details] Diff -- code changes based on advices from JG
This is last call before this change will be incorporated into trunk! If anyone has any objections, please state them now!
http://hg.netbeans.org/main/rev/f072248a57ef