mirror of
https://github.com/EiffelSoftware/eiffel-org.git
synced 2025-12-08 07:42:33 +01:00
git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@1621 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
81 lines
2.8 KiB
Plaintext
81 lines
2.8 KiB
Plaintext
[[Property:uuid|7CCF602E-0B79-49C2-93FE-39C90CBE4E35]]
|
||
[[Property:link_title|Code Templates]]
|
||
[[Property:title|Code Templates]]
|
||
[[Property:weight|7]]
|
||
|
||
EiffelStudio editor includes a new feature designed to help write Eiffel code. Code template completion is it.
|
||
|
||
Code templates in Eiffel are described in Eiffel itself, there are some constraints to define templates that we will cover below. At the moment Code templates can only be used as part of an existing feature. Some templates will be available as global/target-less templates, it means there is not target context, so you can include a useful template inside your current feature. In other cases we will have templates that will be only available to certain context, for example if you have an <code>ARRAY [INTEGER]</code>, then you will be able to see templates applicable to it, if any.
|
||
|
||
|
||
<span id="templates_location"></span>
|
||
==Templates location==
|
||
|
||
EiffelStudio will scan the Eiffel Templates at the EiffelStudio installation and EiffelStudio user directory.
|
||
User defined templates will have precedence over templates located at the EiffelStudio installation.
|
||
|
||
|
||
<span id="templates_definition"></span>
|
||
==Templates Definition==
|
||
|
||
* Every template should inherit from a TEMPLATE class
|
||
class ARRAY_TEMPLATE [T -> COMPARABLE] inherIt TEMPLATE [ARRAY [T]]
|
||
* Multiple Generic Constraints is not supported
|
||
class EXAMPLE_TEMPLATE [T -> {TYPE_1, TYPE_2}]
|
||
* A file could have multiple code templates definitions
|
||
** Queries
|
||
** Commands
|
||
Code templates could be Global or applicable to a given Context
|
||
Queries and Commands accept multiple arguments like (a:T1; b:T2; c:T3), if any, will be used as input arguments where the default values will be filled with defaults if they exist.
|
||
Target Templates
|
||
Inherit from TEMPLATE [T]
|
||
Targetless Templates.
|
||
Metadata: it’s possible to add metadata to code templates using note clause
|
||
title: title of template
|
||
tags: List of tags to classify the template.
|
||
default: use to define default values for input arguments.
|
||
(*) Optional, by default we use the name of the feature in the template.
|
||
|
||
|
||
|
||
<span id="templates_skeleton"></span>
|
||
==Templates Skeleton==
|
||
|
||
===With Generic Constraints===
|
||
|
||
<code>
|
||
note
|
||
description: "[
|
||
Code templates for Arrays of COMPARABLES.
|
||
]"
|
||
template_version: "1.0"
|
||
|
||
|
||
class ARRAY_TEMPLATE [T -> COMPARABLE]
|
||
|
||
inherit
|
||
|
||
TEMPLATE [ARRAY [T]]
|
||
|
||
feature -- Templates
|
||
|
||
slice_maximum (low, high: INTEGER): T
|
||
-- Get the maximum of an array,
|
||
-- where the interval is defined by default by array.lower |..| array.upper.
|
||
note
|
||
tags: "Algorithm, Maximum, ARRAY"
|
||
default: "target.lower, target.upper"
|
||
do
|
||
across low |..| high as i loop
|
||
Result := Result.max (target [i.item])
|
||
end
|
||
end
|
||
end
|
||
</code>
|
||
|
||
|
||
|
||
|
||
|
||
|