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


Java TemplateContextType.addResolver方法代码示例

本文整理汇总了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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:30,代码来源:ContributionContextTypeRegistry.java

示例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);
  }
}
 
开发者ID:m-m-m,项目名称:eclipse-templatevariables,代码行数:21,代码来源:TemplateVariablesStartup.java

示例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);
    }
}
 
开发者ID:fabioz,项目名称:Pydev,代码行数:81,代码来源:AbstractPyCreateClassOrMethodOrField.java

示例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());
}
 
开发者ID:eclipse,项目名称:che,代码行数:15,代码来源:JavaPlugin.java

示例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());
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:15,代码来源:JavaPlugin.java


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