Search in sources :

Example 31 with TemplateVariable

use of org.eclipse.jface.text.templates.TemplateVariable 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 32 with TemplateVariable

use of org.eclipse.jface.text.templates.TemplateVariable 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 33 with TemplateVariable

use of org.eclipse.jface.text.templates.TemplateVariable 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 34 with TemplateVariable

use of org.eclipse.jface.text.templates.TemplateVariable 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)

Example 35 with TemplateVariable

use of org.eclipse.jface.text.templates.TemplateVariable 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());
}
Also used : TemplateVariable(org.eclipse.jface.text.templates.TemplateVariable) TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer)

Aggregations

TemplateVariable (org.eclipse.jface.text.templates.TemplateVariable)44 TemplateBuffer (org.eclipse.jface.text.templates.TemplateBuffer)30 IDocument (org.eclipse.jface.text.IDocument)14 Test (org.junit.Test)14 Document (org.eclipse.jface.text.Document)13 BadLocationException (org.eclipse.jface.text.BadLocationException)11 Template (org.eclipse.jface.text.templates.Template)10 TemplateException (org.eclipse.jface.text.templates.TemplateException)10 CoreException (org.eclipse.core.runtime.CoreException)9 CodeTemplateContext (org.eclipse.jdt.internal.corext.template.java.CodeTemplateContext)6 ArrayList (java.util.ArrayList)5 IRegion (org.eclipse.jface.text.IRegion)4 ITypeParameter (org.eclipse.jdt.core.ITypeParameter)3 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)3 TypeParameter (org.eclipse.jdt.core.dom.TypeParameter)3 MultiVariable (org.eclipse.jdt.internal.ui.text.template.contentassist.MultiVariable)3 CodeTemplateContext (org.eclipse.jdt.ls.core.internal.corext.template.java.CodeTemplateContext)3 CodeGenerationTemplate (org.eclipse.jdt.ls.core.internal.preferences.CodeGenerationTemplate)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashSet (java.util.HashSet)2