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

项目: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;
}
项目:typescript.java    文件:CodeTemplateSourceViewerConfiguration.java   
public String getHoverInfo(ITextViewer textViewer, IRegion subject) {
    try {
        IDocument doc= textViewer.getDocument();
        int offset= subject.getOffset();
        if (offset >= 2 && "${".equals(doc.get(offset-2, 2))) { //$NON-NLS-1$
            String varName= doc.get(offset, subject.getLength());
            TemplateContextType contextType= fProcessor.getContextType();
            if (contextType != null) {
                Iterator iter= contextType.resolvers();
                while (iter.hasNext()) {
                    TemplateVariableResolver var= (TemplateVariableResolver) iter.next();
                    if (varName.equals(var.getType())) {
                        return var.getDescription();
                    }
                }
            }
        }               
    } catch (BadLocationException e) {
    }
    return null;
}
项目: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    文件:ContributionContextTypeRegistry.java   
/**
 * Tries to create a context type given an id. Contributions to the <code>
 * org.eclipse.ui.editors.templates</code> extension point are searched for the given identifier
 * and the specified context type instantiated if it is found. Any contributed {@link
 * org.eclipse.jface.text.templates.TemplateVariableResolver}s are also instantiated and added to
 * the context type.
 *
 * @param id the id for the context type as specified in XML
 * @return the instantiated and configured context type, or <code>null</code> if it is not found
 *     or cannot be instantiated
 */
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) {
    JavaPlugin.log(e);
    type = null;
  }

  return type;
}
项目:che    文件:ContributionContextTypeRegistry.java   
/**
 * Instantiates the resolvers contributed to the context type with id <code>contextTypeId</code>.
 * If instantiation of one resolver fails, the exception are logged and operation continues.
 *
 * @param extensions the configuration elements to parse
 * @param contextTypeId the id of the context type for which resolvers are instantiated
 * @return the instantiated resolvers
 */
private static TemplateVariableResolver[] createResolvers(
    IConfigurationElement[] extensions, String contextTypeId) {
  List resolvers = new ArrayList();
  for (int i = 0; i < extensions.length; i++) {
    if (extensions[i].getName().equals(RESOLVER)) {
      String declaredId = extensions[i].getAttribute(CONTEXT_TYPE_ID);
      if (contextTypeId.equals(declaredId)) {
        try {
          TemplateVariableResolver resolver = createResolver(extensions[i]);
          if (resolver != null) resolvers.add(resolver);
        } catch (CoreException e) {
          JavaPlugin.log(e);
        }
      }
    }
  }

  return (TemplateVariableResolver[])
      resolvers.toArray(new TemplateVariableResolver[resolvers.size()]);
}
项目: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    文件:CodeTemplateSourceViewerConfiguration.java   
public String getHoverInfo(ITextViewer textViewer, IRegion subject) {
    try {
        IDocument doc= textViewer.getDocument();
        int offset= subject.getOffset();
        if (offset >= 2 && "${".equals(doc.get(offset-2, 2))) { //$NON-NLS-1$
            String varName= doc.get(offset, subject.getLength());
            TemplateContextType contextType= fProcessor.getContextType();
            if (contextType != null) {
                Iterator<TemplateVariableResolver> iter= contextType.resolvers();
                while (iter.hasNext()) {
                    TemplateVariableResolver var= iter.next();
                    if (varName.equals(var.getType())) {
                        return var.getDescription();
                    }
                }
            }
        }
    } catch (BadLocationException e) {
    }
    return null;
}
项目: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    文件:CodeTemplateSourceViewerConfiguration.java   
public String getHoverInfo(ITextViewer textViewer, IRegion subject) {
    try {
        IDocument doc= textViewer.getDocument();
        int offset= subject.getOffset();
        if (offset >= 2 && "${".equals(doc.get(offset-2, 2))) { //$NON-NLS-1$
            String varName= doc.get(offset, subject.getLength());
            TemplateContextType contextType= fProcessor.getContextType();
            if (contextType != null) {
                Iterator<TemplateVariableResolver> iter= contextType.resolvers();
                while (iter.hasNext()) {
                    TemplateVariableResolver var= iter.next();
                    if (varName.equals(var.getType())) {
                        return var.getDescription();
                    }
                }
            }
        }
    } catch (BadLocationException e) {
    }
    return null;
}
项目:che    文件:ContributionContextTypeRegistry.java   
private static TemplateVariableResolver createResolver(IConfigurationElement element)
    throws CoreException {
  try {
    String type = element.getAttribute(TYPE);
    if (type != null) {

      TemplateVariableResolver resolver =
          (TemplateVariableResolver) element.createExecutableExtension(CLASS);
      resolver.setType(type);

      String desc = element.getAttribute(DESCRIPTION);
      resolver.setDescription(desc == null ? "" : desc); // $NON-NLS-1$

      return resolver;
    }
  } catch (ClassCastException e) {
    throw new CoreException(
        new Status(
            IStatus.ERROR,
            "org.eclipse.ui.editors",
            IStatus.OK,
            "extension does not implement " + TemplateVariableResolver.class.getName(),
            e)); // $NON-NLS-1$
  }

  return null;
}
项目:brainfuck    文件:BfTemplateType.java   
@Override
protected void validateVariables(TemplateVariable[] variables)
        throws TemplateException {
    for (TemplateVariable variable : variables) {
        TemplateVariableResolver resolver = this.getResolver(variable.getType());
        if (resolver != null && (resolver instanceof ExpressionEvaluator)) {
            @SuppressWarnings("unchecked")
            List<String> params = (variable.getVariableType().getParams());
            ((ExpressionEvaluator) resolver).supportsParameters(params);
        }
    }
}
项目:eclipse-templatevariables    文件:TemplateVariablesStartup.java   
/**
 * This method adds the given {@link TemplateVariableResolver} to each registered
 * {@link TemplateContextType}.
 * 
 * @param javaPlugin is the {@link JavaPlugin}.
 * @param resolver is the {@link TemplateVariableResolver} to add.
 */
@SuppressWarnings({ "rawtypes" })
private void addResolver(JavaPlugin javaPlugin, TemplateVariableResolver resolver) {

  Assert.isNotNull(javaPlugin);
  Assert.isNotNull(resolver);
  ContextTypeRegistry codeTemplateContextRegistry = javaPlugin.getCodeTemplateContextRegistry();
  Assert.isNotNull(codeTemplateContextRegistry);
  Iterator ctIter = codeTemplateContextRegistry.contextTypes();
  while (ctIter.hasNext()) {
    TemplateContextType contextType = (TemplateContextType) ctIter.next();
    contextType.addResolver(resolver);
  }
}
项目:eclipse-templatevariables    文件:TemplateVariablesStartup.java   
/**
 * This method removes the given {@link TemplateVariableResolver} to each registered
 * {@link TemplateContextType}.
 * 
 * @param javaPlugin is the {@link JavaPlugin}.
 * @param resolver is the {@link TemplateVariableResolver} to remove.
 */
@SuppressWarnings({ "rawtypes" })
private void removeResolver(JavaPlugin javaPlugin, TemplateVariableResolver resolver) {

  Assert.isNotNull(javaPlugin);
  Assert.isNotNull(resolver);
  ContextTypeRegistry codeTemplateContextRegistry = javaPlugin.getCodeTemplateContextRegistry();
  Assert.isNotNull(codeTemplateContextRegistry);
  Iterator ctIter = codeTemplateContextRegistry.contextTypes();
  while (ctIter.hasNext()) {
    TemplateContextType contextType = (TemplateContextType) ctIter.next();
    contextType.removeResolver(resolver);
  }
}
项目:Eclipse-Postfix-Code-Completion    文件:TemplateVariableProcessor.java   
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {

        if (fContextType == null)
            return null;

        List<TemplateVariableProposal> proposals= new ArrayList<TemplateVariableProposal>();

        String text= viewer.getDocument().get();
        int start= getStart(text, documentOffset);
        int end= documentOffset;

        String string= text.substring(start, end);
        int colon= string.indexOf(':');
        boolean includeBrace= true;
        int offset= start;
        String prefix= string;
        if (colon != -1) {
            includeBrace= false;
            offset= start + colon + 1;
            prefix= string.substring(colon + 1);
        } else {
            int escape= string.indexOf("${"); //$NON-NLS-1$
            if (escape != -1) {
                offset= start + escape + 2;
                includeBrace= false;
                prefix= string.substring(escape + 2);
            }
        }
        if (prefix.equals("$")) //$NON-NLS-1$
            prefix= ""; //$NON-NLS-1$

        int length= end - offset;

        for (Iterator<TemplateVariableResolver> iterator= fContextType.resolvers(); iterator.hasNext(); ) {
            TemplateVariableResolver variable= iterator.next();

            if (variable.getType().startsWith(prefix))
                proposals.add(new TemplateVariableProposal(variable, offset, length, viewer, includeBrace));
        }

        Collections.sort(proposals, fgTemplateVariableProposalComparator);
        return proposals.toArray(new ICompletionProposal[proposals.size()]);
    }
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:TemplateVariableProcessor.java   
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {

        if (fContextType == null)
            return null;

        List<TemplateVariableProposal> proposals= new ArrayList<TemplateVariableProposal>();

        String text= viewer.getDocument().get();
        int start= getStart(text, documentOffset);
        int end= documentOffset;

        String string= text.substring(start, end);
        int colon= string.indexOf(':');
        boolean includeBrace= true;
        int offset= start;
        String prefix= string;
        if (colon != -1) {
            includeBrace= false;
            offset= start + colon + 1;
            prefix= string.substring(colon + 1);
        } else {
            int escape= string.indexOf("${"); //$NON-NLS-1$
            if (escape != -1) {
                offset= start + escape + 2;
                includeBrace= false;
                prefix= string.substring(escape + 2);
            }
        }
        if (prefix.equals("$")) //$NON-NLS-1$
            prefix= ""; //$NON-NLS-1$

        int length= end - offset;

        for (Iterator<TemplateVariableResolver> iterator= fContextType.resolvers(); iterator.hasNext(); ) {
            TemplateVariableResolver variable= iterator.next();

            if (variable.getType().startsWith(prefix))
                proposals.add(new TemplateVariableProposal(variable, offset, length, viewer, includeBrace));
        }

        Collections.sort(proposals, fgTemplateVariableProposalComparator);
        return proposals.toArray(new ICompletionProposal[proposals.size()]);
    }
项目:bts    文件:TemplateVariableProposal.java   
/**
 * Creates a template variable proposal.
 *
 * @param variable the template variable
 * @param offset the offset to replace
 * @param length the length to replace
 * @param viewer the viewer
 */
public TemplateVariableProposal(TemplateVariableResolver variable, int offset, int length, ITextViewer viewer) {
    fVariable= variable;
    fOffset= offset;
    fLength= length;
    fViewer= viewer;
}
项目:che    文件:JavaPlugin.java   
/**
 * Registers the given Java template context.
 *
 * @param registry the template context type registry
 * @param id the context type id
 * @param parent the parent context type
 * @since 3.4
 */
private static void registerJavaContext(
    ContributionContextTypeRegistry registry, String id, TemplateContextType parent) {
  TemplateContextType contextType = registry.getContextType(id);
  Iterator<TemplateVariableResolver> iter = parent.resolvers();
  while (iter.hasNext()) contextType.addResolver(iter.next());
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaPlugin.java   
/**
 * Registers the given Java template context.
 *
 * @param registry the template context type registry
 * @param id the context type id
 * @param parent the parent context type
 * @since 3.4
 */
private static void registerJavaContext(ContributionContextTypeRegistry registry, String id, TemplateContextType parent) {
    TemplateContextType contextType= registry.getContextType(id);
    Iterator<TemplateVariableResolver> iter= parent.resolvers();
    while (iter.hasNext())
        contextType.addResolver(iter.next());
}
项目:Eclipse-Postfix-Code-Completion    文件:TemplateVariableProposal.java   
/**
 * Creates a template variable proposal.
 *
 * @param variable the template variable
 * @param offset the offset to replace
 * @param length the length to replace
 * @param viewer the viewer
 * @param includeBrace whether to also replace the ${
 */
public TemplateVariableProposal(TemplateVariableResolver variable, int offset, int length, ITextViewer viewer, boolean includeBrace) {
    fResolver= variable;
    fOffset= offset;
    fLength= length;
    fViewer= viewer;
    fIncludeBrace= includeBrace;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaPlugin.java   
/**
 * Registers the given Java template context.
 *
 * @param registry the template context type registry
 * @param id the context type id
 * @param parent the parent context type
 * @since 3.4
 */
private static void registerJavaContext(ContributionContextTypeRegistry registry, String id, TemplateContextType parent) {
    TemplateContextType contextType= registry.getContextType(id);
    Iterator<TemplateVariableResolver> iter= parent.resolvers();
    while (iter.hasNext())
        contextType.addResolver(iter.next());
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:TemplateVariableProposal.java   
/**
 * Creates a template variable proposal.
 *
 * @param variable the template variable
 * @param offset the offset to replace
 * @param length the length to replace
 * @param viewer the viewer
 * @param includeBrace whether to also replace the ${
 */
public TemplateVariableProposal(TemplateVariableResolver variable, int offset, int length, ITextViewer viewer, boolean includeBrace) {
    fResolver= variable;
    fOffset= offset;
    fLength= length;
    fViewer= viewer;
    fIncludeBrace= includeBrace;
}
项目:eclipsensis    文件:NSISTemplateVariableProposal.java   
/**
 * Creates a template variable proposal.
 *
 * @param variable the template variable
 * @param offset the offset to replace
 * @param length the length to replace
 * @param viewer the viewer
 */
public NSISTemplateVariableProposal(TemplateVariableResolver variable, int offset, int length, ITextViewer viewer) {
    mResolver= variable;
    mOffset= offset;
    mLength= length;
    mViewer= viewer;
}