Package org.eclipse.jdt.ui.text.java.correction

## Class CUCorrectionProposal

- java.lang.Object
- - org.eclipse.jdt.core.manipulation.ChangeCorrectionProposalCore
  - - org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal
    - - org.eclipse.jdt.ui.text.java.correction.CUCorrectionProposal

All Implemented Interfaces:
  `ICUCorrectionProposal`, `ICommandAccess`, `IJavaCompletionProposal`, `ICompletionProposal`, `ICompletionProposalExtension5`, `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

### Field Summary

### Fields inherited from class org.eclipse.jdt.core.manipulation.ChangeCorrectionProposalCore

`fChange, fName, fRelevance`

### Fields inherited from interface org.eclipse.jdt.ui.text.java.correction.ICommandAccess

`ASSIST_SUFFIX, COMMAND_ID_PREFIX`

### Constructor Summary

Constructors
`protected` `CUCorrectionProposal​(String name, ICompilationUnit cu, int relevance, Image image)` Constructs a correction proposal working on a compilation unit.
`` `CUCorrectionProposal​(String name, ICompilationUnit cu, TextChange change, int relevance)` Constructs a correction proposal working on a compilation unit with a given text change.
`` `CUCorrectionProposal​(String name, ICompilationUnit cu, TextChange change, int relevance, Image image)` Constructs a correction proposal working on a compilation unit with a given text change.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected void` `addEdits​(IDocument document, TextEdit editRoot)` Called when the `CompilationUnitChange` is initialized.
`void` `apply​(IDocument document)`
`protected Change` `createChange()` Creates the change for this proposal.
`protected TextChange` `createTextChange()` Creates the text change for this proposal.
`protected boolean` `didOpenEditor()` Returns whether the changed compilation unit was not previously open in an editor.
`Object` `getAdditionalProposalInfo​(IProgressMonitor monitor)`
`ICompilationUnit` `getCompilationUnit()` The compilation unit on which the change works.
`String` `getPreviewContent()` Creates a preview of the content of the compilation unit after applying the change.
`TextChange` `getTextChange()` Returns the text change that is invoked when the change is applied.
`String` `toString()`

### Methods inherited from class org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal

`getAdditionalProposalInfo, getChange, getCommandId, getContextInformation, getDisplayString, getImage, getSelection, getStyledDisplayString, performChange, setCommandId, setImage`

### Methods inherited from class org.eclipse.jdt.core.manipulation.ChangeCorrectionProposalCore

`apply, getName, getRelevance, performChange, setDisplayName, setRelevance`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.eclipse.jdt.ui.text.java.IJavaCompletionProposal

`getRelevance`

### Constructor Detail

#### CUCorrectionProposal

    public CUCorrectionProposal​(String name,
                                ICompilationUnit cu,
                                TextChange change,
                                int relevance,
                                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,
                                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,
                                   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

### Method Detail

#### addEdits

    protected void addEdits​(IDocument document,
                            TextEdit editRoot)
                     throws 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:
  `CoreException` - can be thrown if adding the edits is failing.

#### getAdditionalProposalInfo

    public Object getAdditionalProposalInfo​(IProgressMonitor monitor)

Specified by:
  `getAdditionalProposalInfo` in interface `ICompletionProposalExtension5`
Overrides:
  `getAdditionalProposalInfo` in class `ChangeCorrectionProposalCore`

#### apply

    public void apply​(IDocument document)

Specified by:
  `apply` in interface `ICompletionProposal`
Overrides:
  `apply` in class `ChangeCorrectionProposal`

#### createTextChange

    protected TextChange createTextChange()
                                   throws 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:
  `CoreException` - if the creation of the text change failed

#### createChange

    protected final Change createChange()
                                 throws 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:
  `CoreException` - if the creation of the change failed

#### getTextChange

    public final TextChange getTextChange()
                                   throws 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:
  `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 String getPreviewContent()
                             throws CoreException

Creates a preview of the content of the compilation unit after applying the change.

Returns:
  the preview of the changed compilation unit
Throws:
  `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`

#### 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.