Class CodeAction


  • public class CodeAction
    extends java.lang.Object
    A code action represents a change that can be performed in code, e.g. to fix a problem or to refactor code.

    A CodeAction must set either edit and/or a command. If both are supplied, the edit is applied first, then the command is executed.

    • Constructor Summary

      Constructors 
      Constructor Description
      CodeAction()  
      CodeAction​(java.lang.String title)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)  
      Command getCommand()
      A command this code action executes.
      java.lang.Object getData()
      A data entry field that is preserved on a code action between a `textDocument/codeAction` and a `codeAction/resolve` request.
      java.util.List<Diagnostic> getDiagnostics()
      The diagnostics that this code action resolves.
      CodeActionDisabled getDisabled()
      Marks that the code action cannot currently be applied.
      WorkspaceEdit getEdit()
      The workspace edit this code action performs.
      java.lang.Boolean getIsPreferred()
      Marks this as a preferred action.
      java.lang.String getKind()
      The kind of the code action.
      java.lang.String getTitle()
      A short, human-readable, title for this code action.
      int hashCode()  
      void setCommand​(Command command)
      A command this code action executes.
      void setData​(java.lang.Object data)
      A data entry field that is preserved on a code action between a `textDocument/codeAction` and a `codeAction/resolve` request.
      void setDiagnostics​(java.util.List<Diagnostic> diagnostics)
      The diagnostics that this code action resolves.
      void setDisabled​(CodeActionDisabled disabled)
      Marks that the code action cannot currently be applied.
      void setEdit​(WorkspaceEdit edit)
      The workspace edit this code action performs.
      void setIsPreferred​(java.lang.Boolean isPreferred)
      Marks this as a preferred action.
      void setKind​(java.lang.String kind)
      The kind of the code action.
      void setTitle​(java.lang.String title)
      A short, human-readable, title for this code action.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • CodeAction

        public CodeAction()
      • CodeAction

        public CodeAction​(java.lang.String title)
    • Method Detail

      • getTitle

        public java.lang.String getTitle()
        A short, human-readable, title for this code action.
      • setTitle

        public void setTitle​(java.lang.String title)
        A short, human-readable, title for this code action.
      • getKind

        public java.lang.String getKind()
        The kind of the code action.

        Used to filter code actions.

        See CodeActionKind for some predefined code action kinds.

      • setKind

        public void setKind​(java.lang.String kind)
        The kind of the code action.

        Used to filter code actions.

        See CodeActionKind for some predefined code action kinds.

      • getDiagnostics

        public java.util.List<Diagnostic> getDiagnostics()
        The diagnostics that this code action resolves.
      • setDiagnostics

        public void setDiagnostics​(java.util.List<Diagnostic> diagnostics)
        The diagnostics that this code action resolves.
      • getIsPreferred

        public java.lang.Boolean getIsPreferred()
        Marks this as a preferred action. Preferred actions are used by the `auto fix` command and can be targeted by keybindings.

        A quick fix should be marked preferred if it properly addresses the underlying error. A refactoring should be marked preferred if it is the most reasonable choice of actions to take.

        Since 3.15.0

      • setIsPreferred

        public void setIsPreferred​(java.lang.Boolean isPreferred)
        Marks this as a preferred action. Preferred actions are used by the `auto fix` command and can be targeted by keybindings.

        A quick fix should be marked preferred if it properly addresses the underlying error. A refactoring should be marked preferred if it is the most reasonable choice of actions to take.

        Since 3.15.0

      • getDisabled

        public CodeActionDisabled getDisabled()
        Marks that the code action cannot currently be applied.

        Clients should follow the following guidelines regarding disabled code actions:

        • Disabled code actions are not shown in automatic lightbulb code action menu.
        • Disabled actions are shown as faded out in the code action menu when the user request a more specific type of code action, such as refactorings.
        • If the user has a keybinding that auto applies a code action and only a disabled code actions are returned, the client should show the user an error message with CodeActionDisabled.reason in the editor.

        Since 3.16.0

      • setDisabled

        public void setDisabled​(CodeActionDisabled disabled)
        Marks that the code action cannot currently be applied.

        Clients should follow the following guidelines regarding disabled code actions:

        • Disabled code actions are not shown in automatic lightbulb code action menu.
        • Disabled actions are shown as faded out in the code action menu when the user request a more specific type of code action, such as refactorings.
        • If the user has a keybinding that auto applies a code action and only a disabled code actions are returned, the client should show the user an error message with CodeActionDisabled.reason in the editor.

        Since 3.16.0

      • getEdit

        public WorkspaceEdit getEdit()
        The workspace edit this code action performs.
      • setEdit

        public void setEdit​(WorkspaceEdit edit)
        The workspace edit this code action performs.
      • getCommand

        public Command getCommand()
        A command this code action executes. If a code action provides a edit and a command, first the edit is executed and then the command.
      • setCommand

        public void setCommand​(Command command)
        A command this code action executes. If a code action provides a edit and a command, first the edit is executed and then the command.
      • getData

        public java.lang.Object getData()
        A data entry field that is preserved on a code action between a `textDocument/codeAction` and a `codeAction/resolve` request.

        Since 3.16.0

      • setData

        public void setData​(java.lang.Object data)
        A data entry field that is preserved on a code action between a `textDocument/codeAction` and a `codeAction/resolve` request.

        Since 3.16.0

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object