Tabnine Logo
Template
Code IndexAdd Tabnine to your IDE (free)

How to use
Template
in
com.intellij.codeInsight.template

Best Java code snippets using com.intellij.codeInsight.template.Template (Showing top 10 results out of 315)

origin: go-lang-plugin-org/go-lang-idea-plugin

private static void setupFunctionParameters(@NotNull Template template,
                      @NotNull List<GoExpression> args, PsiFile file) {
 Map<String, GoImportSpec> importMap = ((GoFile)file).getImportedPackagesMap();
 template.addTextSegment("(");
 for (int i = 0; i < args.size(); i++) {
  GoExpression e = args.get(i);
  template.addVariable(GoRefactoringUtil.createParameterNameSuggestedExpression(e), true);
  template.addTextSegment(" ");
  String type = convertType(file, e.getGoType(null), importMap);
  template.addVariable(new ConstantNode(type), true);
  if (i != args.size() - 1) template.addTextSegment(", ");
 }
 template.addTextSegment(")");
}
origin: go-lang-plugin-org/go-lang-idea-plugin

 @Override
 public void invoke(@NotNull Project project,
           @NotNull PsiFile file,
           @Nullable("is null when called from inspection") Editor editor,
           @NotNull PsiElement startElement,
           @NotNull PsiElement endElement) {
  if (!(file instanceof GoFile) || editor == null || !(startElement instanceof GoBlock)) return;
  PsiElement brace = ((GoBlock)startElement).getRbrace();
  if (brace == null) return;
  Template template = TemplateSettings.getInstance().getTemplateById("go_lang_add_return");
  if (template == null) return;
  int start = brace.getTextRange().getStartOffset();
  editor.getCaretModel().moveToOffset(start);
  editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
  template.setToReformat(true);
  TemplateManager.getInstance(project).startTemplate(editor, template, true, Collections.emptyMap(), null);
 }
}
origin: go-lang-plugin-org/go-lang-idea-plugin

@Override
public void invoke(@NotNull Project project,
          @NotNull PsiFile file,
          @Nullable("is null when called from inspection") Editor editor,
          @NotNull PsiElement startElement,
          @NotNull PsiElement endElement) {
 if (editor == null) {
  LOG.error("Cannot run quick fix without editor: " + getClass().getSimpleName(),
       AttachmentFactory.createAttachment(file.getVirtualFile()));
  return;
 }
 if (!(startElement instanceof GoCallExpr)) return;
 GoCallExpr call = (GoCallExpr)startElement;
 List<GoExpression> args = call.getArgumentList().getExpressionList();
 GoType resultType = ContainerUtil.getFirstItem(GoTypeUtil.getExpectedTypes(call));
 PsiElement anchor = PsiTreeUtil.findPrevParent(file, call);
 Template template = TemplateManager.getInstance(project).createTemplate("", "");
 template.addTextSegment("\nfunc " + myName);
 setupFunctionParameters(template, args, file);
 setupFunctionResult(template, resultType);
 template.addTextSegment(" {\n\t");
 template.addEndVariable();
 template.addTextSegment("\n}");
 int offset = anchor.getTextRange().getEndOffset();
 editor.getCaretModel().moveToOffset(offset);
 startTemplate(editor, template, project);
}
origin: liias/monkey

 if (index == -1) break;
 template.addTextSegment(templateText.substring(from, index));
  template.addVariable("name", nameExpr, nameExpr, !automatic);
 } else {
  template.addVariableSegment("name");
template.addTextSegment(templateText.substring(from, templateText.length()));
template.setToIndent(true);
template.setToReformat(true);
template.setToShortenLongNames(true);
origin: JetBrains/Grammar-Kit

editor.getCaretModel().moveToOffset(0);
Template template = builder.buildInlineTemplate();
template.setToShortenLongNames(false);
template.setToReformat(false);
TemplateManager.getInstance(project).startTemplate(editor, template, new TemplateEditingAdapter() {
origin: ballerina-platform/ballerina-lang

template.addVariable("name" + i, name, name, true);
template.addVariable("value" + i, name, name, true);
  template.addVariable("name" + i, name, name, true);
  template.addVariable("value" + i, name, name, true);
  template.addVariable("name" + i, name, name, true);
  template.addVariable("value" + i, name, name, true);
template.addVariable("name" + size, name, name, true);
template.addVariable("value" + size, name, name, true);
origin: Camelcade/Perl5-IDEA

@Override
public void processText(Project project, Template template, Document document, RangeMarker templateRange, Editor editor) {
 if (isEnabled(template)) {
  String templateText = template.getTemplateText();
  if (HEREDOC_OPENER_PATTERN.matcher(templateText).find()
    || HEREDOC_OPENER_PATTERN_SQ.matcher(templateText).find()
    || HEREDOC_OPENER_PATTERN_DQ.matcher(templateText).find()
    || HEREDOC_OPENER_PATTERN_XQ.matcher(templateText).find()
   ) {
   template.setToIndent(false);
  }
 }
}
origin: go-lang-plugin-org/go-lang-idea-plugin

private static void setupFunctionResult(@NotNull Template template, @Nullable GoType type) {
 if (type instanceof GoTypeList) {
  template.addTextSegment(" (");
  List<GoType> list = ((GoTypeList)type).getTypeList();
  for (int i = 0; i < list.size(); i++) {
   template.addVariable(new ConstantNode(list.get(i).getText()), true);
   if (i < list.size() - 1) template.addTextSegment(", ");
  }
  template.addTextSegment(")");
  return;
 }
 if (type != null) {
  template.addTextSegment(" ");
  template.addVariable(new ConstantNode(type.getText()), true);
 }
}
origin: go-lang-plugin-org/go-lang-idea-plugin

@Override
public void invoke(@NotNull Project project,
          @NotNull PsiFile file,
          @Nullable("is null when called from inspection") Editor editor,
          @NotNull PsiElement startElement,
          @NotNull PsiElement endElement) {
 if (editor == null) {
  LOG.error("Cannot run quick fix without editor: " + getClass().getSimpleName(),
       AttachmentFactory.createAttachment(file.getVirtualFile()));
  return;
 }
 PsiElement reference = PsiTreeUtil.getNonStrictParentOfType(startElement, GoReferenceExpressionBase.class);
 PsiElement anchor = reference != null ? findAnchor(reference) : null;
 if (anchor == null) {
  LOG.error("Cannot find anchor for " + myWhat + " (GoUnresolvedFixBase), offset: " + editor.getCaretModel().getOffset(),
       AttachmentFactory.createAttachment(file.getVirtualFile()));
  return;
 }
 Template template = TemplateSettings.getInstance().getTemplateById(myTemplateId);
 if (template == null) {
  LOG.error("Cannot find anchor for " + myWhat + " (GoUnresolvedFixBase), offset: " + editor.getCaretModel().getOffset(),
       AttachmentFactory.createAttachment(file.getVirtualFile()));
  return;
 }
 int start = anchor.getTextRange().getStartOffset();
 editor.getCaretModel().moveToOffset(start);
 template.setToReformat(true);
 TemplateManager.getInstance(project).startTemplate(editor, template, true, ContainerUtil.stringMap("NAME", myName), null);
}
origin: go-lang-plugin-org/go-lang-idea-plugin

@Override
public void handleInsert(@NotNull InsertionContext context, LookupElement item) {
 Editor editor = context.getEditor();
 CharSequence documentText = context.getDocument().getImmutableCharSequence();
 int offset = skipWhiteSpaces(editor.getCaretModel().getOffset(), documentText);
 if (documentText.charAt(offset) != '{') {
  Project project = context.getProject();
  Template template = TemplateManager.getInstance(project).createTemplate("braces", "go", myOneLine ? "{$END$}" : " {\n$END$\n}");
  template.setToReformat(true);
  TemplateManager.getInstance(project).startTemplate(editor, template);
 }
 else {
  editor.getCaretModel().moveToOffset(offset);
  ApplicationManager.getApplication().runWriteAction(() -> {
   EditorActionHandler enterAction = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_START_NEW_LINE);
   enterAction.execute(editor, editor.getCaretModel().getCurrentCaret(), ((EditorEx)editor).getDataContext());
  });
 }
}
com.intellij.codeInsight.templateTemplate

Most used methods

  • addVariable
  • setToReformat
  • addTextSegment
  • setToIndent
  • setToShortenLongNames
  • addEndVariable
  • addVariableSegment
  • getTemplateText

Popular in Java

  • Start an intent from android
  • getContentResolver (Context)
  • setScale (BigDecimal)
  • getSystemService (Context)
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • HashMap (java.util)
    HashMap is an implementation of Map. All optional operations are supported.All elements are permitte
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • JOptionPane (javax.swing)
  • Option (scala)
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now