Class CUCorrectionProposalCore

java.lang.Object
org.eclipse.jdt.core.manipulation.ChangeCorrectionProposalCore
org.eclipse.jdt.core.manipulation.CUCorrectionProposalCore
All Implemented Interfaces:
org.eclipse.core.runtime.IAdaptable, ICUCorrectionProposal

public class CUCorrectionProposalCore extends ChangeCorrectionProposalCore implements ICUCorrectionProposal
A proposal for quick fixes and quick assists that work on a single compilation unit. Either a text change is directly passed in the constructor or method addEdits(IDocument, TextEdit) is overridden to provide the text edits that are applied to the document when the proposal is evaluated.

The proposal takes care of the preview of the changes as proposal information.

Since:
1.11
  • Constructor Details

    • CUCorrectionProposalCore

      public CUCorrectionProposalCore(ICUCorrectionProposal proposal, String name, ICompilationUnit cu, org.eclipse.ltk.core.refactoring.TextChange change, int relevance)
      Constructs a correction proposal working on a compilation unit with a given text change.
      Parameters:
      proposal - ICUCorrectionProposal to use
      name - the name that is displayed in the proposal selection dialog
      cu - the compilation unit to which the change can be applied
      change - the change that is executed when the proposal is applied or null if implementors override addEdits(IDocument, TextEdit) to provide the text edits or createTextChange() to provide a text change
      relevance - the relevance of this proposal
    • CUCorrectionProposalCore

      public CUCorrectionProposalCore(String name, ICompilationUnit cu, org.eclipse.ltk.core.refactoring.TextChange change, int relevance)
      Constructs a correction proposal working on a compilation unit with a given text change.
      Parameters:
      name - the name that is displayed in the proposal selection dialog
      cu - the compilation unit to which the change can be applied
      change - the change that is executed when the proposal is applied or null if implementors override addEdits(IDocument, TextEdit) to provide the text edits or createTextChange() to provide a text change
      relevance - the relevance of this proposal
    • CUCorrectionProposalCore

      protected CUCorrectionProposalCore(String name, ICompilationUnit cu, int relevance)
      Constructs a correction proposal working on a compilation unit.

      Users have to override addEdits(IDocument, TextEdit) to provide the text edits or createTextChange() to provide a text change.

      Parameters:
      name - the name that is displayed in the proposal selection dialog
      cu - the compilation unit on that the change works
      relevance - the relevance of this proposal
  • Method Details

    • addEdits

      public void addEdits(org.eclipse.jface.text.IDocument document, org.eclipse.text.edits.TextEdit editRoot) throws org.eclipse.core.runtime.CoreException
      Called when the CompilationUnitChange is initialized. Subclasses can override to add text edits to the root edit of the change. Implementors must not access the proposal, e.g. not call ChangeCorrectionProposalCore.getChange().

      The default implementation does not add any edits

      Parameters:
      document - content of the underlying compilation unit. To be accessed read only.
      editRoot - The root edit to add all edits to
      Throws:
      org.eclipse.core.runtime.CoreException - can be thrown if adding the edits is failing.
      Since:
      1.20
    • getAdditionalProposalInfo

      public Object getAdditionalProposalInfo(org.eclipse.core.runtime.IProgressMonitor monitor)
      Overrides:
      getAdditionalProposalInfo in class ChangeCorrectionProposalCore
    • apply

      public void apply() throws org.eclipse.core.runtime.CoreException
      Overrides:
      apply in class ChangeCorrectionProposalCore
      Throws:
      org.eclipse.core.runtime.CoreException
    • getNewChange

      public org.eclipse.ltk.core.refactoring.TextChange getNewChange()
    • createTextChange

      public org.eclipse.ltk.core.refactoring.TextChange createTextChange() throws org.eclipse.core.runtime.CoreException
      Creates the text change for this proposal. This method is only called once and only when no text change has been passed in {see #CUCorrectionProposal(String, ICompilationUnit, TextChange, int, Image)}.
      Returns:
      the created text change
      Throws:
      org.eclipse.core.runtime.CoreException - if the creation of the text change failed
    • createChange

      protected org.eclipse.ltk.core.refactoring.Change createChange() throws org.eclipse.core.runtime.CoreException
      Description copied from class: ChangeCorrectionProposalCore
      Creates the change for this proposal. This method is only called once and only when no change has been passed in {#ChangeCorrectionProposal(String, Change, int, Image)}. Subclasses may override.
      Overrides:
      createChange in class ChangeCorrectionProposalCore
      Returns:
      the created change
      Throws:
      org.eclipse.core.runtime.CoreException - if the creation of the change failed
    • getTextChange

      public final org.eclipse.ltk.core.refactoring.TextChange getTextChange() throws org.eclipse.core.runtime.CoreException
      Returns the text change that is invoked when the change is applied.
      Specified by:
      getTextChange in interface ICUCorrectionProposal
      Returns:
      the text change that is invoked when the change is applied
      Throws:
      org.eclipse.core.runtime.CoreException - if accessing the change failed
    • getCompilationUnit

      public ICompilationUnit getCompilationUnit()
      The compilation unit on which the change works.
      Returns:
      the compilation unit on which the change works
    • getPreviewContent

      public String getPreviewContent() throws org.eclipse.core.runtime.CoreException
      Creates a preview of the content of the compilation unit after applying the change.
      Returns:
      the preview of the changed compilation unit
      Throws:
      org.eclipse.core.runtime.CoreException - if the creation of the change failed
      Restriction:
      This method is not intended to be referenced by clients.
    • toString

      public String toString()
      Overrides:
      toString in class Object