Package org.eclipse.jface.text.templates

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


        if (ErlTemplateCompletionPreferences.getIndentCode()) {
            template = indentTemplatePattern(template, indentFrom0);
        }

        final TemplateTranslator translator = new TemplateTranslator();
        final TemplateBuffer buffer = translator.translate(template);

        getContextType().resolve(buffer, this);

        return buffer;
    }
View Full Code Here


        }
        reentry = true;
        final DocumentTemplateContext context = new DocumentTemplateContext(
                ErlangSourceContextTypeModule.getDefault(), new Document(
                        fTemplate.getPattern()), 0, fTemplate.getPattern().length());
        TemplateBuffer tb;
        try {
            tb = context.evaluate(fTemplate);
            variable.setValue(tb.getString());
        } catch (final BadLocationException e) {
        } catch (final TemplateException e) {
        }
        reentry = false;
    }
View Full Code Here

    @Override
    public String getAdditionalProposalInfo() {
        try {
            final TemplateContext context = getContext();
            context.setReadOnly(true);
            TemplateBuffer templateBuffer;
            try {
                final Template template = getTemplate();
                if (context instanceof ErlangTemplateContext) {
                    final ErlangTemplateContext etc = (ErlangTemplateContext) context;
                    templateBuffer = etc.evaluate(template, true);
                } else {
                    templateBuffer = context.evaluate(template);
                }
            } catch (final TemplateException e) {
                return null;
            }
            return templateBuffer.getString();
        } catch (final BadLocationException e) {
            return null;
        }
    }
View Full Code Here

            DocumentTemplateContext commentContext = new DocumentTemplateContext(
                    ErlangSourceContextTypeLayout.getDefault(), new Document(
                            commentTemplate.getPattern()), 0, commentTemplate
                            .getPattern().length());
            TemplateBuffer tb = null;
            try {
                tb = commentContext.evaluate(commentTemplate);
            } catch (final BadLocationException e) {
                ErlLogger.warn(e);
                buff.append("Error: " + e.getMessage());
            } catch (final TemplateException e) {
                ErlLogger.warn(e);
                buff.append("Error: " + commentTemplate.getName()
                        + " could not be validated!");
            }

            if (tb != null) {
                buff.append(tb.getString() + "\n");
            }

            final Template template = ErlangSourceContextTypeComment.getDefault()
                    .getTemplateStore()
                    .getTemplateData("org.erlide.ui.erlangsource.functionlayout")
                    .getTemplate();

            commentContext = new DocumentTemplateContext(
                    ErlangSourceContextTypeLayout.getDefault(), new Document(
                            template.getPattern()), 0, template.getPattern().length());
            try {
                tb = commentContext.evaluate(template);
            } catch (final BadLocationException e) {
                ErlLogger.warn(e);
                buff.append("Error: " + e.getMessage());
            } catch (final TemplateException e) {
                ErlLogger.warn(e);
                buff.append("Error: " + template.getName() + " could not be validated!");
            }

            if (tb != null) {
                buff.append(tb.getString() + "\n");
            }

        }

        variable.setValue(buff.toString());
View Full Code Here

                LocalFunctionsVariableResolver.getDefault().addFunction(fun.name,
                        fun.arity);
            }
        }

        TemplateBuffer tb = null;

        try {
            final DocumentTemplateContext context = new DocumentTemplateContext(
                    contextType, new Document(template.getPattern()), 0, template
                            .getPattern().length());
            tb = context.evaluate(template);
        } catch (final BadLocationException e) {
            ErlLogger.warn(e);
        } catch (final TemplateException e) {
            ErlLogger.warn(e);
        }

        if (tb == null) {
            return null;
        }
        return tb.getString();
    }
View Full Code Here

  /*
   * @see org.eclipse.jface.text.templates.TemplateContext#evaluate(org.eclipse.jface.text.templates.Template)
   */
  public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
    TemplateBuffer buffer = super.evaluate(template);
    String templateName = template.getName().toLowerCase();
    if (buffer != null) {
      if ((fInsertOffset > -1) && (fInsertOffset > getStart())) {
        String prefix = getDocument().get(getStart(), fInsertOffset - getStart());
        if (!templateName.startsWith(prefix.toLowerCase())) {
          // generate a new buffer that actually contains the
          // text that was going to be overwritten
          int prefixSize = prefix.length();
          TemplateVariable[] newTemplateVar = buffer.getVariables();
          for (int i =0; i < newTemplateVar.length; i++ ){
            int[] offsets = newTemplateVar[i].getOffsets();
            for (int j=0; j<offsets.length ;j++){
              offsets[j] += prefixSize;
            }
          }
          buffer = new TemplateBuffer(prefix + buffer.getString(), newTemplateVar);
        }
      }
    }
    return buffer;
  }
View Full Code Here

    if (template != null) {
      TemplateContextType contextType = JSPUIPlugin.getDefault().getTemplateContextRegistry().getContextType(TemplateContextTypeIdsJSP.NEW_TAG);
      IDocument document = new Document();
      TemplateContext context = new DocumentTemplateContext(contextType, document, 0, 0);
      try {
        TemplateBuffer buffer = context.evaluate(template);
        templateString = buffer.getString();
      }
      catch (Exception e) {
        Logger.log(Logger.WARNING_DEBUG, "Could not create template for new jsp tag", e); //$NON-NLS-1$
      }
    }
View Full Code Here

  /*
   * @see org.eclipse.jface.text.templates.TemplateContext#evaluate(org.eclipse.jface.text.templates.Template)
   */
  public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
    TemplateBuffer buffer = super.evaluate(template);
    if (buffer != null) {
      if (fInsertOffset > -1 && fInsertOffset > getStart()) {
        String prefix = getDocument().get(getStart(), fInsertOffset - getStart());
        if (!template.getName().startsWith(prefix)) {
          // generate a new buffer that actually contains the
          // text that was going to be overwritten
          int prefixSize = prefix.length();
          TemplateVariable[] newTemplateVar = buffer.getVariables();
          for (int i =0; i < newTemplateVar.length; i++ ){
            int[] offsets = newTemplateVar[i].getOffsets();
            for (int j=0; j<offsets.length ;j++){
              offsets[j] += prefixSize;
            }
          }
          buffer = new TemplateBuffer(prefix + buffer.getString(), newTemplateVar);
        }
      }
    }
    return buffer;
  }
View Full Code Here

    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) {
        Logger.log(Logger.WARNING_DEBUG, "Could not create template for new jsp", e); //$NON-NLS-1$
      }
    }
View Full Code Here

  /*
   * @see org.eclipse.jface.text.templates.TemplateContext#evaluate(org.eclipse.jface.text.templates.Template)
   */
  public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
    TemplateBuffer buffer = super.evaluate(template);
    if (buffer != null) {
      if (fInsertOffset > -1 && fInsertOffset > getStart()) {
        String prefix = getDocument().get(getStart(), fInsertOffset - getStart());
        if (!template.getName().startsWith(prefix)) {
          // generate a new buffer that actually contains the
          // text that was going to be overwritten
          int prefixSize = prefix.length();
          TemplateVariable[] newTemplateVar = buffer.getVariables();
          for (int i =0; i < newTemplateVar.length; i++ ){
            int[] offsets = newTemplateVar[i].getOffsets();
            for (int j=0; j<offsets.length ;j++){
              offsets[j] += prefixSize;
            }
          }
          buffer = new TemplateBuffer(prefix + buffer.getString(), newTemplateVar);
        }
      }
    }
    return buffer;
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jface.text.templates.TemplateBuffer

Copyright © 2018 www.massapicom. 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.