@Override public String getAdditionalProposalInfo() { try { fContext.setReadOnly(true); TemplateBuffer templateBuffer; try { templateBuffer= fContext.evaluate(fTemplate); } catch (TemplateException e) { return null; } return templateBuffer.getString(); } catch (BadLocationException e) { return null; } }
protected boolean validate(Template template, TemplateContext context) { try { context.getContextType().validate(template.getPattern()); } catch(TemplateException e) { return false; } return true; }
@Override protected String resolve(TemplateContext context) { String selection= context.getVariable(SELECTION); if (selection == null) return ""; //$NON-NLS-1$ return selection; }
@Override public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { ITextSelection selection= (ITextSelection) viewer.getSelectionProvider().getSelection(); // adjust offset to end of normalized selection 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<>(); for (Template template : templates) { try { context.getContextType().validate(template.getPattern()); } catch (TemplateException e) { continue; } if (template.matches(prefix, context.getContextType().getId())) matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix))); } Collections.sort(matches, fgProposalComparator); return matches.toArray(new ICompletionProposal[matches.size()]); }
/** * Returns template string to insert. * * @return String to insert or null if none is to be inserted */ String getTemplateString() { String templateString = null; Template template = getSelectedTemplate(); if (template != null) { TemplateContextType contextType = XMLUIPlugin.getDefault().getTemplateContextRegistry().getContextType(TemplateContextTypeIdsXML.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 xml", e); //$NON-NLS-1$ } } return templateString; }
public void createTemplates(ContentAssistContext context, ITemplateAcceptor acceptor) { if (!acceptor.canAcceptMoreTemplates()) return; TemplateContext[] templateContexts = createTemplateContexts(context); if (templateContexts == null || templateContexts.length == 0) return; ITemplateAcceptor nullSafe = new NullSafeTemplateAcceptor(acceptor); for(TemplateContext templateContext: templateContexts) { if (!nullSafe.canAcceptMoreTemplates()) return; templateContext.setVariable("selection", context.getSelectedText()); // name of the selection variables {line, word}_selection //$NON-NLS-1$ createTemplates(templateContext, context, nullSafe); } }
@Override public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { ITextSelection selection= (ITextSelection) viewer.getSelectionProvider().getSelection(); // adjust offset to end of normalized selection 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<>(); for (int i= 0; i < templates.length; i++) { Template template= templates[i]; try { context.getContextType().validate(template.getPattern()); } catch (TemplateException e) { continue; } if (template.matches(prefix, context.getContextType().getId())) matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix))); } Collections.sort(matches, fgProposalComparator); return matches.toArray(new ICompletionProposal[matches.size()]); }
templateBuffer = _context.evaluate(_template); variables = templateBuffer.getVariables();
@Override public String getAdditionalProposalInfo() { try { fContext.setReadOnly(true); TemplateBuffer templateBuffer; try { templateBuffer= fContext.evaluate(fTemplate); } catch (TemplateException e) { return null; } return templateBuffer.getString(); } catch (BadLocationException e) { return null; } }
context.setVariable("selection", selection.getText()); //$NON-NLS-1$ Template[] templates = getTemplates(context.getContextType().getId()); Template template = templates[i]; try { context.getContextType().validate(template.getPattern()); if (template.matches(prefix, context.getContextType().getId())) { matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
@Override protected String resolve(TemplateContext context) { String selection= context.getVariable(SELECTION); if (selection == null) return ""; //$NON-NLS-1$ return selection; }
private boolean canEvaluate(TemplateContext context, Template template) { String contextId= context.getContextType().getId(); Matcher wordSelectionMatcher= $_WORD_SELECTION_PATTERN.matcher(template.getPattern()); Matcher lineSelectionMatcher= $_LINE_SELECTION_PATTERN.matcher(template.getPattern()); if (JavaDocContextType.ID.equals(contextId)) { if (!template.matches("", contextId) || !lineSelectionMatcher.find() && !wordSelectionMatcher.find()) //$NON-NLS-1$ return false; } else { if (template.matches("", JavaDocContextType.ID) || !lineSelectionMatcher.find()) //$NON-NLS-1$ return false; } TemplateContextType contextType= JavaPlugin.getDefault().getTemplateContextRegistry().getContextType(template.getContextTypeId()); return contextType instanceof CompilationUnitContextType; }
@Override public String getAdditionalProposalInfo() { try { TemplateContext context = getContext(); context.setReadOnly(true); TemplateBuffer templateBuffer; try { Template template = getTemplate(); if (context instanceof XtextTemplateContext) { templateBuffer= ((XtextTemplateContext)context).evaluateForDisplay(template); } else { templateBuffer= context.evaluate(template); } } catch (TemplateException e) { return null; } return templateBuffer.getString(); } catch (BadLocationException e) { return null; } } }
context.setVariable("selection", selectionText); //$NON-NLS-1$ selectionContext.setVariable("selection", selectionText); //$NON-NLS-1$ context.setVariable("text", selectionText); //$NON-NLS-1$ selectionContext.setVariable("text", selectionText); //$NON-NLS-1$ Template[] templates = getTemplates(context.getContextType().getId()); context.getContextType().validate(template.getPattern()); } catch (TemplateException e) { continue; if (!template.matches(prefix, context.getContextType().getId())) { continue;
@Override protected String resolve(TemplateContext context) { return context.getVariable(getType()); } }
private boolean canEvaluate(TemplateContext context, Template template) { String contextId= context.getContextType().getId(); Matcher wordSelectionMatcher= $_WORD_SELECTION_PATTERN.matcher(template.getPattern()); Matcher lineSelectionMatcher= $_LINE_SELECTION_PATTERN.matcher(template.getPattern()); if (JavaDocContextType.ID.equals(contextId)) { if (!template.matches("", contextId) || !lineSelectionMatcher.find() && !wordSelectionMatcher.find()) //$NON-NLS-1$ return false; } else { if (template.matches("", JavaDocContextType.ID) || !lineSelectionMatcher.find()) //$NON-NLS-1$ return false; } TemplateContextType contextType= JavaPlugin.getDefault().getTemplateContextRegistry().getContextType(template.getContextTypeId()); return contextType instanceof CompilationUnitContextType; }
_context.setReadOnly(true); TemplateBuffer templateBuffer; try templateBuffer = _context.evaluate(_template);
context.setVariable("selection", selection.getText()); // name of the selection variables {line, word}_selection //$NON-NLS-1$ String contextTypeId = context.getContextType().getId(); boolean isTargetContextType = contextTypeId.equals(TargetContextType.TARGET_CONTEXT_TYPE); if (isTargetContextType) { Template template = templates[i]; try { context.getContextType().validate(template.getPattern());
@Override protected String resolve(TemplateContext context) { return context.getVariable(getType()); } }
@Override protected void createTemplates(TemplateContext templateContext, ContentAssistContext context, ITemplateAcceptor acceptor) { TemplateContextType contextType = templateContext.getContextType(); Template[] templates = templateStore.getTemplates(contextType.getId()); for (Template template : templates) { if (!acceptor.canAcceptMoreTemplates()) return; if (validate(template, templateContext)) { acceptor.accept(createProposal(template, templateContext, context, getImage(template), getRelevance(template))); } } }