Java 类org.eclipse.jface.text.templates.TemplateTranslator 实例源码

项目:eclipse.jdt.ls    文件:CodeTemplateContext.java   
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
    // test that all variables are defined
    Iterator<TemplateVariableResolver> iterator= getContextType().resolvers();
    while (iterator.hasNext()) {
        TemplateVariableResolver var= iterator.next();
        if (var instanceof CodeTemplateContextType.CodeTemplateVariableResolver) {
            Assert.isNotNull(getVariable(var.getType()), "Variable " + var.getType() + "not defined"); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }

    if (!canEvaluate(template)) {
        return null;
    }

    String pattern= changeLineDelimiter(template.getPattern(), fLineDelimiter);

    TemplateTranslator translator= new TemplateTranslator();
    TemplateBuffer buffer= translator.translate(pattern);
    getContextType().resolve(buffer, this);
    return buffer;
}
项目:bts    文件:XtextTemplateContext.java   
protected TemplateTranslator createTemplateTranslator() {
    try {
        int offset = getStart();
        IRegion lineRegion = getDocument().getLineInformationOfOffset(offset);
        String line = getDocument().get(lineRegion.getOffset(), lineRegion.getLength());
        int i = 0;
        while(i < line.length() && Character.isWhitespace(line.charAt(i))) {
            i++;
        }
        if (i != 0)
            return new IndentationAwareTemplateTranslator(line.substring(0, i));
        return new TemplateTranslator();
    } catch(BadLocationException ex) {
        return new TemplateTranslator();
    }
}
项目:che    文件:CodeTemplateContext.java   
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
  // test that all variables are defined
  Iterator<TemplateVariableResolver> iterator = getContextType().resolvers();
  while (iterator.hasNext()) {
    TemplateVariableResolver var = iterator.next();
    if (var instanceof CodeTemplateContextType.CodeTemplateVariableResolver) {
      Assert.isNotNull(
          getVariable(var.getType()),
          "Variable " + var.getType() + "not defined"); // $NON-NLS-1$ //$NON-NLS-2$
    }
  }

  if (!canEvaluate(template)) return null;

  String pattern = changeLineDelimiter(template.getPattern(), fLineDelimiter);

  TemplateTranslator translator = new TemplateTranslator();
  TemplateBuffer buffer = translator.translate(pattern);
  getContextType().resolve(buffer, this);
  return buffer;
}
项目:che    文件:JavaDocContext.java   
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
  TemplateTranslator translator = new TemplateTranslator();
  TemplateBuffer buffer = translator.translate(template);

  getContextType().resolve(buffer, this);

  //        IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore();
  boolean useCodeFormatter =
      true; // prefs.getBoolean(PreferenceConstants.TEMPLATES_USE_CODEFORMATTER);

  IJavaProject project = getJavaProject();
  JavaFormatter formatter =
      new JavaFormatter(
          TextUtilities.getDefaultLineDelimiter(getDocument()),
          getIndentation(),
          useCodeFormatter,
          project);
  formatter.format(buffer, this);

  return buffer;
}
项目:APICloud-Studio    文件:DocumentSnippetTemplateContext.java   
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException
{
    if (!canEvaluate(template))
        return null;

    try
    {
        this.template = template;

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

        getContextType().resolve(buffer, this);

        return buffer;
    }
    finally
    {
        this.template = null;
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:CodeTemplateContext.java   
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
    // test that all variables are defined
    Iterator<TemplateVariableResolver> iterator= getContextType().resolvers();
    while (iterator.hasNext()) {
        TemplateVariableResolver var= iterator.next();
        if (var instanceof CodeTemplateContextType.CodeTemplateVariableResolver) {
            Assert.isNotNull(getVariable(var.getType()), "Variable " + var.getType() + "not defined"); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }

    if (!canEvaluate(template))
        return null;

    String pattern= changeLineDelimiter(template.getPattern(), fLineDelimiter);

    TemplateTranslator translator= new TemplateTranslator();
    TemplateBuffer buffer= translator.translate(pattern);
    getContextType().resolve(buffer, this);
    return buffer;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaDocContext.java   
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
    TemplateTranslator translator= new TemplateTranslator();
    TemplateBuffer buffer= translator.translate(template);

    getContextType().resolve(buffer, this);

    IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore();
    boolean useCodeFormatter= prefs.getBoolean(PreferenceConstants.TEMPLATES_USE_CODEFORMATTER);

    IJavaProject project= getJavaProject();
    JavaFormatter formatter= new JavaFormatter(TextUtilities.getDefaultLineDelimiter(getDocument()), getIndentation(), useCodeFormatter, project);
    formatter.format(buffer, this);

    return buffer;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CodeTemplateContext.java   
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
    // test that all variables are defined
    Iterator<TemplateVariableResolver> iterator= getContextType().resolvers();
    while (iterator.hasNext()) {
        TemplateVariableResolver var= iterator.next();
        if (var instanceof CodeTemplateContextType.CodeTemplateVariableResolver) {
            Assert.isNotNull(getVariable(var.getType()), "Variable " + var.getType() + "not defined"); //$NON-NLS-1$ //$NON-NLS-2$
        }
    }

    if (!canEvaluate(template))
        return null;

    String pattern= changeLineDelimiter(template.getPattern(), fLineDelimiter);

    TemplateTranslator translator= new TemplateTranslator();
    TemplateBuffer buffer= translator.translate(pattern);
    getContextType().resolve(buffer, this);
    return buffer;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaDocContext.java   
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
    TemplateTranslator translator= new TemplateTranslator();
    TemplateBuffer buffer= translator.translate(template);

    getContextType().resolve(buffer, this);

    IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore();
    boolean useCodeFormatter= prefs.getBoolean(PreferenceConstants.TEMPLATES_USE_CODEFORMATTER);

    IJavaProject project= getJavaProject();
    JavaFormatter formatter= new JavaFormatter(TextUtilities.getDefaultLineDelimiter(getDocument()), getIndentation(), useCodeFormatter, project);
    formatter.format(buffer, this);

    return buffer;
}
项目:bts    文件:XtextTemplateContext.java   
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
    if (!canEvaluate(template))
        return null;

    TemplateTranslator translator= createTemplateTranslator();
    TemplateBuffer buffer= translator.translate(template);

    getContextType().resolve(buffer, this);

    return buffer;
}
项目:bts    文件:XtextTemplateContext.java   
/**
 * @since 2.3
 */
public TemplateBuffer evaluateForDisplay(Template template) throws BadLocationException, TemplateException {
    if (!canEvaluate(template))
        return null;

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

    getContextType().resolve(buffer, this);

    return buffer;
}
项目:KaiZen-OpenAPI-Editor    文件:SwaggerTemplateContext.java   
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
    if (!canEvaluate(template))
        return null;

    TemplateTranslator translator = createTemplateTranslator();
    TemplateBuffer buffer = translator.translate(template);

    getContextType().resolve(buffer, this);

    return buffer;
}
项目:KaiZen-OpenAPI-Editor    文件:SwaggerTemplateContext.java   
/**
 * @since 2.3
 */
public TemplateBuffer evaluateForDisplay(Template template) throws BadLocationException, TemplateException {
    if (!canEvaluate(template))
        return null;

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

    getContextType().resolve(buffer, this);

    return buffer;
}
项目:KaiZen-OpenAPI-Editor    文件:SwaggerTemplateContext.java   
protected TemplateTranslator createTemplateTranslator() {
    try {
        int offset = getStart();
        IRegion lineRegion = getDocument().getLineInformationOfOffset(offset);
        String line = getDocument().get(lineRegion.getOffset(), lineRegion.getLength());
        int i = 0;
        // support for array items
        StringBuilder indentation = new StringBuilder();
        while (i < line.length()) {
            char indentSymbol = line.charAt(i);
            if (Character.isWhitespace(indentSymbol)) {
                indentation.append(indentSymbol);
                i++;
            } else if ('-' == indentSymbol) {// array item
                indentation.append(' ');
                i++;
            } else {
                break;
            }
        }
        if (i != 0)
            return new IndentationAwareTemplateTranslator(indentation.toString());
        return new TemplateTranslator();
    } catch (BadLocationException ex) {
        return new TemplateTranslator();
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaContext.java   
@Override
    public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
        clear();

        if (!canEvaluate(template))
            throw new TemplateException(JavaTemplateMessages.Context_error_cannot_evaluate);

        TemplateTranslator translator= new TemplateTranslator() {
            @Override
            protected TemplateVariable createVariable(TemplateVariableType type, String name, int[] offsets) {
//              TemplateVariableResolver resolver= getContextType().getResolver(type.getName());
//              return resolver.createVariable();

                MultiVariable variable= new JavaVariable(type, name, offsets);
                fVariables.put(name, variable);
                return variable;
            }
        };
        TemplateBuffer buffer= translator.translate(template);

        getContextType().resolve(buffer, this);

        rewriteImports();

        IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore();
        boolean useCodeFormatter= prefs.getBoolean(PreferenceConstants.TEMPLATES_USE_CODEFORMATTER);

        IJavaProject project= getJavaProject();
        JavaFormatter formatter= new JavaFormatter(TextUtilities.getDefaultLineDelimiter(getDocument()), getIndentation(), useCodeFormatter, project);
        formatter.format(buffer, this);

        clear();

        return buffer;
    }
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaContext.java   
@Override
    public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
        clear();

        if (!canEvaluate(template))
            throw new TemplateException(JavaTemplateMessages.Context_error_cannot_evaluate);

        TemplateTranslator translator= new TemplateTranslator() {
            @Override
            protected TemplateVariable createVariable(TemplateVariableType type, String name, int[] offsets) {
//              TemplateVariableResolver resolver= getContextType().getResolver(type.getName());
//              return resolver.createVariable();

                MultiVariable variable= new JavaVariable(type, name, offsets);
                fVariables.put(name, variable);
                return variable;
            }
        };
        TemplateBuffer buffer= translator.translate(template);

        getContextType().resolve(buffer, this);

        rewriteImports();

        IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore();
        boolean useCodeFormatter= prefs.getBoolean(PreferenceConstants.TEMPLATES_USE_CODEFORMATTER);

        IJavaProject project= getJavaProject();
        JavaFormatter formatter= new JavaFormatter(TextUtilities.getDefaultLineDelimiter(getDocument()), getIndentation(), useCodeFormatter, project);
        formatter.format(buffer, this);

        clear();

        return buffer;
    }
项目:goclipse    文件:LangContext.java   
public TemplateBuffer evaluate(Template template, boolean fixIndentation) 
            throws BadLocationException, TemplateException {
        if (!canEvaluate(template))
            return null;

        TemplateTranslator translator= new TemplateTranslator();

        String pattern = template.getPattern();
//      if(fixIndentation) {
//          pattern = fixIndentation(pattern);
//      }
        TemplateBuffer buffer = translator.translate(pattern);

        getContextType().resolve(buffer, this);

        if(fixIndentation) {
            String delimiter = TextUtilities.getDefaultLineDelimiter(getDocument());
            JavaFormatter formatter = new JavaFormatter(delimiter) {
                @Override
                protected void indent(IDocument document) throws BadLocationException, MalformedTreeException {
                    simpleIndent(document);
                }
            };
            formatter.format(buffer, this);
        }

        return buffer;
    }
项目:che    文件:JavaContext.java   
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
  clear();

  if (!canEvaluate(template))
    throw new TemplateException(JavaTemplateMessages.Context_error_cannot_evaluate);

  TemplateTranslator translator =
      new TemplateTranslator() {
        @Override
        protected TemplateVariable createVariable(
            TemplateVariableType type, String name, int[] offsets) {
          //                TemplateVariableResolver resolver= getContextType().getResolver(type.getName());
          //                return resolver.createVariable();

          MultiVariable variable = new JavaVariable(type, name, offsets);
          fVariables.put(name, variable);
          return variable;
        }
      };
  TemplateBuffer buffer = translator.translate(template);

  getContextType().resolve(buffer, this);

  rewriteImports();

  //        IPreferenceStore prefs = JavaPlugin.getDefault().getPreferenceStore();
  boolean useCodeFormatter =
      true; // prefs.getBoolean(PreferenceConstants.TEMPLATES_USE_CODEFORMATTER);

  IJavaProject project = getJavaProject();
  JavaFormatter formatter =
      new JavaFormatter(
          TextUtilities.getDefaultLineDelimiter(getDocument()),
          getIndentation(),
          useCodeFormatter,
          project);
  formatter.format(buffer, this);

  clear();

  return buffer;
}