当前位置: 首页>>代码示例>>Java>>正文


Java DocumentTemplateContext类代码示例

本文整理汇总了Java中org.eclipse.jface.text.templates.DocumentTemplateContext的典型用法代码示例。如果您正苦于以下问题:Java DocumentTemplateContext类的具体用法?Java DocumentTemplateContext怎么用?Java DocumentTemplateContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DocumentTemplateContext类属于org.eclipse.jface.text.templates包,在下文中一共展示了DocumentTemplateContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isReplacedAreaEmpty

import org.eclipse.jface.text.templates.DocumentTemplateContext; //导入依赖的package包/类
private boolean isReplacedAreaEmpty(TemplateContext context) {
  // don't trim the buffer if the replacement area is empty
  // case: surrounding empty lines with block
  if (context instanceof DocumentTemplateContext) {
    DocumentTemplateContext dtc = (DocumentTemplateContext) context;
    if (dtc.getStart() == dtc.getCompletionOffset())
      try {
        IDocument document = dtc.getDocument();
        int lineOffset = document.getLineInformationOfOffset(dtc.getStart()).getOffset();
        // only if we are at the beginning of the line
        if (lineOffset != dtc.getStart()) return false;

        // Does the selection only contain whitespace characters?
        if (document.get(dtc.getStart(), dtc.getEnd() - dtc.getStart()).trim().length() == 0)
          return true;
      } catch (BadLocationException x) {
        // ignore - this may happen when the document was modified after the initial invocation,
        // and the
        // context does not track the changes properly - don't trim in that case
        return true;
      }
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:JavaFormatter.java

示例2: calculateValue

import org.eclipse.jface.text.templates.DocumentTemplateContext; //导入依赖的package包/类
@Override
int calculateValue(TemplateContext context) {
	String parseValue = null;
	if (this.isVariable) {
		parseValue = context.getVariable(this.value);
		if (parseValue == null) {
			String contextInfo = "";
			if (context instanceof DocumentTemplateContext) {
				contextInfo = ": '" + ((DocumentTemplateContext) context).getKey() + "'";
			}
			throw new VariableEvaluationException("Variable " + this.value + " is undefined in context"+ contextInfo);
		}
		parseValue = this.sign + parseValue;
	}
	else {
		parseValue = this.value;
	}
	try {
		return Integer.parseInt(parseValue);
	}
	catch (NumberFormatException ex) {
		throw new VariableEvaluationException(ex.getMessage(), ex);
	}
}
 
开发者ID:RichardBirenheide,项目名称:brainfuck,代码行数:25,代码来源:ExpressionEvaluator.java

示例3: applyTemplateAtTheEnd

import org.eclipse.jface.text.templates.DocumentTemplateContext; //导入依赖的package包/类
/**
 * @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();
	}
}
 
开发者ID:gama-platform,项目名称:gama,代码行数:23,代码来源:GamlEditor.java

示例4: isReplacedAreaEmpty

import org.eclipse.jface.text.templates.DocumentTemplateContext; //导入依赖的package包/类
private boolean isReplacedAreaEmpty(TemplateContext context) {
	// don't trim the buffer if the replacement area is empty
	// case: surrounding empty lines with block
	if (context instanceof DocumentTemplateContext) {
		DocumentTemplateContext dtc= (DocumentTemplateContext) context;
		if (dtc.getStart() == dtc.getCompletionOffset())
			try {
				IDocument document= dtc.getDocument();
				int lineOffset= document.getLineInformationOfOffset(dtc.getStart()).getOffset();
				//only if we are at the beginning of the line
				if (lineOffset != dtc.getStart())
					return false;

				//Does the selection only contain whitespace characters?
				if (document.get(dtc.getStart(), dtc.getEnd() - dtc.getStart()).trim().length() == 0)
					return true;
			} catch (BadLocationException x) {
				// ignore - this may happen when the document was modified after the initial invocation, and the
				// context does not track the changes properly - don't trim in that case
				return true;
			}
	}
	return false;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:JavaFormatter.java

示例5: getTemplateString

import org.eclipse.jface.text.templates.DocumentTemplateContext; //导入依赖的package包/类
/**
 * 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 = GlassmakerUIPlugin.getDefault().getTemplateContextRegistry().getContextType(CardContextType.CONTEXT_TYPE);
		IDocument document = new Document();
		TemplateContext context = new DocumentTemplateContext(contextType, document, 0, 0);
		try {
			TemplateBuffer buffer = context.evaluate(template);
			templateString = buffer.getString();
		}
		catch (Exception e) {
			GlassmakerUIPlugin.logError("Could not create template for new html", e); 
		}
	}

	return templateString;
}
 
开发者ID:eteration,项目名称:glassmaker,代码行数:25,代码来源:NewCardTemplatesWizardPage.java

示例6: getTemplateString

import org.eclipse.jface.text.templates.DocumentTemplateContext; //导入依赖的package包/类
/**
 * Returns template string to insert.
 * 
 * @return String to insert or null if none is to be inserted
 */
public String getTemplateString() {
    String templateString = null;

    Template template = getSelectedTemplate();
    if (template != null) {
        TemplateContextType contextType=SilverStripePDTPlugin.getDefault().getTemplateContextRegistry().getContextType(this._languageProvider.getTemplateContext());
        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 html", e); //$NON-NLS-1$
        }
    }

    return templateString;
}
 
开发者ID:UndefinedOffset,项目名称:eclipse-silverstripedt,代码行数:25,代码来源:NewSilverStripeTemplatesWizardPage.java

示例7: isReplacedAreaEmpty

import org.eclipse.jface.text.templates.DocumentTemplateContext; //导入依赖的package包/类
protected boolean isReplacedAreaEmpty(TemplateContext context) {
	// don't trim the buffer if the replacement area is empty
	// case: surrounding empty lines with block
	if (context instanceof DocumentTemplateContext) {
		DocumentTemplateContext dtc= (DocumentTemplateContext) context;
		if (dtc.getStart() == dtc.getCompletionOffset())
			try {
				IDocument document= dtc.getDocument();
				int lineOffset= document.getLineInformationOfOffset(dtc.getStart()).getOffset();
				//only if we are at the beginning of the line
				if (lineOffset != dtc.getStart())
					return false;

				//Does the selection only contain whitespace characters?
				if (document.get(dtc.getStart(), dtc.getEnd() - dtc.getStart()).trim().length() == 0)
					return true;
			} catch (BadLocationException x) {
				// ignore - this may happen when the document was modified after the initial invocation, and the
				// context does not track the changes properly - don't trim in that case
				return true;
			}
	}
	return false;
}
 
开发者ID:GoClipse,项目名称:goclipse,代码行数:25,代码来源:JavaFormatter.java

示例8: getReplaceOffset

import org.eclipse.jface.text.templates.DocumentTemplateContext; //导入依赖的package包/类
/**
 * Returns the offset of the range in the document that will be replaced by
 * applying this template.
 *
 * @return the offset of the range in the document that will be replaced by
 *         applying this template
 * @since 3.1
 */
protected final int getReplaceOffset() {
	int start;
	if (fContext instanceof DocumentTemplateContext) {
		DocumentTemplateContext docContext = (DocumentTemplateContext) fContext;
		start = docContext.getStart();
	} else {
		start = fRegion.getOffset();
	}
	return start;
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:19,代码来源:TweakedTemplateProposal.java

示例9: getReplaceEndOffset

import org.eclipse.jface.text.templates.DocumentTemplateContext; //导入依赖的package包/类
/**
 * Returns the end offset of the range in the document that will be replaced
 * by applying this template.
 *
 * @return the end offset of the range in the document that will be replaced
 *         by applying this template
 * @since 3.1
 */
protected final int getReplaceEndOffset() {
	int end;
	if (fContext instanceof DocumentTemplateContext) {
		DocumentTemplateContext docContext = (DocumentTemplateContext) fContext;
		end = docContext.getEnd();
	} else {
		end = fRegion.getOffset() + fRegion.getLength();
	}
	return end;
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:19,代码来源:TweakedTemplateProposal.java

示例10: computeRelevance

import org.eclipse.jface.text.templates.DocumentTemplateContext; //导入依赖的package包/类
/**
 * Computes the relevance to match the relevance values generated by the core content assistant.
 *
 * @return a sensible relevance value.
 */
private int computeRelevance() {
  // see org.eclipse.jdt.internal.codeassist.RelevanceConstants
  final int R_DEFAULT = 0;
  final int R_INTERESTING = 5;
  final int R_CASE = 10;
  final int R_NON_RESTRICTED = 3;
  final int R_EXACT_NAME = 4;
  final int R_INLINE_TAG = 31;

  int base = R_DEFAULT + R_INTERESTING + R_NON_RESTRICTED;

  try {
    if (fContext instanceof DocumentTemplateContext) {
      DocumentTemplateContext templateContext = (DocumentTemplateContext) fContext;
      IDocument document = templateContext.getDocument();

      String content = document.get(fRegion.getOffset(), fRegion.getLength());
      if (content.length() > 0 && fTemplate.getName().startsWith(content)) base += R_CASE;
      if (fTemplate.getName().equalsIgnoreCase(content)) base += R_EXACT_NAME;
      if (fContext instanceof JavaDocContext) base += R_INLINE_TAG;
    }
  } catch (BadLocationException e) {
    // ignore - not a case sensitive match then
  }

  // see CompletionProposalCollector.computeRelevance
  // just under keywords, but better than packages
  final int TEMPLATE_RELEVANCE = 1;
  return base * 16 + TEMPLATE_RELEVANCE;
}
 
开发者ID:eclipse,项目名称:che,代码行数:36,代码来源:TemplateProposal.java

示例11: getReplaceOffset

import org.eclipse.jface.text.templates.DocumentTemplateContext; //导入依赖的package包/类
/**
 * Returns the offset of the range in the document that will be replaced by applying this
 * template.
 *
 * @return the offset of the range in the document that will be replaced by applying this template
 */
protected final int getReplaceOffset() {
  int start;
  if (fContext instanceof DocumentTemplateContext) {
    DocumentTemplateContext docContext = (DocumentTemplateContext) fContext;
    start = docContext.getStart();
  } else {
    start = fRegion.getOffset();
  }
  return start;
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:TemplateProposal.java

示例12: getReplaceEndOffset

import org.eclipse.jface.text.templates.DocumentTemplateContext; //导入依赖的package包/类
/**
 * Returns the end offset of the range in the document that will be replaced by applying this
 * template.
 *
 * @return the end offset of the range in the document that will be replaced by applying this
 *     template
 */
protected final int getReplaceEndOffset() {
  int end;
  if (fContext instanceof DocumentTemplateContext) {
    DocumentTemplateContext docContext = (DocumentTemplateContext) fContext;
    end = docContext.getEnd();
  } else {
    end = fRegion.getOffset() + fRegion.getLength();
  }
  return end;
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:TemplateProposal.java

示例13: isSelectionTemplate

import org.eclipse.jface.text.templates.DocumentTemplateContext; //导入依赖的package包/类
/**
 * Returns <code>true</code> if the proposal has a selection, e.g. will wrap some code.
 *
 * @return <code>true</code> if the proposals completion length is non zero
 * @since 3.2
 */
private boolean isSelectionTemplate() {
  if (fContext instanceof DocumentTemplateContext) {
    DocumentTemplateContext ctx = (DocumentTemplateContext) fContext;
    if (ctx.getCompletionLength() > 0) return true;
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:14,代码来源:TemplateProposal.java

示例14: createProposal

import org.eclipse.jface.text.templates.DocumentTemplateContext; //导入依赖的package包/类
@Override
protected ICompletionProposal createProposal(Template template, TemplateContext context, IRegion region,
		int relevance) {
       if (context instanceof DocumentTemplateContext) {
           context = new SwaggerTemplateContext((DocumentTemplateContext) context);
       }
	return new StyledTemplateProposal(template, context, region, getImage(template), getTemplateLabel(template),
			relevance);
}
 
开发者ID:RepreZen,项目名称:KaiZen-OpenAPI-Editor,代码行数:10,代码来源:JsonContentAssistProcessor.java

示例15: resolve

import org.eclipse.jface.text.templates.DocumentTemplateContext; //导入依赖的package包/类
@Override
protected String resolve(TemplateContext context) {
	if (context instanceof DocumentTemplateContext) {
		return ((DocumentTemplateContext) context).getKey();
	}
	return null;
}
 
开发者ID:RichardBirenheide,项目名称:brainfuck,代码行数:8,代码来源:BfKeyResolver.java


注:本文中的org.eclipse.jface.text.templates.DocumentTemplateContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。