Package org.eclipse.jface.text.templates

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


    if (selection.getOffset() == offset)
      offset= selection.getOffset() + selection.getLength();

    String prefix= extractPrefix(viewer, offset);
    Region region= new Region(offset - prefix.length(), prefix.length());
    TemplateContext context= createContext(viewer, region);
    if (context == null)
      return new ICompletionProposal[0];

    context.setVariable("selection", selection.getText()); // name of the selection variables {line, word}_selection //$NON-NLS-1$

    Template[] templates= getTemplates(context.getContextType().getId());

    List<ICompletionProposal> matches= new ArrayList<ICompletionProposal>();
    for (int i= 0; i < templates.length; i++) {
      Template template= templates[i];
      try {
        context.getContextType().validate(template.getPattern());
      } catch (TemplateException e) {
        continue;
      }
      if (template.getName().startsWith(prefix) &&
          template.matches(prefix, context.getContextType().getId()))
        matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
    }

    return matches.toArray(new ICompletionProposal[matches.size()]);
  }
View Full Code Here


                    "Cursor Position:    %d",
                    replacementString, replacementOffset, replacementLength, cursorPos);
        }

        IRegion region = ps.getRegion();
        TemplateContext context = createContext(edit.getPySourceViewer(), region, ps.getDoc());

        Template t = new Template("Convert", "% to .format()", "", replacementString, false);
        l.add(new TemplateProposal(t, context, region, imageCache.get(UIConstants.COMPLETION_TEMPLATE), 5));
        return l;
    }
View Full Code Here

        String surroundedCode = selectedText;
        surroundedCode = indentation + surroundedCode.replaceAll(delimiter, delimiter + indentation);

        //region
        IRegion region = ps.getRegion();
        TemplateContext context = null;
        if (edit != null) {
            context = createContext(edit.getPySourceViewer(), region, ps.getDoc());
        }

        //not static because we need the actual code.
View Full Code Here

     */
    private void fillWithEpydocFields(ITextViewer viewer, CompletionRequest request, ArrayList<ICompletionProposal> ret) {
        try {
            Region region = new Region(request.documentOffset - request.qlen, request.qlen);
            Image image = PyCodeCompletionImages.getImageForType(IToken.TYPE_EPYDOC);
            TemplateContext context = createContext(viewer, region, request.doc);

            char c = request.doc.getChar(request.documentOffset - request.qualifier.length() - 1);
            if (c == '@') {
                //ok, looking for epydoc filters
                for (int i = 0; i < EPYDOC_FIELDS.length; i++) {
View Full Code Here

    int length = selectionText.length() + prefix.length();
    Region region = new Region(offset, length);
    String templatePattern;
    Boolean hasSelectionVariable = false;
    IDocument doc = viewer.getDocument();
    TemplateContext context = createContext(viewer, region);
    if (context == null || doc.getLength() < 1)
      return new ICompletionProposal[0];

    Template[] templates = getTemplates(context.getContextType().getId());
    // TODO: move these variables to the CFTemplateContext class
    context.setVariable("selection", selectionText); // name of the selection variables {line, word}_selection //$NON-NLS-1$
    if(((ICFDocument)doc).getCFDocument() != null) {     
      context.setVariable("currentfile", ((ICFDocument)doc).getCFDocument().getFilename());
    }
    boolean inChevron = false;
    try {
      if (doc.getLength() > offset + 1 && (doc.getChar(offset - 1) == '<' || doc.getChar(offset + 1) == '>')) {
        inChevron = true;
      }
    } catch (BadLocationException e1) {
      e1.printStackTrace();
    }

    List matches = new ArrayList();
    for (int i = 0; i < templates.length; i++) {
      Template template = templates[i];
      hasSelectionVariable = false;
      try {
        templatePattern = template.getPattern();
        context.getContextType().validate(templatePattern);
        if((templatePattern.indexOf("${word_selection}") > 0 || templatePattern.indexOf("${line_selection}") > 0 )
          && selectionText.length() > 0){
          hasSelectionVariable = true;
        }
      } catch (TemplateException e) {
        continue;
      }
      relavance = getRelevance(template, prefix);
      if (template.matches(prefix, context.getContextType().getId()) && relavance > && selectionText.length() == 0 || hasSelectionVariable && template.matches("", context.getContextType().getId())) {
        if(inChevron && templatePattern.startsWith("<") && templatePattern.endsWith(">")){
          region = getRegionNoChevrons(doc, offset, length);
          context = createContext(viewer, region);
          context.setVariable("selection", selectionText);
        }
        matches.add(createProposal(template, context, (IRegion) region, relavance));
      }
    }
View Full Code Here

        if (!isValidPrefix(prefix)) {
            return new ICompletionProposal[0];
        }
        IRegion region = new Region(offset - prefix.length(), prefix.length());

        TemplateContext context = createContext(viewer, region);
        if (context == null) {
            return new ICompletionProposal[0];
        }
        List<TemplateProposal> matches = new ArrayList<TemplateProposal>();

        Template[] templates = getTemplates(context.getContextType().getId());
        for (int i = 0; i < templates.length; i++) {
            Template template = templates[i];
            try {
                context.getContextType().validate(template.getPattern());
            } catch (TemplateException e) {
                continue;
            }
            if (isMatchingTemplate(template, prefix, context))
                matches.add((TemplateProposal) createProposal(template,
View Full Code Here

TOP

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

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.