Java 类org.eclipse.xtext.ui.editor.templates.XtextTemplateContextType 实例源码

项目:gama    文件:GamlEditor.java   
/**
 * @see msi.gama.lang.gaml.ui.editor.IGamlEditor#applyTemplate(org.eclipse.jface.text.templates.Template)
 */

public void applyTemplateAtTheEnd(final Template t) {

    try {
        final IDocument doc = getDocument();
        int offset = doc.getLineOffset(doc.getNumberOfLines() - 1);
        doc.replace(offset, 0, "\n\n");
        offset += 2;
        final int length = 0;
        final Position pos = new Position(offset, length);
        final XtextTemplateContextType ct = new XtextTemplateContextType();
        final DocumentTemplateContext dtc = new DocumentTemplateContext(ct, doc, pos);
        final IRegion r = new Region(offset, length);
        final TemplateProposal tp = new TemplateProposal(t, dtc, r, null);
        tp.apply(getInternalSourceViewer(), (char) 0, 0, offset);
    } catch (final BadLocationException e) {
        e.printStackTrace();
    }
}
项目:gama    文件:GamlEditor.java   
public void applyTemplate(final Template t) {
    // TODO Create a specific context type (with GAML specific variables ??)
    final XtextTemplateContextType ct = new XtextTemplateContextType();
    final IDocument doc = getDocument();
    final ITextSelection selection = (ITextSelection) getSelectionProvider().getSelection();
    final int offset = selection.getOffset();
    final int length = selection.getLength();
    final Position pos = new Position(offset, length);
    final DocumentTemplateContext dtc = new DocumentTemplateContext(ct, doc, pos);
    final IRegion r = new Region(offset, length);
    final TemplateProposal tp = new TemplateProposal(t, dtc, r, null);
    tp.apply(getInternalSourceViewer(), (char) 0, 0, offset);
}
项目:sadlos2    文件:TemplateQuickAssistProcessor.java   
protected ICompletionProposal createTemplateProposal(
        TemplateIssueResolution res) {
    try {
        TemplateContextSupplier fac = res.getContextFactory();
        IDocument doc = XtextDocumentUtil.get(qaCtx.getSourceViewer());
        Position pos = fac.getPosition(doc, qaCtx);
        String prefix = fac.getPrefix(doc, qaCtx);
        String postfix = fac.getPostfix(doc, qaCtx);
        Map<String, String> vars = fac.getVariables(doc, qaCtx);
        Region r = new Region(pos.getOffset(), pos.getLength());
        ContentAssistContext cactx = builderProvider.get()
                .setOffset(pos.getOffset()).setPrefix(prefix)
                .setViewer(qaCtx.getSourceViewer()).toContext();

        // create a TemplateProposalContext
        Image i = ((DefaultTemplateProposalProvider) templatePP)
                .getImage(res.getTemplate());
        XtextTemplateContextType type = templateCtxTypeProvider.get();
        XtextTemplateContext tplctx = new QuickfixTemplateContext(type,
                doc, pos, cactx, scopeProvider, prefix, postfix);
        for (Map.Entry<String, String> e : vars.entrySet())
            tplctx.setVariable(e.getKey(), e.getValue());

        // create a TemplateProposal
        XtextTemplateProposal proposal = new XtextTemplateProposal(
                res.getTemplate(), tplctx, r, i);
        return proposal;
    } catch (RuntimeException e1) {
        throw e1;
    } catch (Exception e2) {
        throw new WrappedException(e2);
    }
}
项目:dsl-devkit    文件:CheckUiModule.java   
@Override
public Class<? extends XtextTemplateContextType> bindXtextTemplateContextType() {
  return CheckTemplateContextType.class;
}
项目:sadlos2    文件:SadlUiModule.java   
public Class<? extends XtextTemplateContextType> bindTemplateContextType() {
    return SadlTemplateContextType.class;
}
项目:DialogScriptDSL    文件:TerminalRuleAwareTemplateContextTypeRegistry.java   
@Inject
public TerminalRuleAwareTemplateContextTypeRegistry(final IGrammarAccess grammarAccess, final Provider<XtextTemplateContextType> ctxTypeProvider, final ContextTypeIdHelper helper) {
  super(grammarAccess, ctxTypeProvider, helper);
}