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

## Class ChangeCorrectionProposal

- java.lang.Object
- - org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal

All Implemented Interfaces:
  ICommandAccess, IJavaCompletionProposal, ICompletionProposal, ICompletionProposalExtension5, ICompletionProposalExtension6

Direct Known Subclasses:
  CUCorrectionProposal

    public class ChangeCorrectionProposal
    extends Object
    implements IJavaCompletionProposal, ICommandAccess, ICompletionProposalExtension5, ICompletionProposalExtension6

Implementation of a Java completion proposal to be used for quick fix and quick assist proposals that are based on a `Change`. The proposal offers additional proposal information (based on the `Change`).

Since:
  3.8

### Field Summary

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

`ASSIST_SUFFIX, COMMAND_ID_PREFIX`

### Constructor Summary

Constructors
Constructor and Description
`ChangeCorrectionProposal(String name, Change change, int relevance)` Constructs a change correction proposal.
`ChangeCorrectionProposal(String name, Change change, int relevance, Image image)` Constructs a change correction proposal.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `apply(IDocument document)`
`protected Change` `createChange()` Creates the change for this proposal.
`String` `getAdditionalProposalInfo()`
`Object` `getAdditionalProposalInfo(IProgressMonitor monitor)`
`Change` `getChange()` Returns the change that will be executed when the proposal is applied.
`String` `getCommandId()` Returns the id of the command that should invoke this correction proposal.
`IContextInformation` `getContextInformation()`
`String` `getDisplayString()`
`Image` `getImage()`
`String` `getName()` Returns the name of the proposal.
`int` `getRelevance()` Returns the relevance of this completion proposal.
`Point` `getSelection(IDocument document)`
`StyledString` `getStyledDisplayString()`
`protected void` `performChange(IEditorPart activeEditor, IDocument document)` Performs the change associated with this proposal.
`void` `setCommandId(String commandId)` Set the proposal id to allow assigning a shortcut to the correction proposal.
`void` `setDisplayName(String name)` Sets the display name.
`void` `setImage(Image image)` Sets the proposal's image or `null` if no image is desired.
`void` `setRelevance(int relevance)` Sets the relevance.

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

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

### Constructor Detail

#### ChangeCorrectionProposal

    public ChangeCorrectionProposal(String name,
                                    Change change,
                                    int relevance,
                                    Image image)

Constructs a change correction proposal.

Parameters:
  `name` - the name that is displayed in the proposal selection dialog
  `change` - the change that is executed when the proposal is applied or `null` if the change will be created by implementors of `createChange()`
  `relevance` - the relevance of this proposal
  `image` - the image that is displayed for this proposal or `null` if no image is desired

#### ChangeCorrectionProposal

    public ChangeCorrectionProposal(String name,
                                    Change change,
                                    int relevance)

Constructs a change correction proposal. Uses the default image for this proposal.

Parameters:
  `name` - The name that is displayed in the proposal selection dialog.
  `change` - The change that is executed when the proposal is applied or `null` if the change will be created by implementors of `createChange()`.
  `relevance` - The relevance of this proposal.

### Method Detail

#### apply

    public void apply(IDocument document)

Specified by:
  `apply` in interface `ICompletionProposal`

#### performChange

    protected void performChange(IEditorPart activeEditor,
                                 IDocument document)
                          throws CoreException

Performs the change associated with this proposal.

Subclasses may extend, but must call the super implementation.

Parameters:
  `activeEditor` - the editor currently active or `null` if no editor is active
  `document` - the document of the editor currently active or `null` if no editor is visible
Throws:
  `CoreException` - when the invocation of the change failed

#### getAdditionalProposalInfo

    public String getAdditionalProposalInfo()

Specified by:
  `getAdditionalProposalInfo` in interface `ICompletionProposal`

#### getAdditionalProposalInfo

    public Object getAdditionalProposalInfo(IProgressMonitor monitor)

Specified by:
  `getAdditionalProposalInfo` in interface `ICompletionProposalExtension5`

#### getContextInformation

    public IContextInformation getContextInformation()

Specified by:
  `getContextInformation` in interface `ICompletionProposal`

#### getDisplayString

    public String getDisplayString()

Specified by:
  `getDisplayString` in interface `ICompletionProposal`

#### getStyledDisplayString

    public StyledString getStyledDisplayString()

Specified by:
  `getStyledDisplayString` in interface `ICompletionProposalExtension6`

#### getName

    public String getName()

Returns the name of the proposal.

Returns:
  the name of the proposal

#### getImage

    public Image getImage()

Specified by:
  `getImage` in interface `ICompletionProposal`

#### getSelection

    public Point getSelection(IDocument document)

Specified by:
  `getSelection` in interface `ICompletionProposal`

#### setImage

    public void setImage(Image image)

Sets the proposal's image or `null` if no image is desired.

Parameters:
  `image` - the desired image.

#### getChange

    public final Change getChange()
                           throws CoreException

Returns the change that will be executed when the proposal is applied. This method calls `createChange()` to compute the change.

Returns:
  the change for this proposal, can be `null` in rare cases if creation of the change failed
Throws:
  `CoreException` - when the change could not be created

#### createChange

    protected Change createChange()
                           throws CoreException

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.

Returns:
  the created change
Throws:
  `CoreException` - if the creation of the change failed

#### setDisplayName

    public void setDisplayName(String name)

Sets the display name.

Parameters:
  `name` - the name to set

#### getRelevance

    public int getRelevance()

Description copied from interface: `IJavaCompletionProposal`
Returns the relevance of this completion proposal.

The relevance is used to determine if this proposal is more relevant than another proposal.

Specified by:
  `getRelevance` in interface `IJavaCompletionProposal`
Returns:
  the relevance of this completion proposal in the range of [0, 1000]

#### setRelevance

    public void setRelevance(int relevance)

Sets the relevance.

Parameters:
  `relevance` - the relevance to set
See Also:
  `getRelevance()`

#### 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`
Returns:
  the id of the command or `null` if this proposal does not have a command. This id must start with `ICommandAccess.COMMAND_ID_PREFIX` to be recognized as a correction command. In addition, the id must end with `ICommandAccess.ASSIST_SUFFIX` to be recognized as a quick assist command.

#### setCommandId

    public void setCommandId(String commandId)

Set the proposal id to allow assigning a shortcut to the correction proposal.

Parameters:
  `commandId` - The proposal id for this proposal or `null` if no command should be assigned to this proposal.