use of org.eclipse.jface.text.templates.TemplateBuffer in project eclipse.platform.text by eclipse.
the class TemplateTranslatorTest method testNoVarTemplate.
public void testNoVarTemplate() throws Exception {
TemplateBuffer buffer = fTranslator.translate("foo bar");
assertNull(fTranslator.getErrorMessage());
TemplateVariable[] vars = buffer.getVariables();
assertEquals(0, vars.length);
assertEquals("foo bar", buffer.getString());
}
use of org.eclipse.jface.text.templates.TemplateBuffer in project eclipse.platform.text by eclipse.
the class TemplateVariablesWordSelectionTest method testWithParameter.
@Test
public void testWithParameter() throws Exception {
TemplateBuffer buffer = fTranslator.translate("No selection results in the ${w:word_selection('default')} text.");
fType.resolve(buffer, fContext);
StringBuffer expected = new StringBuffer();
expected.append("No selection results in the default text.");
assertBufferStringAndVariables(expected.toString(), buffer);
}
use of org.eclipse.jface.text.templates.TemplateBuffer in project webtools.sourceediting by eclipse.
the class NewXSLFileTemplatesWizardPage method getTemplateString.
String getTemplateString(int[] offset) {
String templateString = null;
offset[0] = 0;
Template template = getSelectedTemplate();
if (template != null) {
TemplateContextType contextType = XSLUIPlugin.getDefault().getTemplateContextRegistry().getContextType(XSLUIConstants.TEMPLATE_CONTEXT_XSL_NEW);
IDocument document = new Document();
TemplateContext context = new DocumentTemplateContext(contextType, document, 0, 0);
try {
TemplateBuffer buffer = context.evaluate(template);
templateString = buffer.getString();
for (TemplateVariable t : buffer.getVariables()) {
if (t.getName().equals(org.eclipse.jface.text.templates.GlobalTemplateVariables.Cursor.NAME)) {
if (t.getOffsets().length > 0)
offset[0] = t.getOffsets()[0];
}
}
} catch (Exception e) {
XSLUIPlugin.log(e);
}
}
return templateString;
}
use of org.eclipse.jface.text.templates.TemplateBuffer in project webtools.sourceediting by eclipse.
the class NewHTMLTemplatesWizardPage method getTemplateString.
/**
* Returns template string to insert.
*
* @return String to insert or null if none is to be inserted
*/
String getTemplateString() {
String templateString = null;
Template template = getSelectedTemplate();
if (template != null) {
TemplateContextType contextType = HTMLUIPlugin.getDefault().getTemplateContextRegistry().getContextType(TemplateContextTypeIdsHTML.NEW);
IDocument document = new Document();
TemplateContext context = new DocumentTemplateContext(contextType, document, 0, 0);
try {
TemplateBuffer buffer = context.evaluate(template);
templateString = buffer.getString();
} catch (Exception e) {
// $NON-NLS-1$
Logger.log(Logger.WARNING_DEBUG, "Could not create template for new html", e);
}
}
return templateString;
}
use of org.eclipse.jface.text.templates.TemplateBuffer in project webtools.sourceediting by eclipse.
the class NewJSPTemplatesWizardPage method getTemplateString.
/**
* Returns template string to insert.
*
* @return String to insert or null if none is to be inserted
*/
String getTemplateString() {
String templateString = null;
Template template = getSelectedTemplate();
if (template != null) {
TemplateContextType contextType = JSPUIPlugin.getDefault().getTemplateContextRegistry().getContextType(TemplateContextTypeIdsJSP.NEW);
IDocument document = new Document();
TemplateContext context = new DocumentTemplateContext(contextType, document, 0, 0);
try {
TemplateBuffer buffer = context.evaluate(template);
templateString = buffer.getString();
} catch (Exception e) {
// $NON-NLS-1$
Logger.log(Logger.WARNING_DEBUG, "Could not create template for new jsp", e);
}
}
return templateString;
}
Aggregations