Search in sources :

Example 26 with TemplateVariable

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

the class TemplateTranslatorTest method testMultiParameterizedTypeTemplate2.

@Test
public void testMultiParameterizedTypeTemplate2() throws Exception {
    TemplateBuffer buffer = fTranslator.translate("foo ${var:type(param)} bar ${var} end");
    assertNull(fTranslator.getErrorMessage());
    assertEquals("foo var bar var end", buffer.getString());
    TemplateVariable[] vars = buffer.getVariables();
    assertEquals(1, vars.length);
    assertEquals("var", vars[0].getName());
    assertEquals(2, vars[0].getOffsets().length);
    assertEquals(4, vars[0].getOffsets()[0]);
    assertEquals(12, vars[0].getOffsets()[1]);
    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 27 with TemplateVariable

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

the class TemplateTranslatorTest method testParameterizedTypeTemplateWithWhitespace.

@Test
public void testParameterizedTypeTemplateWithWhitespace() throws Exception {
    TemplateBuffer buffer = fTranslator.translate("foo ${ var : type ( param1 , param2 , param3 ) } 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());
    List<String> params = new ArrayList<>(2);
    params.add("param1");
    params.add("param2");
    params.add("param3");
    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 28 with TemplateVariable

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

the class TemplateTranslatorTest method testSimpleTemplate.

@Test
public void testSimpleTemplate() throws Exception {
    TemplateBuffer buffer = fTranslator.translate("foo ${var} 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("var", vars[0].getType());
}
Also used : TemplateVariable(org.eclipse.jface.text.templates.TemplateVariable) TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) Test(org.junit.Test)

Example 29 with TemplateVariable

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

the class TemplateTranslatorTest method testQualifiedTypeTemplate.

@Test
public void testQualifiedTypeTemplate() throws Exception {
    TemplateBuffer buffer = fTranslator.translate("foo ${ var : qual.type ( qual.param1, qual.param2 ) } 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<>(2);
    params.add("qual.param1");
    params.add("qual.param2");
    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 30 with TemplateVariable

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

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