<!-- <questionid="arch-what"when="init"> Whatisthisprojectgoodfor? <hint> Pleaseprovidehereafewlinesdescribingtheproject, whatproblemitshouldsolve,providelinkstodocumentation, specifications,etc. </hint> </question>
-->
<answer id="arch-what">
Code Templates allow to paste various code snippets by using parametrized text.
The parameters of the same name will share the same default value and if that value
gets changed by user's typing the new value gets replicated into all the parameter's
occurrences.
<br/>
Code Templates replace the original abbreviations functionality.
<p>
Code template's example
</p>
<pre>
for (Iterator ${iterator} = ${collection instanceof="java.util.Collection"}.iterator(); ${iterator}.hasNext();) {
${cursor}${iterator}.next();"
}
</pre>
Each parameter can have additional hints of what values
can be assigned to it.
The hint has a form
<pre>
${param hint=value}
</pre>
or just
<pre>
${param hint}
</pre>
which translates to
<pre>
${param hint="true"}
</pre>
<p>
If necessary the value of the hint can be enclosed
in quotes to allow to write whitespace or <code>{</code> or <code>}</code>
into the value. The quote can be written by using <code>\"</code>.
</p>
<h4>Reserved parameter names</h4>
<p>
<code>${cursor}</code> defines position where the caret will be located
after the editing of the code template default values will finish.
</p>
<h4>Reserved hint names</h4>
<p>
<code>${param <b>editable</b>=false}</code> can be used to make the parameter to be skipped
from user's editing. This may be useful e.g. with using java-specific <code>type</code>
hint (described below).
</p>
<p>
Java:
<br/>
<code>${ind <b>index</b>}</code> defines that the default value of the parameter
should be an unused variable in the given context named <code>i</code>.
If <code>i</code> is already used then <code>j</code> is attempted
or then <code>k</code> etc. until <code>z</code>.
Then <code>i0</code>, <code>i1</code> etc. are attempted.
<br/>
<code>${param <b>type</b>="java.util.Collection"}</code> defines
java type that the parameter must be instance of.
Besides class names there can be array e.g. <code>String[]</code>
or generics <code>java.util.List<String></code>
<br/>
<code>${param <b>array</b>}</code> defines parameter of array type (including
arrays of primitive data types).
<br/>
<code>${param <b>type</b>="java.util.Iterator"}</code> defines
that the parameter has the given java type. The template processing infrastructure
will use short name <code>Iterator</code> and import <code>java.util.Iterator</code>.
</p>
<!-- <questionid="arch-quality"when="init"> Howwillthe<ahref="http://www.netbeans.org/community/guidelines/q-evangelism.html">quality</a> ofyourcodebetestedand howarefutureregressionsgoingtobeprevented? <hint> Whatkindoftestingdo youwanttouse?Howmuchfunctionality,inwhichareas, shouldbecoveredbythetests? </hint> </question>
-->
<answer id="arch-quality">
The unit tests are available in <a href="https://github.com/apache/netbeans/tree/master/ide/editor.codetemplates/test">ide/editor.codetemplates/test</a>.
<p/>
The following scenarios are tested:
<ul>
<li> Correctness of the template parameters parsing. </li>
<li> Correctness of the parameter's hints parsing. </li>
</ul>
</answer>
<!-- <questionid="arch-time"when="init"> Whatarethetimeestimatesofthework? <hint> Pleaseexpressyourestimatesofhowlongthedesign,implementation, stabilizationarelikelytolast.Howmanypeoplewillbeneededto implementthisandwhatistheexpectedmilestonebywhichtheworkshouldbe ready? </hint> </question>
-->
<answer id="arch-time">
The work is expected to be finished into NetBeans 4.2.
</answer>
<usecase id="code-template-parameters" name="Code Template Parameters">
One of the main benefits of the code templates is their parametrization
which allows to substitute the default values for the parameters
before the final insertion and it also allows the user to modify
these default values explicitly after the code template gets inserted
into the document.
<br/>
The parameters are marked in the code template's text by <code>${...}</code>.
<br/>
Parameters of the same name benefit from automatic replication. Once the template
gets pasted into the document all the parameter's occurrences
get replaced by parameter's default value.
<br/>
The first parameter's occurrence gets selected.
<br/>
The user can now replace the default value. If the user does so the new value
gets replicated to all the other occurrences of this parameter automatically.
</usecase>
<usecase id="mime-type-specific-operation" name="Mime-type specific operation">
Each code template needs to find the default values for its parameters
before it gets inserted into the text.
<br/>
Sometimes it's enough to just specify the default value in the template's text
but usually the default value gets determined from the context of insertion.
<br/>
There is an intent to create a mime-type specific code template processor
that would be registered per mime-type. There could be even more than one
such processors processing the template in a specific order.
</usecase>
<usecase id="parameter-hints" name="Parameter hints">
Besides parameter's name the template processors may need additional
hints of how to find a default value for the parameter.
<br/>
For example java code template's parameter may be an <code>index</code>
parameter which means that the infrastructure should fill in
a fresh index variable e.g. <code>i</code>.
<br/>
Or the parameter can only be of a certain java type such
as in the case of iterating through a collection
the type must be subtype of <code>java.util.Collection</code>.
<br/>
These requirements could be specified as additional hints
to the parameters e.g. <code>${i index}</code>
or <code>${c instanceof=java.util.Collection}</code>.
<br/>
The hints allow string literals to support arbitrary
explicit default values specifications
e.g. <code>${x default="Hello world"}</code>.
<br/>
The '{' and '}' have no special meaning inside the string literal.
<br/>
The '"' char is allowed to be used by escaping
<code>${x default="\"quoted string\""}</code>.
</usecase>
<usecase id="temporary-code-templates" name="Temporary Code Templates">
The Code Completion functionality allows to build temporary
Code Templates functionality if it could build a temporary template
for completing of the method parameters. The parameters could
be completed one by one by tabbing and the Code Templates framework
would fill in proper default values just like it does for regular templates.
<pre>
JTextComponent pane = ...
String tempCodeTemplateText = ...
CodeTemplate ct = CodeTemplateManager.get(pane.getDocument()).createTemporary(tempCodeTemplateText);
ct.insert(pane);
</pre>
</usecase>
<usecase id="insert-text" name="Insert Text Building and Updating">
The parametrized text of the code template first gets parsed
and the parameters get their default values which by default are
the names of the parameters.
The code template processor are then called to update this default
value.
<br/>
The new java infrastructure being developed would benefit
from the possibility to obtain the full string containing
the skeleton of the code template (without parameters)
with the present default values. It can take that string
and locally parse it to find out types of local variables
used in the particular template and fill in dependent
variable types.
</usecase>
<usecase id="parameter-editability" name="Parameter Editability">
Certain part of the code template may change text but it should
not be edited by the user. For example when iterating over collection
given as a parameter the collection may be generics-ed
by additional type. The iterator's variable type then also
needs to generics-ed with the same type.
<br/>
The iterator's type parameter should not be editable because
this operation may be done automatically
by the java code template processor.
<br/>
There should be a hint <code>editable</code> having
<code>true</code>/<code>false</code>.
</usecase>
<!-- <questionid="compat-version"when="impl"> Canyourmodulecoexistwithearlierandfuture versionsofitself?Canyoucorrectlyreadalloldsettings?Willfuture versionsbeabletoreadyourcurrentsettings?Canyouread orpolitelyignoresettingsstoredbyafutureversion? <hint> Veryhelpfulforreadingsettingsistostoreversionnumber there,sofutureversionscandecidewhetherhowtoread/convert thesettingsandolderversionscanignorethenewones. </hint> </question>
-->
<answer id="compat-version">
There will be default code templates provided by distribution
and the user can create its own. They will be stored in xml files.
</answer>
<!-- <questionid="dep-jre"when="final"> WhichversionofJREdoyouneed(1.2,1.3,1.4,etc.)? <hint> Itisexpectedthatifyourmodulerunson1.xthatitwillrun on1.x+1ifno,statethatplease.Alsodescribeherecaseswhere yourundifferentcodeondifferentversionsofJREandwhy. </hint> </question>
-->
<answer id="dep-jre">
JDK1.4 and higher can be used.
</answer>
<!-- <questionid="dep-nb"when="init"> WhatotherNetBeansprojectsandmodulesdoesthisonedependon? <hint> Ifyouwant,describesuchprojectsasimportedAPIsusing the<code><apiname="identification"type="importorexport"category="stable"url="whereisthedescription"/></code> </hint> </question>
-->
<answer id="dep-nb">
<defaultanswer generate="none"/>
<ul>
<li><api type='import' group='java' category='devel' name='EditorModuleAPI'url='@org-netbeans-modules-editor@/overview-summary.html' >
The module is needed for compilation.
The module is used during runtime.
Specification version 1.24
is required.
</api>
</li>
<li><api type='import' group='java' category='official' name='CodeCompletionAPI'url='../org-netbeans-modules-editor-completion/overview-summary.html' >
The module is needed for compilation.
The module is used during runtime.
</api>
</li>
<li><api type='import' group='java' category='devel' name='EditorHyperlinkSPI'url='@org-netbeans-modules-editor-lib@/overview-summary.html' >
The module is needed for compilation.
The module is used during runtime.
Specification version 1.3
is required.
</api>
</li>
<li><api type='import' group='java' category='official' name='MimeLookupAPI'url='../org-netbeans-modules-editor-mimelookup/overview-summary.html' >
The module is needed for compilation.
The module is used during runtime.
</api>
</li>
<li><api type='import' group='java' category='official' name='EditorSettingsAPI'url='@org-netbeans-modules-editor-settings@/overview-summary.html' >
The module is needed for compilation.
The module is used during runtime.
</api>
</li>
<li><api type='import' group='java' category='friend' name='EditorUtilitiesAPI'url='@org-netbeans-modules-editor-util@/overview-summary.html' >
The module is needed for compilation.
The module is used during runtime.
Specification version 1.5
is required.
</api>
</li>
<li><api type='import' group='java' category='private' name='org.netbeans.spi.editor.hints'>
The module is needed for compilation.
The module is used during runtime.
</api>
</li>
<li><api type='import' group='java' category='official' name='FilesystemsAPI'url='../org-openide-filesystems/overview-summary.html' >
The module is needed for compilation.
The module is used during runtime.
Specification version 7.0
is required.
</api>
</li>
<li><api type='import' group='java' category='official' name='ModulesAPI'url='../org-openide-modules/overview-summary.html' >
The module is needed for compilation.
The module is used during runtime.
Specification version 6.2
is required.
</api>
</li>
<li><api type='import' group='java' category='official' name='EditorAPI'url='../org-openide-text/overview-summary.html' >
The module is needed for compilation.
The module is used during runtime.
Specification version 6.16
is required.
</api>
</li>
<li><api type='import' group='java' category='official' name='UtilitiesAPI'url='../org-openide-util/overview-summary.html' >
The module is needed for compilation.
The module is used during runtime.
Specification version 6.2
is required.
</api>
</li>
<li><api type='import' group='java' category='official' name='WindowSystemAPI'url='../org-openide-windows/overview-summary.html' >
The module is needed for compilation.
The module is used during runtime.
Specification version 6.7
is required.
</api>
</li>
</ul>
</answer>
<!-- <questionid="dep-non-nb"when="init"> WhatotherprojectsoutsideNetBeansdoesthisonedependon? <hint> Somenon-NetBeansprojectsarepackagedasNetBeansmodules (see<ahref="http://libs.netbeans.org/">libraries</a>)and itispreferredtousethisapproachwhenmoremodulesmay dependonsuchthird-partylibrary. </hint> </question>
-->
<answer id="dep-non-nb">
No other projects.
</answer>
<!-- <questionid="deploy-packages"when="init"> Arepackagesofyourmodulemadeinaccessiblebynotdeclaringthem public? <hint> NetBeansmodulesystemallowsrestrictionofaccessrightsto publicclassesofyourmodulefromothermodules.Thisprevents unwanteddependenciesofothersonyourcodeandshouldbeused wheneverpossible(<ahref="http://www.netbeans.org/download/javadoc/OpenAPIs/org/openide/doc-files/upgrade.html#3.4-public-packages"> publicpackages </a>).Ifyoudonotrestrictaccesstoyourclassesyouare makingittooeasyforotherpeopletomisuseyourimplementation details,thatiswhyyoushouldhavegoodreasonfornot restrictingpackageaccess. </hint> </question>
-->
<answer id="deploy-packages">
Yes, only the API and SPI are public. The implementation is not public.
</answer>
<!-- <questionid="format-types"when="impl"> Whichprotocolsandfileformats(ifany)doesyourmodulereadorwriteondisk, ortransmitorreceiveoverthenetwork? </question>
-->
<answer id="format-types">
No files read or written to the disk.
</answer>
<!-- <questionid="lookup-lookup"when="init"> Doesyourmoduleuse<code>org.openide.util.Lookup</code> oranysimilartechnologytofindanycomponentstocommunicatewith?Whichones? <hint> Pleasedescribetheinterfacesyouaresearchingfor,where aredefined,whetheryouaresearchingforjustoneormoreofthem, iftheorderisimportant,etc.Alsoclassifythestabilityofsuch APIcontract. </hint> </question>
-->
<answer id="lookup-lookup">
Yes, it searches for Code Template Processors for particular mime-type by using
<api group="lookup" name="org.netbeans.api.editor.mimelookup.MimeLookup"type="import" category="official">
</api>
</answer>
<!-- <questionid="perf-mem"when="final"> Howmuchmemorydoesyourcomponentconsume?Estimate witharelationtothenumberofwindows,etc. </question>
-->
<answer id="perf-mem">
Proportional to number of Code Templates which range
from zero up to several tens for a typical mime-type.
</answer>
<!-- <questionid="perf-progress"when="final"> Doesyourmoduleexecuteanylong-runningtasks? <hint>Longrunningtasksshouldneverblock AWTthreadasitbadlyhurtstheUI <ahref="http://performance.netbeans.org/responsiveness/issues.html"> responsiveness</a>. Taskslikeconnectingover network,computinghugeamountofdata,compilation bedoneasynchronously(forexample using<code>RequestProcessor</code>),definitivelyitshould notblockAWTthread. </hint> </question>
-->
<answer id="perf-progress">
The code template processor may need to consult the context which can take
considerable amount of time.
<br/>
For example the java processor may need to consult MDR.
<br/>
Still, once the user has requested pasting of the code template
the the user will wait for the template to be pasted and will do
no other typing.
<br/>
Therefore there is no plan to reschedule the processor work
into other threads than AWT.
</answer>
<!-- <questionid="perf-scale"when="init"> Whichexternalcriteriainfluencetheperformanceofyour program(sizeoffileineditor,numberoffilesinmenu, insourcedirectory,etc.)andhowwellyourcodescales? <hint> Pleaseincludesomeestimates,thereareothermoredetailed questionstoanswerinlaterphasesofimplementation. </hint> </question>
-->
<answer id="perf-scale">
Size and number of parameters of the code template.
<br/>
Size of the editor's document slightly.
</answer>
<!-- <questionid="perf-spi"when="init"> Howtheperformanceofthepluggedincodewillbeenforced? <hint> Ifyouallowforeigncodetobepluggedintoyourownmodule,how doyouenforcethatitwillbehavecorrectlyandquicklyandwillnot negativelyinfluencetheperformanceofyourownmodule? </hint> </question>
-->
<answer id="perf-spi">
The only plugged code should be code template processors that should
just check the parameter's hints and possibly update the default value
of the parameter.
</answer>
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.