本文整理汇总了Java中org.eclipse.jface.text.templates.TemplateContext类的典型用法代码示例。如果您正苦于以下问题:Java TemplateContext类的具体用法?Java TemplateContext怎么用?Java TemplateContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TemplateContext类属于org.eclipse.jface.text.templates包,在下文中一共展示了TemplateContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TweakedTemplateProposal
import org.eclipse.jface.text.templates.TemplateContext; //导入依赖的package包/类
/**
* Creates a template proposal with a template and its context.
*
* @param template
* the template
* @param context
* the context in which the template was requested.
* @param image
* the icon of the proposal.
* @param region
* the region this proposal is applied to
* @param relevance
* the relevance of the proposal
*/
public TweakedTemplateProposal(Template template, TemplateContext context, IRegion region, Image image,
int relevance) {
Assert.isNotNull(template);
Assert.isNotNull(context);
Assert.isNotNull(region);
fTemplate = template;
Check.isTrue(context instanceof FtcDocumentTemplateContext);
fContext = (FtcDocumentTemplateContext) context;
fImage = image;
fRegion = region;
fDisplayString = null;
fRelevance = relevance;
}
示例2: resolveAll
import org.eclipse.jface.text.templates.TemplateContext; //导入依赖的package包/类
@Override
protected String[] resolveAll(TemplateContext context) {
Check.isTrue(context instanceof FtcDocumentTemplateContext);
FtcDocumentTemplateContext ftcContext = (FtcDocumentTemplateContext) context;
String pattern = ftcContext.getCurrentTemplate().getPattern();
Check.notNull(pattern);
String currentText = ftcContext.getDocument().get();
ICompletionProposal[] proposals = createCompletionProposals(ftcContext.getCompletionOffset(), getType(),
pattern, currentText);
String[] result = new String[proposals.length];
for (int i = 0; i < proposals.length; i++)
result[i] = proposals[i].getDisplayString();
return result;
}
示例3: createTemplates
import org.eclipse.jface.text.templates.TemplateContext; //导入依赖的package包/类
@Override
protected void createTemplates(final TemplateContext templateContext, final ContentAssistContext context, final ITemplateAcceptor acceptor) {
if (templateContext.getContextType().getId().equals("com.avaloq.tools.ddk.checkcfg.CheckCfg.ConfiguredCheck")) { //$NON-NLS-1$
addConfiguredCheckTemplates(templateContext, context, acceptor);
return;
} else if (templateContext.getContextType().getId().equals("com.avaloq.tools.ddk.checkcfg.CheckCfg.kw_catalog")) { //$NON-NLS-1$
addCatalogConfigurations(templateContext, context, 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)));
}
}
}
示例4: resolve
import org.eclipse.jface.text.templates.TemplateContext; //导入依赖的package包/类
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
variable.setUnambiguous(true);
variable.setValue(""); // $NON-NLS-1$
if (context instanceof JavaContext) {
JavaContext jc = (JavaContext) context;
List<String> params = variable.getVariableType().getParams();
if (params.size() > 0) {
for (Iterator<String> iterator = params.iterator(); iterator.hasNext(); ) {
String typeName = iterator.next();
jc.addImport(typeName);
}
}
} else {
super.resolve(variable, context);
}
}
示例5: resolve
import org.eclipse.jface.text.templates.TemplateContext; //导入依赖的package包/类
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
variable.setUnambiguous(true);
variable.setValue(""); // $NON-NLS-1$
if (context instanceof JavaContext) {
JavaContext jc = (JavaContext) context;
List<String> params = variable.getVariableType().getParams();
if (params.size() > 0) {
for (Iterator<String> iterator = params.iterator(); iterator.hasNext(); ) {
String qualifiedMemberName = iterator.next();
jc.addStaticImport(qualifiedMemberName);
}
}
} else {
super.resolve(variable, context);
}
}
示例6: resolve
import org.eclipse.jface.text.templates.TemplateContext; //导入依赖的package包/类
@Override
protected String resolve(TemplateContext context) {
IJavaElement element =
((CompilationUnitContext) context).findEnclosingElement(IJavaElement.METHOD);
if (element == null) return null;
IMethod method = (IMethod) element;
try {
String[] arguments = method.getParameterNames();
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < arguments.length; i++) {
if (i > 0) buffer.append(", "); // $NON-NLS-1$
buffer.append(arguments[i]);
}
return buffer.toString();
} catch (JavaModelException e) {
return null;
}
}
示例7: format
import org.eclipse.jface.text.templates.TemplateContext; //导入依赖的package包/类
/**
* Formats the template buffer.
*
* @param buffer
* @param context
* @throws BadLocationException
*/
public void format(TemplateBuffer buffer, TemplateContext context) throws BadLocationException {
try {
VariableTracker tracker = new VariableTracker(buffer);
IDocument document = tracker.getDocument();
internalFormat(document, context);
convertLineDelimiters(document);
if (!(context instanceof JavaDocContext) && !isReplacedAreaEmpty(context))
trimStart(document);
tracker.updateBuffer();
} catch (MalformedTreeException e) {
throw new BadLocationException();
}
}
示例8: isReplacedAreaEmpty
import org.eclipse.jface.text.templates.TemplateContext; //导入依赖的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;
}
示例9: resolve
import org.eclipse.jface.text.templates.TemplateContext; //导入依赖的package包/类
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
if (!(variable instanceof MultiVariable)) {
super.resolve(variable, context);
return;
}
MultiVariable mv = (MultiVariable) variable;
List<String> params = variable.getVariableType().getParams();
if (params.isEmpty()) {
super.resolve(variable, context);
return;
}
JavaContext jc = (JavaContext) context;
String reference = params.get(0);
TemplateVariable refVar = jc.getTemplateVariable(reference);
if (refVar instanceof JavaVariable) {
JavaVariable jvar = (JavaVariable) refVar;
resolve(mv, jvar, jc);
return;
}
super.resolve(variable, context);
}
示例10: resolve
import org.eclipse.jface.text.templates.TemplateContext; //导入依赖的package包/类
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
if (variable instanceof MultiVariable) {
JavaContext jc = (JavaContext) context;
JavaVariable jv = (JavaVariable) variable;
Variable[] iterables = getVariables(jc);
if (iterables.length > 0) {
jv.setChoices(iterables);
jc.markAsUsed(iterables[0].getName());
if (iterables.length > 1) variable.setUnambiguous(false);
else variable.setUnambiguous(isUnambiguous(context));
return;
}
}
super.resolve(variable, context);
}
示例11: createContext
import org.eclipse.jface.text.templates.TemplateContext; //导入依赖的package包/类
@Override
protected TemplateContext createContext(ITextViewer viewer, IRegion region) {
TemplateContext context = null;
TemplateContextType contextType= getContextType(viewer, region);
if (contextType != null) {
IDocument document= viewer.getDocument();
context = new BfTemplateContext(contextType, document, region.getOffset(), region.getLength());
}
if (context == null) {
return null;
}
try {
String prefix = viewer.getDocument().get(region.getOffset(), region.getLength());
int i = 0;
for (String param : parseParameters(prefix)) {
context.setVariable("x" + (i++), param);
}
}
catch (BadLocationException ex) {
BfActivator.getDefault().logError("Prefix for Template could not be computed", ex);
}
return context;
}
示例12: calculateValue
import org.eclipse.jface.text.templates.TemplateContext; //导入依赖的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);
}
}
示例13: resolve
import org.eclipse.jface.text.templates.TemplateContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void resolve(TemplateVariable variable, TemplateContext context)
{
if (!variable.getVariableType().getParams().isEmpty())
{
String[] values = (String[]) variable.getVariableType().getParams().toArray(new String[0]);
variable.setValues(values);
variable.setUnambiguous(false);
variable.setResolved(true);
}
else
{
super.resolve(variable, context);
setEvaluationString(variable.getName());
}
}
示例14: insertAsTemplate
import org.eclipse.jface.text.templates.TemplateContext; //导入依赖的package包/类
public static void insertAsTemplate(ITextViewer textViewer, final IRegion region, String templateText,
CommandElement commandElement)
{
SnippetsCompletionProcessor snippetsCompletionProcessor = new SnippetsCompletionProcessor();
Template template = new SnippetTemplate(commandElement, templateText);
TemplateContext context = snippetsCompletionProcessor.createContext(textViewer, region);
SnippetTemplateProposal completionProposal = (SnippetTemplateProposal) snippetsCompletionProcessor
.createProposal(template, context, region, 0);
completionProposal.setTemplateProposals(new ICompletionProposal[] { completionProposal });
completionProposal.apply(textViewer, '0', SWT.NONE, region.getOffset());
Point selection = completionProposal.getSelection(textViewer.getDocument());
if (selection != null)
{
textViewer.setSelectedRange(selection.x, selection.y);
textViewer.revealRange(selection.x, selection.y);
}
}
示例15: resolve
import org.eclipse.jface.text.templates.TemplateContext; //导入依赖的package包/类
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
List<String> params= variable.getVariableType().getParams();
String param;
if (params.size() == 0)
param= fDefaultType;
else
param= params.get(0);
JavaContext jc= (JavaContext) context;
MultiVariable mv= (MultiVariable) variable;
String reference= jc.addImport(param);
mv.setValue(reference);
mv.setUnambiguous(true);
}