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


Java VariableNode类代码示例

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


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

示例1: setVariables

import com.intellij.codeInsight.template.impl.VariableNode; //导入依赖的package包/类
@Override
public void setVariables(@NotNull Template template, @NotNull PsiElement element) {
  MacroCallNode type = new MacroCallNode(new IterableComponentTypeMacro());
  MacroCallNode name = new MacroCallNode(new SuggestVariableNameMacro());
  type.addParameter(new VariableNode("expr", null));
  template.addVariable("type", type, type, false);
  template.addVariable("name", name, name, true);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:ForeachPostfixTemplate.java

示例2: createElement

import com.intellij.codeInsight.template.impl.VariableNode; //导入依赖的package包/类
@Override
protected DomElement createElement(final WebApp context,
                                   final Editor editor,
                                   PsiFile file,
                                   final Project project,
                                   final PsiClass selectedClass) {

  new WriteCommandAction.Simple(project, "Create Filter", file) {
    @Override
    protected void run() throws Throwable {
      Filter filter = (Filter)createElement(context);
      filter.getFilterClass().setValue(selectedClass);

      FilterMapping mapping = context.addFilterMapping();

      TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(context.getXmlElement());
      VariableNode nameNode = new VariableNode("NAME", new MacroCallNode(new CompleteMacro()));
      replaceElementValue(builder, filter.getFilterName(), nameNode);

      replaceElementValue(builder, mapping.getFilterName(), nameNode);
      GenericDomValue<String> value = mapping.addUrlPattern();
      XmlTag tag = value.ensureTagExists();
      PsiElement child = tag.getLastChild();
      while (child != null && child != tag.getFirstChild()) {
        PsiElement prevSibling = child.getPrevSibling();
        child.delete();
        child = prevSibling;
      }
      builder.replaceElement(tag, TextRange.from(1, 0), new MacroCallNode(new CompleteSmartMacro()));

      PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
      builder.run();
    }
  }.execute();
  return null;
}
 
开发者ID:consulo,项目名称:consulo-javaee,代码行数:37,代码来源:GenerateFilterAction.java

示例3: createElement

import com.intellij.codeInsight.template.impl.VariableNode; //导入依赖的package包/类
@Override
protected DomElement createElement(final WebApp context,
                                   final Editor editor,
                                   PsiFile file,
                                   final Project project,
                                   final PsiClass selectedClass) {

  new WriteCommandAction.Simple(project, "Create servlet", file) {
    @Override
    protected void run() throws Throwable {
      Servlet servlet = (Servlet)createElement(context);
      servlet.getServletClass().setValue(selectedClass);

      ServletMapping mapping = context.addServletMapping();

      TemplateBuilder builder = TemplateBuilderFactory.getInstance().createTemplateBuilder(context.getXmlElement());
      VariableNode nameNode = new VariableNode("NAME", new MacroCallNode(new CompleteMacro()));
      replaceElementValue(builder, servlet.getServletName(), nameNode);

      replaceElementValue(builder, mapping.getServletName(), nameNode);
      replaceElementValue(builder, mapping.addUrlPattern(), new EmptyNode());

      PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
      builder.run();
    }
  }.execute();
  return null;
}
 
开发者ID:consulo,项目名称:consulo-javaee,代码行数:29,代码来源:GenerateServletAction.java

示例4: expand

import com.intellij.codeInsight.template.impl.VariableNode; //导入依赖的package包/类
@Override
public void expand(@NotNull PsiElement context, @NotNull Editor editor) {
  PsiExpression expr = JavaPostfixTemplatesUtils.getTopmostExpression(context);
  if (expr == null) return;
  Project project = context.getProject();

  Document document = editor.getDocument();
  document.deleteString(expr.getTextRange().getStartOffset(), expr.getTextRange().getEndOffset());
  TemplateManager manager = TemplateManager.getInstance(project);

  Template template = manager.createTemplate("", "");
  template.setToReformat(true);
  template.addTextSegment("for (");
  MacroCallNode type = new MacroCallNode(new IterableComponentTypeMacro());

  String variable = "variable";
  type.addParameter(new VariableNode(variable, null));
  MacroCallNode name = new MacroCallNode(new SuggestVariableNameMacro());

  template.addVariable("type", type, type, false);
  template.addTextSegment(" ");
  template.addVariable("name", name, name, true);

  template.addTextSegment(" : ");
  template.addVariable(variable, new TextExpression(expr.getText()), false);
  template.addTextSegment(") {\n");
  template.addEndVariable();
  template.addTextSegment("\n}");

  manager.startTemplate(editor, template);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:32,代码来源:ForeachPostfixTemplate.java


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