Examples of TemplateContextType


Examples of org.eclipse.jface.text.templates.TemplateContextType

    return PHPUiPlugin.getDefault().getCodeTemplateContextRegistry();
  }

  protected String getTemplatesLocationMessage() {
    ContextTypeRegistry templateContextRegistry = getTemplatesContextTypeRegistry();
    TemplateContextType templateContextType = templateContextRegistry
        .getContextType(getTemplateContextTypeId());
    String name = templateContextType.getName();
    return NLS
        .bind(PHPUIMessages.newPhpFile_wizard_templatePage_phpTemplatesLocation,
            name);
  }
View Full Code Here

Examples of org.eclipse.jface.text.templates.TemplateContextType

      throwReadException(e);
    }
  }

  protected String validateTemplate(Template template) {
    TemplateContextType type = fRegistry.getContextType(template
        .getContextTypeId());
    if (type == null) {
      return PhpTemplateMessages.TemplateSet_3 + template.getContextTypeId();
    }
    try {
      type.validate(template.getPattern());
      return null;
    } catch (TemplateException e) {
      return e.getMessage();
    }
  }
View Full Code Here

Examples of org.eclipse.jface.text.templates.TemplateContextType

  /* (non-Javadoc)
   * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#createContext(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
   */
  protected TemplateContext createContext(ITextViewer contextViewer, IRegion region) {
    TemplateContextType contextType= getContextType(contextViewer, region);
    if (contextType != null) {
            Point selection= contextViewer.getSelectedRange();
            Position position;
            if (selection.y > 0) {
                position= new Position(selection.x, selection.y);   
View Full Code Here

Examples of org.eclipse.jface.text.templates.TemplateContextType

    /**
     * Overridden so that we can do the indentation in this case.
     */
    @Override
    protected TemplateContext createContext(final ITextViewer viewer, final IRegion region) {
        TemplateContextType contextType = getContextType(viewer, region);
        return PyTemplateCompletionProcessor.createContext(contextType, viewer, region);
    }
View Full Code Here

Examples of org.eclipse.jface.text.templates.TemplateContextType

public class PyDocumentTemplateContextTest extends TestCase {

    public void testApply() throws Exception {
        Document doc = new Document("" + "\n" + "");
        PyDocumentTemplateContext context = new PyDocumentTemplateContext(new TemplateContextType(), doc, 0, 0, null,
                new TestIndentPrefs(true, 4));

        Template template = new Template("", "", "", "if a:\n\tpass", true);
        TemplateBuffer buffer = context.evaluate(template);
        assertEquals("if a:\n    pass", buffer.getString());

        context = new PyDocumentTemplateContext(new TemplateContextType(), doc, 0, 0, null, new TestIndentPrefs(false,
                4));
        template = new Template("", "", "", "if a\n    print 'a:    '", true);
        buffer = context.evaluate(template);
        assertEquals("if a\n\tprint 'a:    '", buffer.getString());

        doc = new Document("" + "\n\t" + "");
        context = new PyDocumentTemplateContext(new TemplateContextType(), doc, doc.getLength(), 0, "\t",
                new TestIndentPrefs(false, 4));
        template = new Template("", "", "", "if a\n    print 'a:    '", true);
        buffer = context.evaluate(template);
        assertEquals("if a\n\t\tprint 'a:    '", buffer.getString());

        doc = new Document("" + "\n    " + "");
        context = new PyDocumentTemplateContext(new TemplateContextType(), doc, doc.getLength(), 0, "    ",
                new TestIndentPrefs(true, 4));
        template = new Template("", "", "", "if a\n\tprint 'a:    '", true);
        buffer = context.evaluate(template);
        assertEquals("if a\n        print 'a:    '", buffer.getString());

        //let's check if we have a template with \n and a document with \r\n (it should be applied with \r\n)
        doc = new Document("" + "\r\n    " + "");
        context = new PyDocumentTemplateContext(new TemplateContextType(), doc, doc.getLength(), 0, "    ",
                new TestIndentPrefs(true, 4));
        template = new Template("", "", "", "if a\n\tprint 'a:    '", true);
        buffer = context.evaluate(template);
        assertEquals("if a\r\n        print 'a:    '", buffer.getString());

        //let's check if we have a template with \r\n and a document with \r (it should be applied with \r)
        doc = new Document("" + "\r    " + "");
        context = new PyDocumentTemplateContext(new TemplateContextType(), doc, doc.getLength(), 0, "    ",
                new TestIndentPrefs(true, 4));
        template = new Template("", "", "", "if a\r\n\tprint 'a:    '", true);
        buffer = context.evaluate(template);
        assertEquals("if a\r        print 'a:    '", buffer.getString());
View Full Code Here

Examples of org.eclipse.jface.text.templates.TemplateContextType

    }


    protected TemplateContextType getContextType( ITextViewer viewer, IRegion region )
    {
        TemplateContextType contextType = BrowserUIPlugin.getDefault().getFilterTemplateContextTypeRegistry()
            .getContextType( BrowserUIConstants.FILTER_TEMPLATE_ID );
        return contextType;
    }
View Full Code Here

Examples of org.eclipse.jface.text.templates.TemplateContextType

    }

    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(
        new Path(containerName + "/" + fileName));
    ISourceModule sourceModule = DLTKCore.createSourceModuleFrom(file);
    TemplateContextType type = contextTypeRegistry.getContextType(template
        .getContextTypeId());
   

   
    return ((CodeTemplateContextType) type).createContext(document, 0, 0,sourceModule, varHolder);
View Full Code Here

Examples of org.eclipse.jface.text.templates.TemplateContextType

  public void addContextType(String id) {
    Assert.isNotNull(id);
    if (getContextType(id) != null)
      return;

    TemplateContextType type= createContextType(id);
    if (type != null)
      addContextType(type);

  }
View Full Code Here

Examples of org.eclipse.jface.text.templates.TemplateContextType

   */
  public static TemplateContextType createContextType(String id) {
    Assert.isNotNull(id);

    IConfigurationElement[] extensions= getTemplateExtensions();
    TemplateContextType type;
    try {
      type= createContextType(extensions, id);
      if (type != null) {
        TemplateVariableResolver[] resolvers= createResolvers(extensions, id);
        for (int i= 0; i < resolvers.length; i++)
          type.addResolver(resolvers[i]);
      }
    } catch (CoreException e) {
      TextEditorPlugin.log(e);
      type= null;
    }
View Full Code Here

Examples of org.eclipse.jface.text.templates.TemplateContextType

  }

  private static TemplateContextType createContextType(IConfigurationElement element) throws CoreException {
    String id= element.getAttribute(ID);
    try {
      TemplateContextType contextType= (TemplateContextType) element.createExecutableExtension(CLASS);
      String name= element.getAttribute(NAME);
      if (name == null)
        name= id;

      if (contextType.getId() == null)
        contextType.setId(id);
      if (contextType.getName() == null)
        contextType.setName(name);

      return contextType;
    } catch (ClassCastException e) {
      throw new CoreException(new Status(IStatus.ERROR, TextEditorPlugin.PLUGIN_ID, IStatus.OK, "extension does not implement " + TemplateContextType.class.getName(), e)); //$NON-NLS-1$
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.