comparison org.eclipse.text/src/org/eclipse/jface/text/templates/Template.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children 5feec68b4556
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
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 org.eclipse.jface.text.templates.Template;
14
15 import org.eclipse.jface.text.templates.SimpleTemplateVariableResolver; // packageimport
16 import org.eclipse.jface.text.templates.TemplateBuffer; // packageimport
17 import org.eclipse.jface.text.templates.TemplateContext; // packageimport
18 import org.eclipse.jface.text.templates.TemplateContextType; // packageimport
19 import org.eclipse.jface.text.templates.TemplateVariable; // packageimport
20 import org.eclipse.jface.text.templates.PositionBasedCompletionProposal; // packageimport
21 import org.eclipse.jface.text.templates.TemplateException; // packageimport
22 import org.eclipse.jface.text.templates.TemplateTranslator; // packageimport
23 import org.eclipse.jface.text.templates.DocumentTemplateContext; // packageimport
24 import org.eclipse.jface.text.templates.GlobalTemplateVariables; // packageimport
25 import org.eclipse.jface.text.templates.InclusivePositionUpdater; // packageimport
26 import org.eclipse.jface.text.templates.TemplateProposal; // packageimport
27 import org.eclipse.jface.text.templates.ContextTypeRegistry; // packageimport
28 import org.eclipse.jface.text.templates.JFaceTextTemplateMessages; // packageimport
29 import org.eclipse.jface.text.templates.TemplateCompletionProcessor; // packageimport
30 import org.eclipse.jface.text.templates.TextTemplateMessages; // packageimport
31 import org.eclipse.jface.text.templates.TemplateVariableType; // packageimport
32 import org.eclipse.jface.text.templates.TemplateVariableResolver; // packageimport
33
34
35 import java.lang.all;
36 import java.util.Set;
37
38 import org.eclipse.core.runtime.Assert;
39
40
41 /**
42 * A template consisting of a name and a pattern.
43 * <p>
44 * Clients may instantiate this class. May become final in the future.
45 * </p>
46 * @since 3.0
47 * @noextend This class is not intended to be subclassed by clients.
48 */
49 public class Template {
50
51 private alias .toHash toHash;
52 private alias .equals equals;
53
54 /** The name of this template */
55 private /*final*/ String fName;
56 /** A description of this template */
57 private /*final*/ String fDescription;
58 /** The name of the context type of this template */
59 private /*final*/ String fContextTypeId;
60 /** The template pattern. */
61 private /*final*/ String fPattern;
62 /**
63 * The auto insertable property.
64 * @since 3.1
65 */
66 private const bool fIsAutoInsertable;
67
68 /**
69 * Creates an empty template.
70 */
71 public this() {
72 this("", "", "", "", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
73 }
74
75 /**
76 * Creates a copy of a template.
77 *
78 * @param template the template to copy
79 */
80 public this(Template template_) {
81 this(template_.getName(), template_.getDescription(), template_.getContextTypeId(), template_.getPattern(), template_.isAutoInsertable());
82 }
83
84 /**
85 * Creates a template.
86 *
87 * @param name the name of the template
88 * @param description the description of the template
89 * @param contextTypeId the id of the context type in which the template can be applied
90 * @param pattern the template pattern
91 * @deprecated as of 3.1 replaced by {@link #Template(String, String, String, String, bool)}
92 */
93 public this(String name, String description, String contextTypeId, String pattern) {
94 this(name, description, contextTypeId, pattern, true); // templates are auto insertable per default
95 }
96
97 /**
98 * Creates a template.
99 *
100 * @param name the name of the template
101 * @param description the description of the template
102 * @param contextTypeId the id of the context type in which the template can be applied
103 * @param pattern the template pattern
104 * @param isAutoInsertable the auto insertable property of the template
105 * @since 3.1
106 */
107 public this(String name, String description, String contextTypeId, String pattern, bool isAutoInsertable) {
108 Assert.isNotNull(description);
109 fDescription= description;
110 fName= name;
111 Assert.isNotNull(contextTypeId);
112 fContextTypeId= contextTypeId;
113 fPattern= pattern;
114 fIsAutoInsertable= isAutoInsertable;
115 }
116
117 /*
118 * @see Object#hashCode()
119 */
120 public override hash_t toHash() {
121 return fName.toHash() ^ fPattern.toHash() ^ fContextTypeId.toHash();
122 }
123
124 /**
125 * Sets the description of the template.
126 *
127 * @param description the new description
128 * @deprecated Templates should never be modified
129 */
130 public void setDescription(String description) {
131 Assert.isNotNull(description);
132 fDescription= description;
133 }
134
135 /**
136 * Returns the description of the template.
137 *
138 * @return the description of the template
139 */
140 public String getDescription() {
141 return fDescription;
142 }
143
144 /**
145 * Sets the name of the context type in which the template can be applied.
146 *
147 * @param contextTypeId the new context type name
148 * @deprecated Templates should never be modified
149 */
150 public void setContextTypeId(String contextTypeId) {
151 Assert.isNotNull(contextTypeId);
152 fContextTypeId= contextTypeId;
153 }
154
155 /**
156 * Returns the id of the context type in which the template can be applied.
157 *
158 * @return the id of the context type in which the template can be applied
159 */
160 public String getContextTypeId() {
161 return fContextTypeId;
162 }
163
164 /**
165 * Sets the name of the template.
166 *
167 * @param name the name of the template
168 * @deprecated Templates should never be modified
169 */
170 public void setName(String name) {
171 fName= name;
172 }
173
174 /**
175 * Returns the name of the template.
176 *
177 * @return the name of the template
178 */
179 public String getName() {
180 return fName;
181 }
182
183 /**
184 * Sets the pattern of the template.
185 *
186 * @param pattern the new pattern of the template
187 * @deprecated Templates should never be modified
188 */
189 public void setPattern(String pattern) {
190 fPattern= pattern;
191 }
192
193 /**
194 * Returns the template pattern.
195 *
196 * @return the template pattern
197 */
198 public String getPattern() {
199 return fPattern;
200 }
201
202 /**
203 * Returns <code>true</code> if template is enabled and matches the context,
204 * <code>false</code> otherwise.
205 *
206 * @param prefix the prefix (e.g. inside a document) to match
207 * @param contextTypeId the context type id to match
208 * @return <code>true</code> if template is enabled and matches the context,
209 * <code>false</code> otherwise
210 */
211 public bool matches(String prefix, String contextTypeId) {
212 return fContextTypeId.equals(contextTypeId);
213 }
214
215 /*
216 * @see java.lang.Object#equals(java.lang.Object)
217 */
218 public bool equals(Object o) {
219 if (!( cast(Template)o ))
220 return false;
221
222 Template t= cast(Template) o;
223 if (t is this)
224 return true;
225
226 return t.fName.equals(fName)
227 && t.fPattern.equals(fPattern)
228 && t.fContextTypeId.equals(fContextTypeId)
229 && t.fDescription.equals(fDescription)
230 && t.fIsAutoInsertable is fIsAutoInsertable;
231 }
232
233 /**
234 * Returns the auto insertable property of the template.
235 *
236 * @return the auto insertable property of the template
237 * @since 3.1
238 */
239 public bool isAutoInsertable() {
240 return fIsAutoInsertable;
241 }
242 }