當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。