Mercurial > projects > dwt-addons
annotate dwtx/jface/text/templates/Template.d @ 145:02cd5f1224d3
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 24 Aug 2008 22:31:00 +0200 |
parents | b6bad70d540a |
children | 75302ef3f92f |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.jface.text.templates.Template; | |
14 | |
131 | 15 import dwtx.jface.text.templates.SimpleTemplateVariableResolver; // packageimport |
16 import dwtx.jface.text.templates.TemplateBuffer; // packageimport | |
17 import dwtx.jface.text.templates.TemplateContext; // packageimport | |
18 import dwtx.jface.text.templates.TemplateContextType; // packageimport | |
19 import dwtx.jface.text.templates.TemplateVariable; // packageimport | |
20 import dwtx.jface.text.templates.PositionBasedCompletionProposal; // packageimport | |
21 import dwtx.jface.text.templates.TemplateException; // packageimport | |
22 import dwtx.jface.text.templates.TemplateTranslator; // packageimport | |
23 import dwtx.jface.text.templates.DocumentTemplateContext; // packageimport | |
24 import dwtx.jface.text.templates.GlobalTemplateVariables; // packageimport | |
25 import dwtx.jface.text.templates.InclusivePositionUpdater; // packageimport | |
26 import dwtx.jface.text.templates.TemplateProposal; // packageimport | |
27 import dwtx.jface.text.templates.ContextTypeRegistry; // packageimport | |
28 import dwtx.jface.text.templates.JFaceTextTemplateMessages; // packageimport | |
29 import dwtx.jface.text.templates.TemplateCompletionProcessor; // packageimport | |
30 import dwtx.jface.text.templates.TextTemplateMessages; // packageimport | |
31 import dwtx.jface.text.templates.TemplateVariableType; // packageimport | |
32 import dwtx.jface.text.templates.TemplateVariableResolver; // packageimport | |
33 | |
34 | |
129 | 35 import dwt.dwthelper.utils; |
36 | |
37 import dwtx.core.runtime.Assert; | |
38 | |
39 | |
40 /** | |
41 * A template consisting of a name and a pattern. | |
42 * <p> | |
43 * Clients may instantiate this class. May become final in the future. | |
44 * </p> | |
45 * @since 3.0 | |
46 * @noextend This class is not intended to be subclassed by clients. | |
47 */ | |
48 public class Template { | |
49 | |
50 /** The name of this template */ | |
51 private /*final*/ String fName; | |
52 /** A description of this template */ | |
53 private /*final*/ String fDescription; | |
54 /** The name of the context type of this template */ | |
55 private /*final*/ String fContextTypeId; | |
56 /** The template pattern. */ | |
57 private /*final*/ String fPattern; | |
58 /** | |
59 * The auto insertable property. | |
60 * @since 3.1 | |
61 */ | |
62 private final bool fIsAutoInsertable; | |
63 | |
64 /** | |
65 * Creates an empty template. | |
66 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
67 public this() { |
129 | 68 this("", "", "", "", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
69 } | |
70 | |
71 /** | |
72 * Creates a copy of a template. | |
73 * | |
74 * @param template the template to copy | |
75 */ | |
145 | 76 public this(Template template_) { |
77 this(template_.getName(), template_.getDescription(), template_.getContextTypeId(), template_.getPattern(), template_.isAutoInsertable()); | |
129 | 78 } |
79 | |
80 /** | |
81 * Creates a template. | |
82 * | |
83 * @param name the name of the template | |
84 * @param description the description of the template | |
85 * @param contextTypeId the id of the context type in which the template can be applied | |
86 * @param pattern the template pattern | |
87 * @deprecated as of 3.1 replaced by {@link #Template(String, String, String, String, bool)} | |
88 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
89 public this(String name, String description, String contextTypeId, String pattern) { |
129 | 90 this(name, description, contextTypeId, pattern, true); // templates are auto insertable per default |
91 } | |
92 | |
93 /** | |
94 * Creates a template. | |
95 * | |
96 * @param name the name of the template | |
97 * @param description the description of the template | |
98 * @param contextTypeId the id of the context type in which the template can be applied | |
99 * @param pattern the template pattern | |
100 * @param isAutoInsertable the auto insertable property of the template | |
101 * @since 3.1 | |
102 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
103 public this(String name, String description, String contextTypeId, String pattern, bool isAutoInsertable) { |
129 | 104 Assert.isNotNull(description); |
105 fDescription= description; | |
106 fName= name; | |
107 Assert.isNotNull(contextTypeId); | |
108 fContextTypeId= contextTypeId; | |
109 fPattern= pattern; | |
110 fIsAutoInsertable= isAutoInsertable; | |
111 } | |
112 | |
113 /* | |
114 * @see Object#hashCode() | |
115 */ | |
116 public int hashCode() { | |
117 return fName.hashCode() ^ fPattern.hashCode() ^ fContextTypeId.hashCode(); | |
118 } | |
119 | |
120 /** | |
121 * Sets the description of the template. | |
122 * | |
123 * @param description the new description | |
124 * @deprecated Templates should never be modified | |
125 */ | |
126 public void setDescription(String description) { | |
127 Assert.isNotNull(description); | |
128 fDescription= description; | |
129 } | |
130 | |
131 /** | |
132 * Returns the description of the template. | |
133 * | |
134 * @return the description of the template | |
135 */ | |
136 public String getDescription() { | |
137 return fDescription; | |
138 } | |
139 | |
140 /** | |
141 * Sets the name of the context type in which the template can be applied. | |
142 * | |
143 * @param contextTypeId the new context type name | |
144 * @deprecated Templates should never be modified | |
145 */ | |
146 public void setContextTypeId(String contextTypeId) { | |
147 Assert.isNotNull(contextTypeId); | |
148 fContextTypeId= contextTypeId; | |
149 } | |
150 | |
151 /** | |
152 * Returns the id of the context type in which the template can be applied. | |
153 * | |
154 * @return the id of the context type in which the template can be applied | |
155 */ | |
156 public String getContextTypeId() { | |
157 return fContextTypeId; | |
158 } | |
159 | |
160 /** | |
161 * Sets the name of the template. | |
162 * | |
163 * @param name the name of the template | |
164 * @deprecated Templates should never be modified | |
165 */ | |
166 public void setName(String name) { | |
167 fName= name; | |
168 } | |
169 | |
170 /** | |
171 * Returns the name of the template. | |
172 * | |
173 * @return the name of the template | |
174 */ | |
175 public String getName() { | |
176 return fName; | |
177 } | |
178 | |
179 /** | |
180 * Sets the pattern of the template. | |
181 * | |
182 * @param pattern the new pattern of the template | |
183 * @deprecated Templates should never be modified | |
184 */ | |
185 public void setPattern(String pattern) { | |
186 fPattern= pattern; | |
187 } | |
188 | |
189 /** | |
190 * Returns the template pattern. | |
191 * | |
192 * @return the template pattern | |
193 */ | |
194 public String getPattern() { | |
195 return fPattern; | |
196 } | |
197 | |
198 /** | |
199 * Returns <code>true</code> if template is enabled and matches the context, | |
200 * <code>false</code> otherwise. | |
201 * | |
202 * @param prefix the prefix (e.g. inside a document) to match | |
203 * @param contextTypeId the context type id to match | |
204 * @return <code>true</code> if template is enabled and matches the context, | |
205 * <code>false</code> otherwise | |
206 */ | |
207 public bool matches(String prefix, String contextTypeId) { | |
208 return fContextTypeId.equals(contextTypeId); | |
209 } | |
210 | |
211 /* | |
212 * @see java.lang.Object#equals(java.lang.Object) | |
213 */ | |
214 public bool equals(Object o) { | |
138 | 215 if (!( cast(Template)o )) |
129 | 216 return false; |
217 | |
134 | 218 Template t= cast(Template) o; |
129 | 219 if (t is this) |
220 return true; | |
221 | |
222 return t.fName.equals(fName) | |
223 && t.fPattern.equals(fPattern) | |
224 && t.fContextTypeId.equals(fContextTypeId) | |
225 && t.fDescription.equals(fDescription) | |
226 && t.fIsAutoInsertable is fIsAutoInsertable; | |
227 } | |
228 | |
229 /** | |
230 * Returns the auto insertable property of the template. | |
231 * | |
232 * @return the auto insertable property of the template | |
233 * @since 3.1 | |
234 */ | |
235 public bool isAutoInsertable() { | |
236 return fIsAutoInsertable; | |
237 } | |
238 } |