本文整理汇总了Java中org.eclipse.jface.text.templates.TemplateContextType.addResolver方法的典型用法代码示例。如果您正苦于以下问题:Java TemplateContextType.addResolver方法的具体用法?Java TemplateContextType.addResolver怎么用?Java TemplateContextType.addResolver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jface.text.templates.TemplateContextType
的用法示例。
在下文中一共展示了TemplateContextType.addResolver方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createContextType
import org.eclipse.jface.text.templates.TemplateContextType; //导入方法依赖的package包/类
/**
* Tries to create a context type given an id. Contributions to the <code>
* org.eclipse.ui.editors.templates</code> extension point are searched for the given identifier
* and the specified context type instantiated if it is found. Any contributed {@link
* org.eclipse.jface.text.templates.TemplateVariableResolver}s are also instantiated and added to
* the context type.
*
* @param id the id for the context type as specified in XML
* @return the instantiated and configured context type, or <code>null</code> if it is not found
* or cannot be instantiated
*/
public static TemplateContextType createContextType(String id) {
Assert.isNotNull(id);
IConfigurationElement[] extensions = getTemplateExtensions();
TemplateContextType type;
try {
type = createContextType(extensions, id);
if (type != null) {
TemplateVariableResolver[] resolvers = createResolvers(extensions, id);
for (int i = 0; i < resolvers.length; i++) type.addResolver(resolvers[i]);
}
} catch (CoreException e) {
JavaPlugin.log(e);
type = null;
}
return type;
}
示例2: addResolver
import org.eclipse.jface.text.templates.TemplateContextType; //导入方法依赖的package包/类
/**
* This method adds the given {@link TemplateVariableResolver} to each registered
* {@link TemplateContextType}.
*
* @param javaPlugin is the {@link JavaPlugin}.
* @param resolver is the {@link TemplateVariableResolver} to add.
*/
@SuppressWarnings({ "rawtypes" })
private void addResolver(JavaPlugin javaPlugin, TemplateVariableResolver resolver) {
Assert.isNotNull(javaPlugin);
Assert.isNotNull(resolver);
ContextTypeRegistry codeTemplateContextRegistry = javaPlugin.getCodeTemplateContextRegistry();
Assert.isNotNull(codeTemplateContextRegistry);
Iterator ctIter = codeTemplateContextRegistry.contextTypes();
while (ctIter.hasNext()) {
TemplateContextType contextType = (TemplateContextType) ctIter.next();
contextType.addResolver(resolver);
}
}
示例3: createProposal
import org.eclipse.jface.text.templates.TemplateContextType; //导入方法依赖的package包/类
protected ICompletionProposal createProposal(PySelection pySelection, String source,
Tuple<Integer, String> offsetAndIndent, boolean requireEmptyLines, Pass replacePassStatement) {
int offset;
int len;
String indent = offsetAndIndent.o2;
if (replacePassStatement == null) {
len = 0;
offset = offsetAndIndent.o1;
if (requireEmptyLines) {
int checkLine = pySelection.getLineOfOffset(offset);
int lineOffset = pySelection.getLineOffset(checkLine);
//Make sure we have 2 spaces from the last thing written.
if (lineOffset == offset) {
//it'll be added to the start of the line, so, we have to analyze the previous line to know if we'll need
//to new lines at the start.
checkLine--;
}
if (checkLine >= 0) {
//It'll be added to the current line, so, check the current line and the previous line to know about spaces.
String line = pySelection.getLine(checkLine);
if (line.trim().length() >= 1) {
source = "\n\n" + source;
} else if (checkLine > 1) {
line = pySelection.getLine(checkLine - 1);
if (line.trim().length() > 0) {
source = "\n" + source;
}
}
}
//If we have a '\n', all is OK (all contents after a \n will be indented)
if (!source.startsWith("\n")) {
try {
//Ok, it doesn't start with a \n, that means we have to check the line indentation where it'll
//be added and make sure things are correct (eventually adding a new line or just fixing the indent).
String lineContentsToCursor = pySelection.getLineContentsToCursor(offset);
if (lineContentsToCursor.length() > 0) {
source = "\n" + source;
} else {
source = indent + source;
}
} catch (BadLocationException e) {
source = "\n" + source;
}
}
}
} else {
offset = pySelection.getAbsoluteCursorOffset(replacePassStatement.beginLine - 1,
replacePassStatement.beginColumn - 1);
len = 4; //pass.len
if (requireEmptyLines) {
source = "\n\n" + source;
}
}
if (targetEditor != null) {
String creationStr = getCreationStr();
Region region = new Region(offset, len);
//Note: was using new PyContextType(), but when we had something as ${user} it
//would end up replacing it with the actual name of the user, which is not what
//we want!
TemplateContextType contextType = new TemplateContextType();
contextType.addResolver(new GlobalTemplateVariables.Cursor()); //We do want the cursor thought.
PyDocumentTemplateContext context = PyTemplateCompletionProcessor.createContext(contextType,
targetEditor.getPySourceViewer(), region, indent);
Template template = new Template("Create " + creationStr, "Create " + creationStr, "", source, true);
TemplateProposal templateProposal = new TemplateProposal(template, context, region, null);
return templateProposal;
} else {
//This should only happen in tests.
source = StringUtils.indentTo(source, indent, false);
return new CompletionProposal(source, offset, len, 0);
}
}
示例4: registerJavaContext
import org.eclipse.jface.text.templates.TemplateContextType; //导入方法依赖的package包/类
/**
* Registers the given Java template context.
*
* @param registry the template context type registry
* @param id the context type id
* @param parent the parent context type
* @since 3.4
*/
private static void registerJavaContext(
ContributionContextTypeRegistry registry, String id, TemplateContextType parent) {
TemplateContextType contextType = registry.getContextType(id);
Iterator<TemplateVariableResolver> iter = parent.resolvers();
while (iter.hasNext()) contextType.addResolver(iter.next());
}
示例5: registerJavaContext
import org.eclipse.jface.text.templates.TemplateContextType; //导入方法依赖的package包/类
/**
* Registers the given Java template context.
*
* @param registry the template context type registry
* @param id the context type id
* @param parent the parent context type
* @since 3.4
*/
private static void registerJavaContext(ContributionContextTypeRegistry registry, String id, TemplateContextType parent) {
TemplateContextType contextType= registry.getContextType(id);
Iterator<TemplateVariableResolver> iter= parent.resolvers();
while (iter.hasNext())
contextType.addResolver(iter.next());
}