summaryrefslogtreecommitdiff
path: root/platform/lang-api/src/com/intellij/lang/surroundWith/Surrounder.java
blob: dcfa6b5a12b3244d6012f3c20c64d48812736e58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.lang.surroundWith;

import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.NlsActions;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.util.ArrayFactory;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * Defines a single template which can be used in <em>Code | Surround With</em> action.
 *
 * @see SurroundDescriptor
 * @see <a href="https://plugins.jetbrains.com/docs/intellij/surround-with.html">Surround With (IntelliJ Platform Docs)</a>
 */
public interface Surrounder {
  Surrounder[] EMPTY_ARRAY = new Surrounder[0];
  ArrayFactory<Surrounder> myArrayFactory = count -> count == 0 ? EMPTY_ARRAY : new Surrounder[count];

  /**
   * @return the user-visible name of the <em>Surround With</em> template
   */
  @NlsActions.ActionText
  String getTemplateDescription();

  /**
   * Checks if the template can be used to surround the specified range of elements.
   *
   * @param elements the elements to be surrounded
   * @return {@code true} if the template is applicable to the elements, {@code false} otherwise
   */
  boolean isApplicable(PsiElement @NotNull [] elements);

  /**
   * Performs the <em>Code | Surround With</em> action on the specified range of elements.
   *
   * @param elements the elements to be surrounded
   * @return range to select/to position the caret
   */
  @Nullable
  TextRange surroundElements(@NotNull Project project,
                             @NotNull Editor editor,
                             PsiElement @NotNull [] elements) throws IncorrectOperationException;
}