Package com.intellij.codeInsight.template

Examples of com.intellij.codeInsight.template.Template


            TemplateSettings templateSettings = TemplateSettings.getInstance();
            Document doc = parser.build(inputStream);
            Element root = doc.getRootElement();
            for (Object element : root.getChildren()) {
                if (element instanceof Element) {
                    final Template template = readExternal((Element) element, templateName);
                    final String key = template.getKey();
                    // Only add if not present
                    if (key != null && templateSettings.getTemplate(key) == null) {
                        templateSettings.addTemplate(template);
                    }
                }
View Full Code Here


                                  : DartBundle.message("dart.fix.override.none.found");
  }

  @Override
  protected Template buildFunctionsText(TemplateManager templateManager, DartComponent element) {
    final Template template = templateManager.createTemplate(getClass().getName(), DART_TEMPLATE_GROUP);
    template.setToReformat(true);
    final DartReturnType returnType = PsiTreeUtil.getChildOfType(element, DartReturnType.class);
    final DartType dartType = PsiTreeUtil.getChildOfType(element, DartType.class);
    if (returnType != null) {
      template.addTextSegment(DartPresentableUtil.buildTypeText(element, returnType, specializations));
      template.addTextSegment(" ");
    }
    else if (dartType != null) {
      template.addTextSegment(DartPresentableUtil.buildTypeText(element, dartType, specializations));
      template.addTextSegment(" ");
    }
    if (element.isGetter() || element.isSetter()) {
      template.addTextSegment(element.isGetter() ? "get " : "set ");
    }
    //noinspection ConstantConditions
    template.addTextSegment(element.getName());
    if (!element.isGetter()) {
      template.addTextSegment("(");
      template.addTextSegment(DartPresentableUtil.getPresentableParameterList(element, specializations));
      template.addTextSegment(")");
    }
    template.addTextSegment("{\n");
    template.addEndVariable();
    template.addTextSegment("\n}\n");
    return template;
  }
View Full Code Here

  protected String getNothingFoundMessage() {
    return ""; // can't be called actually because processElements() is overridden
  }

  protected Template buildFunctionsText(TemplateManager templateManager, Set<DartComponent> elementsToProcess) {
    final Template template = templateManager.createTemplate(getClass().getName(), DART_TEMPLATE_GROUP);
    template.setToReformat(true);

    //noinspection ConstantConditions
    template.addTextSegment(myDartClass.getName());
    template.addTextSegment("(");
    for (Iterator<DartComponent> iterator = elementsToProcess.iterator(); iterator.hasNext(); ) {
      DartComponent component = iterator.next();
      template.addTextSegment("this.");
      //noinspection ConstantConditions
      template.addTextSegment(component.getName());
      if (iterator.hasNext()) {
        template.addTextSegment(",");
      }
    }
    template.addTextSegment(")");
    template.addTextSegment("{\n");
    template.addEndVariable();
    template.addTextSegment("\n}\n");
    return template;
  }
View Full Code Here

  protected Template buildFunctionsText(TemplateManager templateManager, DartComponent namedComponent) {
    final DartReturnType returnType = PsiTreeUtil.getChildOfType(namedComponent, DartReturnType.class);
    final DartType dartType = PsiTreeUtil.getChildOfType(namedComponent, DartType.class);
    final String typeText = returnType == null ? DartPresentableUtil.buildTypeText(namedComponent, dartType, null)
                                               : DartPresentableUtil.buildTypeText(namedComponent, returnType, null);
    final Template template = templateManager.createTemplate(getClass().getName(), DART_TEMPLATE_GROUP);
    template.setToReformat(true);
    if (myStrategy == Strategy.GETTER || myStrategy == Strategy.GETTERSETTER) {
      buildGetter(template, namedComponent.getName(), typeText);
    }
    if (myStrategy == Strategy.SETTER || myStrategy == Strategy.GETTERSETTER) {
      buildSetter(template, namedComponent.getName(), typeText);
View Full Code Here

  }

  @Override
  protected void applyFix(Project project, @NotNull PsiElement psiElement, Editor editor) {
    final TemplateManager templateManager = TemplateManager.getInstance(project);
    Template template = templateManager.createTemplate("", "");
    template.setToReformat(true);

    if (!buildTemplate(template, psiElement)) {
      return;
    }
View Full Code Here

    if (anchor == null) {
      return;
    }

    final TemplateManager templateManager = TemplateManager.getInstance(project);
    Template template = templateManager.createTemplate("", "");
    template.setToReformat(true);

    template.addTextSegment("class ");
    template.addVariable(DartPresentableUtil.getExpression(myClassName), false);
    template.addTextSegment("{\n");
    template.addEndVariable();
    template.addTextSegment("\n}\n");

    final Editor openedEditor = navigate(project, anchor.getTextOffset(), anchor.getContainingFile().getVirtualFile());
    if (openedEditor != null) {
      templateManager.startTemplate(openedEditor, template);
    }
View Full Code Here

  }

  @Override
  protected void applyFix(Project project, @NotNull PsiElement psiElement, Editor editor) {
    final TemplateManager templateManager = TemplateManager.getInstance(project);
    Template template = templateManager.createTemplate("", "");
    template.setToReformat(true);

    buildTemplate(template, psiElement);

    PsiElement anchor = findAnchor(psiElement);
View Full Code Here

    final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();

    assert editor != null;
    final TemplateManager templateManager = TemplateManager.getInstance(file.getProject());
    final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor);
    final Template template = templateManager.getActiveTemplate(editor);
    if (templateState != null && template != null) {
      templateState.gotoEnd(false);
    }
  }
View Full Code Here

        }

        final RangeMarker rangeMarker = doc.createRangeMarker(startElement.getTextRange());

        GoFile goFile = (GoFile) file;
        Template template;
        GoVarDeclarations[] globalVariables = goFile.getGlobalVariables();
        if (globalVariables.length == 0) {
            template = createNewStatementTemplate(editor, goFile, startElement);
        } else {
            GoVarDeclarations lastVar = globalVariables[globalVariables.length - 1];
View Full Code Here

import org.intellij.erlang.psi.impl.ErlangPsiImplUtil;
import org.jetbrains.annotations.NotNull;

public class ErlangUnitTestMethodAction extends CodeInsightAction implements CodeInsightActionHandler {
  private static void insertTestFunction(@NotNull Project project, @NotNull Editor editor, String name, boolean needNewline) {
    Template template = TemplateManager.getInstance(project).createTemplate("", "");
    Expression nameExpr = new ConstantNode(name);
    Expression expected = new ConstantNode("expected");
    Expression expr = new ConstantNode("expr");
    template.addTextSegment("\n" + (needNewline ? "\n" : ""));
    template.addVariable("name", nameExpr, nameExpr, true);
    template.addTextSegment("_test() ->\n");
    template.addTextSegment("?assertEqual(");
    template.addVariable(expected, true);
    template.addTextSegment(", ");
    template.addVariable(expr, true);
    template.addTextSegment(").");
    template.addEndVariable();
    template.setToIndent(true);
    template.setToReformat(true);
    TemplateManager.getInstance(project).startTemplate(editor, template, null);
  }
View Full Code Here

TOP

Related Classes of com.intellij.codeInsight.template.Template

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.