Class CUCorrectionProposal

All Implemented Interfaces:
org.eclipse.core.runtime.IAdaptable, ICUCorrectionProposal, ICommandAccess, IJavaCompletionProposal, org.eclipse.jface.text.contentassist.ICompletionProposal, org.eclipse.jface.text.contentassist.ICompletionProposalExtension5, org.eclipse.jface.text.contentassist.ICompletionProposalExtension6
Direct Known Subclasses:
ASTRewriteCorrectionProposal

public class CUCorrectionProposal extends ChangeCorrectionProposal 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:
3.8
  • Constructor Details

    • CUCorrectionProposal

      public CUCorrectionProposal(String name, ICompilationUnit cu, org.eclipse.ltk.core.refactoring.TextChange change, int relevance, org.eclipse.swt.graphics.Image image)
      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
      image - the image that is displayed for this proposal or null if no image is desired
    • CUCorrectionProposal

      public CUCorrectionProposal(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. Uses the default image for this proposal.
      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
    • CUCorrectionProposal

      protected CUCorrectionProposal(String name, ICompilationUnit cu, int relevance, org.eclipse.swt.graphics.Image image)
      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
      image - the image that is displayed for this proposal or null if no image is desired
    • CUCorrectionProposal

      public CUCorrectionProposal(String name, ICompilationUnit cu, int relevance, org.eclipse.swt.graphics.Image image, CUCorrectionProposalCore delegate)
      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
      image - the image that is displayed for this proposal or null if no image is desired
      delegate - The delegate instance
      Since:
      3.31
    • CUCorrectionProposal

      public CUCorrectionProposal(String name, ICompilationUnit cu, org.eclipse.ltk.core.refactoring.TextChange change, int relevance, org.eclipse.swt.graphics.Image image, CUCorrectionProposalCore delegate)
      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
      change - The text change to be applied
      relevance - the relevance of this proposal
      image - the image that is displayed for this proposal or null if no image is desired
      delegate - The delegate proposal underlying this proposal
      Since:
      3.31
  • Method Details

    • getDelegate

      protected CUCorrectionProposalCore getDelegate()
      Returns:
      the delegate
      Since:
      3.32
    • addEdits

      protected 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 ChangeCorrectionProposal.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.
    • getAdditionalProposalInfo

      public Object getAdditionalProposalInfo(org.eclipse.core.runtime.IProgressMonitor monitor)
      Specified by:
      getAdditionalProposalInfo in interface org.eclipse.jface.text.contentassist.ICompletionProposalExtension5
      Overrides:
      getAdditionalProposalInfo in class ChangeCorrectionProposalCore
    • getInitialCompilationUnit

      protected ICompilationUnit getInitialCompilationUnit()
      Returns:
      the compilation unit
      Since:
      3.31
    • apply

      public void apply(org.eclipse.jface.text.IDocument document)
      Specified by:
      apply in interface org.eclipse.jface.text.contentassist.ICompletionProposal
      Overrides:
      apply in class ChangeCorrectionProposal
    • createTextChange

      protected 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 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
    • useDelegateToCreateTextChange

      protected boolean useDelegateToCreateTextChange()
      Since:
      3.31
    • createTextChangeLocal

      protected org.eclipse.ltk.core.refactoring.TextChange createTextChangeLocal() throws org.eclipse.core.runtime.CoreException
      Returns:
      the text change
      Throws:
      org.eclipse.core.runtime.CoreException
      Since:
      3.31
    • createTextChangeViaDelegate

      protected org.eclipse.ltk.core.refactoring.TextChange createTextChangeViaDelegate() throws org.eclipse.core.runtime.CoreException
      Returns:
      a text change created via the delegate
      Throws:
      org.eclipse.core.runtime.CoreException
      Since:
      3.31
    • createChange

      protected final org.eclipse.ltk.core.refactoring.Change createChange() throws org.eclipse.core.runtime.CoreException
      Clients should not override this method
      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 final ICompilationUnit getCompilationUnit()
      The compilation unit on which the change works.
      Returns:
      the compilation unit on which the change works
    • getPreviewContent

      public final 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.
    • getName

      public String getName()
      Description copied from class: ChangeCorrectionProposalCore
      Returns the name of the proposal.
      Overrides:
      getName in class ChangeCorrectionProposalCore
      Returns:
      the name of the proposal
    • getCommandId

      public String getCommandId()
      Description copied from interface: ICommandAccess
      Returns the id of the command that should invoke this correction proposal.
      Specified by:
      getCommandId in interface ICommandAccess
      Overrides:
      getCommandId in class ChangeCorrectionProposalCore
      Returns:
      the command id
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • didOpenEditor

      protected boolean didOpenEditor()
      Returns whether the changed compilation unit was not previously open in an editor.
      Returns:
      true if the changed compilation unit was not previously open in an editor, false if the changed compilation unit was already open in an editor
      Restriction:
      This method is not intended to be referenced by clients.
    • getAdapter

      public <T> T getAdapter(Class<T> adapter)
      Specified by:
      getAdapter in interface org.eclipse.core.runtime.IAdaptable
      Overrides:
      getAdapter in class ChangeCorrectionProposalCore
      Since:
      3.32