Mercurial > projects > dwt-addons
annotate dwtx/jface/text/templates/TemplateContext.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, 2005 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.TemplateContext; | |
14 | |
131 | 15 import dwtx.jface.text.templates.SimpleTemplateVariableResolver; // packageimport |
16 import dwtx.jface.text.templates.TemplateBuffer; // packageimport | |
17 import dwtx.jface.text.templates.TemplateContextType; // packageimport | |
18 import dwtx.jface.text.templates.Template; // 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 | |
153
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
146
diff
changeset
|
37 import dwtx.dwtxhelper.Collection; |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
146
diff
changeset
|
38 |
129 | 39 |
40 import dwtx.jface.text.BadLocationException; | |
41 | |
42 /** | |
43 * Provides the context for a <code>Template</code> being resolved. Keeps track | |
44 * of resolved variables. | |
45 * <p> | |
46 * Clients may extend this class. | |
47 * </p> | |
48 * | |
49 * @since 3.0 | |
50 */ | |
51 public abstract class TemplateContext { | |
52 | |
53 /** The context type of this context */ | |
146 | 54 private const TemplateContextType fContextType; |
129 | 55 /** Additional variables. */ |
162 | 56 private const Map fVariables; |
129 | 57 /** A flag to indicate that the context should not be modified. */ |
58 private bool fReadOnly; | |
59 | |
60 /** | |
61 * Creates a template context of a particular context type. | |
62 * | |
63 * @param contextType the context type of this context | |
64 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
65 protected this(TemplateContextType contextType) { |
162 | 66 fVariables= new HashMap(); |
129 | 67 fContextType= contextType; |
68 fReadOnly= true; | |
69 } | |
70 | |
71 /** | |
72 * Returns the context type of this context. | |
73 * | |
74 * @return the context type of this context | |
75 */ | |
76 public TemplateContextType getContextType() { | |
77 return fContextType; | |
78 } | |
79 | |
80 /** | |
81 * Sets or clears the read-only flag. | |
82 * | |
83 * @param readOnly the new read-only state | |
84 */ | |
85 public void setReadOnly(bool readOnly) { | |
86 fReadOnly= readOnly; | |
87 } | |
88 | |
89 /** | |
90 * Returns <code>true</code> if the receiver is read-only, <code>false</code> otherwise. | |
91 * | |
92 * @return <code>true</code> if the receiver is read-only, <code>false</code> otherwise | |
93 */ | |
94 public bool isReadOnly() { | |
95 return fReadOnly; | |
96 } | |
97 | |
98 /** | |
99 * Defines the value of a variable. | |
100 * | |
101 * @param name the name of the variable | |
102 * @param value the value of the variable, <code>null</code> to un-define a variable | |
103 */ | |
104 public void setVariable(String name, String value) { | |
105 fVariables.put(name, value); | |
106 } | |
107 | |
108 /** | |
109 * Returns the value of a defined variable. | |
110 * | |
111 * @param name the name of the variable | |
112 * @return returns the value of the variable, <code>null</code> if the variable was not defined | |
113 */ | |
114 public String getVariable(String name) { | |
162 | 115 return stringcast( fVariables.get(name)); |
129 | 116 } |
117 | |
118 /** | |
119 * Evaluates the template in this context and returns a template buffer. | |
120 * <p> | |
121 * Evaluation means translating the template into a <code>TemplateBuffer</code>, | |
122 * resolving the defined variables in this context and possibly formatting | |
123 * the resolved buffer.</p> | |
124 * | |
125 * @param template the template to evaluate | |
126 * @return returns the buffer with the evaluated template or <code>null</code> if the buffer could not be created | |
127 * @throws BadLocationException if evaluation fails due to concurrently changed documents etc. | |
128 * @throws TemplateException if the template specification is not valid | |
129 */ | |
145 | 130 public abstract TemplateBuffer evaluate(Template template_); |
129 | 131 |
132 /** | |
133 * Tests if the specified template can be evaluated in this context. | |
134 * <p>Examples are templates defined for a different context (e.g. a javadoc | |
135 * template cannot be evaluated in Java context).</p> | |
136 * | |
137 * @param template the <code>Template</code> to check | |
138 * @return <code>true</code> if <code>template</code> can be evaluated | |
139 * in this context, <code>false</code> otherwise | |
140 */ | |
145 | 141 public abstract bool canEvaluate(Template template_); |
129 | 142 |
143 } |