Search in sources :

Example 46 with TemplateBuffer

use of org.eclipse.jface.text.templates.TemplateBuffer in project eclipse.platform.text by eclipse.

the class TemplateTranslatorTest method testTextParameterTemplate.

@Test
public void testTextParameterTemplate() throws Exception {
    TemplateBuffer buffer = fTranslator.translate("foo ${ var : qual.type ( 'a parameter 1', qual.param2, 'a parameter ''3' ) } bar");
    assertNull(fTranslator.getErrorMessage());
    assertEquals("foo var bar", buffer.getString());
    TemplateVariable[] vars = buffer.getVariables();
    assertEquals(1, vars.length);
    assertEquals("var", vars[0].getName());
    assertEquals(1, vars[0].getOffsets().length);
    assertEquals(4, vars[0].getOffsets()[0]);
    assertEquals(3, vars[0].getLength());
    assertEquals(false, vars[0].isUnambiguous());
    assertEquals("var", vars[0].getDefaultValue());
    assertEquals(1, vars[0].getValues().length);
    assertEquals(vars[0].getDefaultValue(), vars[0].getValues()[0]);
    assertEquals("qual.type", vars[0].getType());
    List<String> params = new ArrayList<>(3);
    params.add("a parameter 1");
    params.add("qual.param2");
    params.add("a parameter '3");
    assertEquals(params, vars[0].getVariableType().getParams());
}
Also used : ArrayList(java.util.ArrayList) TemplateVariable(org.eclipse.jface.text.templates.TemplateVariable) TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) Test(org.junit.Test)

Example 47 with TemplateBuffer

use of org.eclipse.jface.text.templates.TemplateBuffer in project eclipse.platform.text by eclipse.

the class TemplateTranslatorTest method testTypedTemplate.

/* 3.3 typed template variables */
@Test
public void testTypedTemplate() throws Exception {
    TemplateBuffer buffer = fTranslator.translate("foo ${var:type} bar");
    assertNull(fTranslator.getErrorMessage());
    assertEquals("foo var bar", buffer.getString());
    TemplateVariable[] vars = buffer.getVariables();
    assertEquals(1, vars.length);
    assertEquals("var", vars[0].getName());
    assertEquals(1, vars[0].getOffsets().length);
    assertEquals(4, vars[0].getOffsets()[0]);
    assertEquals(3, vars[0].getLength());
    assertEquals(false, vars[0].isUnambiguous());
    assertEquals("var", vars[0].getDefaultValue());
    assertEquals(1, vars[0].getValues().length);
    assertEquals("type", vars[0].getType());
    assertEquals(vars[0].getDefaultValue(), vars[0].getValues()[0]);
}
Also used : TemplateVariable(org.eclipse.jface.text.templates.TemplateVariable) TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) Test(org.junit.Test)

Example 48 with TemplateBuffer

use of org.eclipse.jface.text.templates.TemplateBuffer in project eclipse.platform.text by eclipse.

the class TemplateTranslatorTest method testDollar.

@Test
public void testDollar() throws Exception {
    TemplateBuffer buffer = fTranslator.translate("foo $$ bar");
    assertNull(fTranslator.getErrorMessage());
    TemplateVariable[] vars = buffer.getVariables();
    assertEquals(0, vars.length);
    assertEquals("foo $ bar", buffer.getString());
}
Also used : TemplateVariable(org.eclipse.jface.text.templates.TemplateVariable) TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) Test(org.junit.Test)

Example 49 with TemplateBuffer

use of org.eclipse.jface.text.templates.TemplateBuffer in project eclipse.platform.text by eclipse.

the class TemplateTranslatorTest method testNonAsciiVarTemplate.

@Test
public void testNonAsciiVarTemplate() throws Exception {
    TemplateBuffer buffer = fTranslator.translate("System.out.println(${bl\u00F6d:var} + \" with element type \" + ${h\u00E4:elemType(bl\u00F6d)});");
    assertNull(fTranslator.getErrorMessage());
    assertEquals("System.out.println(bl\u00F6d + \" with element type \" + h\u00E4);", buffer.getString());
    TemplateVariable[] vars = buffer.getVariables();
    assertEquals(2, vars.length);
    assertEquals("bl\u00F6d", vars[0].getName());
    assertEquals(1, vars[0].getOffsets().length);
    assertEquals(19, vars[0].getOffsets()[0]);
    assertEquals(4, vars[0].getLength());
    assertEquals(false, vars[0].isUnambiguous());
    assertEquals("bl\u00F6d", vars[0].getDefaultValue());
    assertEquals(1, vars[0].getValues().length);
    assertEquals(vars[0].getDefaultValue(), vars[0].getValues()[0]);
    assertEquals("var", vars[0].getType());
    assertEquals("h\u00E4", vars[1].getName());
    assertEquals(1, vars[1].getOffsets().length);
    assertEquals(50, vars[1].getOffsets()[0]);
    assertEquals(2, vars[1].getLength());
    assertEquals(false, vars[1].isUnambiguous());
    assertEquals("h\u00E4", vars[1].getDefaultValue());
    assertEquals(1, vars[1].getValues().length);
    assertEquals(vars[1].getDefaultValue(), vars[1].getValues()[0]);
    assertEquals("elemType", vars[1].getType());
}
Also used : TemplateVariable(org.eclipse.jface.text.templates.TemplateVariable) TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) Test(org.junit.Test)

Example 50 with TemplateBuffer

use of org.eclipse.jface.text.templates.TemplateBuffer in project eclipse.platform.text by eclipse.

the class TemplateTranslatorTest method testParameterizedTypeTemplate.

@Test
public void testParameterizedTypeTemplate() throws Exception {
    TemplateBuffer buffer = fTranslator.translate("foo ${var:type(param)} bar");
    assertNull(fTranslator.getErrorMessage());
    assertEquals("foo var bar", buffer.getString());
    TemplateVariable[] vars = buffer.getVariables();
    assertEquals(1, vars.length);
    assertEquals("var", vars[0].getName());
    assertEquals(1, vars[0].getOffsets().length);
    assertEquals(4, vars[0].getOffsets()[0]);
    assertEquals(3, vars[0].getLength());
    assertEquals(false, vars[0].isUnambiguous());
    assertEquals("var", vars[0].getDefaultValue());
    assertEquals(1, vars[0].getValues().length);
    assertEquals(vars[0].getDefaultValue(), vars[0].getValues()[0]);
    assertEquals("type", vars[0].getType());
    assertEquals(Collections.singletonList("param"), vars[0].getVariableType().getParams());
}
Also used : TemplateVariable(org.eclipse.jface.text.templates.TemplateVariable) TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) Test(org.junit.Test)

Aggregations

TemplateBuffer (org.eclipse.jface.text.templates.TemplateBuffer)71 TemplateVariable (org.eclipse.jface.text.templates.TemplateVariable)30 BadLocationException (org.eclipse.jface.text.BadLocationException)26 TemplateException (org.eclipse.jface.text.templates.TemplateException)26 Document (org.eclipse.jface.text.Document)23 Template (org.eclipse.jface.text.templates.Template)23 Test (org.junit.Test)22 IDocument (org.eclipse.jface.text.IDocument)21 CoreException (org.eclipse.core.runtime.CoreException)17 DocumentTemplateContext (org.eclipse.jface.text.templates.DocumentTemplateContext)11 TemplateTranslator (org.eclipse.jface.text.templates.TemplateTranslator)11 TemplateContext (org.eclipse.jface.text.templates.TemplateContext)9 TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)8 CodeTemplateContext (org.eclipse.jdt.internal.corext.template.java.CodeTemplateContext)6 SimpleDateFormat (com.ibm.icu.text.SimpleDateFormat)4 CodeGenerationTemplate (org.eclipse.jdt.ls.core.internal.preferences.CodeGenerationTemplate)4 ArrayList (java.util.ArrayList)3 ITypeParameter (org.eclipse.jdt.core.ITypeParameter)3 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)3 TypeParameter (org.eclipse.jdt.core.dom.TypeParameter)3