本文整理汇总了Java中org.eclipse.jface.text.templates.Template.matches方法的典型用法代码示例。如果您正苦于以下问题:Java Template.matches方法的具体用法?Java Template.matches怎么用?Java Template.matches使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jface.text.templates.Template
的用法示例。
在下文中一共展示了Template.matches方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeCompletionProposals
import org.eclipse.jface.text.templates.Template; //导入方法依赖的package包/类
@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 (!prefix.equals("") && prefix.charAt(0) == '<') { //$NON-NLS-1$
prefix = prefix.substring(1);
}
if (!prefix.equals("") //$NON-NLS-1$
&& (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()]);
}
示例2: computeCompletionProposals
import org.eclipse.jface.text.templates.Template; //导入方法依赖的package包/类
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 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 (ICompletionProposal[]) matches.toArray(new ICompletionProposal[matches.size()]);
}
示例3: canEvaluate
import org.eclipse.jface.text.templates.Template; //导入方法依赖的package包/类
@Override
public boolean canEvaluate(Template template) {
if (fForceEvaluation)
return true;
String key = getKey();
return template.matches(key, getContextType().getId()) && key.length() != 0
&& template.getName().toLowerCase().startsWith(key.toLowerCase());
}
示例4: hasCompatibleContextType
import org.eclipse.jface.text.templates.Template; //导入方法依赖的package包/类
private boolean hasCompatibleContextType(Template template) {
String key = getKey();
if (template.matches(key, getContextType().getId())) return true;
if (fCompatibleContextTypeIds == null) return false;
Iterator<String> iter = fCompatibleContextTypeIds.iterator();
while (iter.hasNext()) {
if (template.matches(key, iter.next())) return true;
}
return false;
}
示例5: canEvaluate
import org.eclipse.jface.text.templates.Template; //导入方法依赖的package包/类
@Override
public boolean canEvaluate(Template template) {
String key = getKey();
if (fForceEvaluation) return true;
return template.matches(key, getContextType().getId())
&& (key.length() != 0)
&& template.getName().toLowerCase().startsWith(key.toLowerCase());
}
示例6: computeCompletionProposals
import org.eclipse.jface.text.templates.Template; //导入方法依赖的package包/类
/**
* Override improves matching accuracy
*/
@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];
}
Region selectionRegion = new Region(selection.getOffset(), selection.getLength());
TemplateContext selectionContext = createContext(viewer, selectionRegion);
int lineOffset = 0;
try {
IRegion lineInformationOfOffset = viewer.getDocument().getLineInformationOfOffset(offset);
lineOffset = offset - lineInformationOfOffset.getOffset();
} catch (BadLocationException e1) {}
String selectionText = selection.getText();
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());
List<ICompletionProposal> matches = new ArrayList<ICompletionProposal>(templates.length);
for (Template template : templates) {
try {
context.getContextType().validate(template.getPattern());
} catch (TemplateException e) {
continue;
}
if (!template.matches(prefix, context.getContextType().getId())) {
continue;
}
boolean selectionBasedMatch = isSelectionBasedMatch(template, context);
if (template.getName().startsWith(prefix) || selectionBasedMatch) {
int relevance = getRelevance(template, lineOffset, prefix);
if (selectionBasedMatch) {
matches.add(createProposal(template, selectionContext, (IRegion) selectionRegion, relevance));
} else {
matches.add(createProposal(template, context, (IRegion) region, relevance));
}
}
}
Collections.sort(matches, proposalComparator);
return matches.toArray(new ICompletionProposal[matches.size()]);
}