Mercurial > projects > dwt-addons
annotate dwtx/jface/text/templates/Template.d @ 200:eb3414669eb0 default tip
fix for dmd 1.041 and tango 0.99.8
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 28 Mar 2009 03:09:57 +0100 |
parents | 1a5b8f8129df |
children |
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 | |
162 | 50 private alias .toHash toHash; |
51 private alias .equals equals; | |
52 | |
129 | 53 /** The name of this template */ |
54 private /*final*/ String fName; | |
55 /** A description of this template */ | |
56 private /*final*/ String fDescription; | |
57 /** The name of the context type of this template */ | |
58 private /*final*/ String fContextTypeId; | |
59 /** The template pattern. */ | |
60 private /*final*/ String fPattern; | |
61 /** | |
162 | 62 * The auto insertable property. |
129 | 63 * @since 3.1 |
64 */ | |
146 | 65 private const bool fIsAutoInsertable; |
129 | 66 |
67 /** | |
68 * Creates an empty template. | |
69 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
70 public this() { |
129 | 71 this("", "", "", "", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
72 } | |
73 | |
74 /** | |
75 * Creates a copy of a template. | |
76 * | |
77 * @param template the template to copy | |
78 */ | |
145 | 79 public this(Template template_) { |
80 this(template_.getName(), template_.getDescription(), template_.getContextTypeId(), template_.getPattern(), template_.isAutoInsertable()); | |
129 | 81 } |
82 | |
83 /** | |
84 * Creates a template. | |
85 * | |
86 * @param name the name of the template | |
87 * @param description the description of the template | |
88 * @param contextTypeId the id of the context type in which the template can be applied | |
89 * @param pattern the template pattern | |
90 * @deprecated as of 3.1 replaced by {@link #Template(String, String, String, String, bool)} | |
91 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
92 public this(String name, String description, String contextTypeId, String pattern) { |
129 | 93 this(name, description, contextTypeId, pattern, true); // templates are auto insertable per default |
94 } | |
95 | |
96 /** | |
97 * Creates a template. | |
98 * | |
99 * @param name the name of the template | |
100 * @param description the description of the template | |
101 * @param contextTypeId the id of the context type in which the template can be applied | |
102 * @param pattern the template pattern | |
103 * @param isAutoInsertable the auto insertable property of the template | |
104 * @since 3.1 | |
105 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
106 public this(String name, String description, String contextTypeId, String pattern, bool isAutoInsertable) { |
129 | 107 Assert.isNotNull(description); |
108 fDescription= description; | |
109 fName= name; | |
110 Assert.isNotNull(contextTypeId); | |
111 fContextTypeId= contextTypeId; | |
112 fPattern= pattern; | |
113 fIsAutoInsertable= isAutoInsertable; | |
114 } | |
115 | |
116 /* | |
117 * @see Object#hashCode() | |
118 */ | |
160 | 119 public override hash_t toHash() { |
120 return fName.toHash() ^ fPattern.toHash() ^ fContextTypeId.toHash(); | |
129 | 121 } |
122 | |
123 /** | |
124 * Sets the description of the template. | |
125 * | |
126 * @param description the new description | |
127 * @deprecated Templates should never be modified | |
128 */ | |
129 public void setDescription(String description) { | |
130 Assert.isNotNull(description); | |
131 fDescription= description; | |
132 } | |
133 | |
134 /** | |
135 * Returns the description of the template. | |
136 * | |
137 * @return the description of the template | |
138 */ | |
139 public String getDescription() { | |
140 return fDescription; | |
141 } | |
142 | |
143 /** | |
144 * Sets the name of the context type in which the template can be applied. | |
145 * | |
146 * @param contextTypeId the new context type name | |
147 * @deprecated Templates should never be modified | |
148 */ | |
149 public void setContextTypeId(String contextTypeId) { | |
150 Assert.isNotNull(contextTypeId); | |
151 fContextTypeId= contextTypeId; | |
152 } | |
153 | |
154 /** | |
155 * Returns the id of the context type in which the template can be applied. | |
156 * | |
157 * @return the id of the context type in which the template can be applied | |
158 */ | |
159 public String getContextTypeId() { | |
160 return fContextTypeId; | |
161 } | |
162 | |
163 /** | |
164 * Sets the name of the template. | |
165 * | |
166 * @param name the name of the template | |
167 * @deprecated Templates should never be modified | |
168 */ | |
169 public void setName(String name) { | |
170 fName= name; | |
171 } | |
172 | |
173 /** | |
174 * Returns the name of the template. | |
175 * | |
176 * @return the name of the template | |
177 */ | |
178 public String getName() { | |
179 return fName; | |
180 } | |
181 | |
182 /** | |
183 * Sets the pattern of the template. | |
184 * | |
185 * @param pattern the new pattern of the template | |
186 * @deprecated Templates should never be modified | |
187 */ | |
188 public void setPattern(String pattern) { | |
189 fPattern= pattern; | |
190 } | |
191 | |
192 /** | |
193 * Returns the template pattern. | |
194 * | |
195 * @return the template pattern | |
196 */ | |
197 public String getPattern() { | |
198 return fPattern; | |
199 } | |
200 | |
201 /** | |
202 * Returns <code>true</code> if template is enabled and matches the context, | |
203 * <code>false</code> otherwise. | |
204 * | |
205 * @param prefix the prefix (e.g. inside a document) to match | |
206 * @param contextTypeId the context type id to match | |
207 * @return <code>true</code> if template is enabled and matches the context, | |
208 * <code>false</code> otherwise | |
209 */ | |
210 public bool matches(String prefix, String contextTypeId) { | |
211 return fContextTypeId.equals(contextTypeId); | |
212 } | |
213 | |
214 /* | |
215 * @see java.lang.Object#equals(java.lang.Object) | |
216 */ | |
217 public bool equals(Object o) { | |
138 | 218 if (!( cast(Template)o )) |
129 | 219 return false; |
220 | |
134 | 221 Template t= cast(Template) o; |
129 | 222 if (t is this) |
223 return true; | |
224 | |
225 return t.fName.equals(fName) | |
226 && t.fPattern.equals(fPattern) | |
227 && t.fContextTypeId.equals(fContextTypeId) | |
228 && t.fDescription.equals(fDescription) | |
229 && t.fIsAutoInsertable is fIsAutoInsertable; | |
230 } | |
231 | |
232 /** | |
233 * Returns the auto insertable property of the template. | |
162 | 234 * |
129 | 235 * @return the auto insertable property of the template |
236 * @since 3.1 | |
237 */ | |
238 public bool isAutoInsertable() { | |
239 return fIsAutoInsertable; | |
240 } | |
241 } |