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

## Class ASTRewriteCorrectionProposal

- 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
      - - org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal

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

    public class ASTRewriteCorrectionProposal
    extends CUCorrectionProposal

A proposal for quick fixes and quick assists that works on an AST rewrite. Either a rewrite is directly passed in the constructor or the method `getRewrite()` is overridden to provide the AST rewrite that is evaluated on the document when the proposal is applied.

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
`ASTRewriteCorrectionProposal​(String name, ICompilationUnit cu, ASTRewrite rewrite, int relevance)` Constructs an AST rewrite correction proposal.
`ASTRewriteCorrectionProposal​(String name, ICompilationUnit cu, ASTRewrite rewrite, int relevance, Image image)` Constructs an AST rewrite correction proposal.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected void` `addEdits​(IDocument document, TextEdit editRoot)` Called when the `CompilationUnitChange` is initialized.
`ImportRewrite` `createImportRewrite​(CompilationUnit astRoot)` Creates and sets the import rewrite used for this compilation unit.
`ImportRewrite` `getImportRewrite()` Returns the import rewrite used for this compilation unit.
`protected ASTRewrite` `getRewrite()` Returns the rewrite that has been passed in the constructor.
`void` `setImportRewrite​(ImportRewrite rewrite)` Sets the import rewrite used for this compilation unit.

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

`apply, createChange, createTextChange, didOpenEditor, getAdditionalProposalInfo, getCompilationUnit, getPreviewContent, getTextChange, 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

#### ASTRewriteCorrectionProposal

    public ASTRewriteCorrectionProposal​(String name,
                                        ICompilationUnit cu,
                                        ASTRewrite rewrite,
                                        int relevance,
                                        Image image)

Constructs an AST rewrite correction proposal.

Parameters:
  `name` - the display name of the proposal
  `cu` - the compilation unit that is modified
  `rewrite` - the AST rewrite that is invoked when the proposal is applied or `null` if `getRewrite()` is overridden
  `relevance` - the relevance of this proposal
  `image` - the image that is displayed for this proposal or `null` if no image is desired

#### ASTRewriteCorrectionProposal

    public ASTRewriteCorrectionProposal​(String name,
                                        ICompilationUnit cu,
                                        ASTRewrite rewrite,
                                        int relevance)

Constructs an AST rewrite correction proposal. Uses the default image for this proposal.

Parameters:
  `name` - the display name of the proposal
  `cu` - the compilation unit that is modified
  `rewrite` - the AST rewrite that is invoked when the proposal is applied or `null` if `getRewrite()` is overridden
  `relevance` - The relevance of this proposal

### Method Detail

#### getImportRewrite

    public ImportRewrite getImportRewrite()

Returns the import rewrite used for this compilation unit.

Returns:
  the import rewrite or `null` if no import rewrite has been set
Restriction:
  This method is not intended to be re-implemented or extended by clients.

#### setImportRewrite

    public void setImportRewrite​(ImportRewrite rewrite)

Sets the import rewrite used for this compilation unit.

Parameters:
  `rewrite` - the import rewrite
Restriction:
  This method is not intended to be re-implemented or extended by clients.

#### createImportRewrite

    public ImportRewrite createImportRewrite​(CompilationUnit astRoot)

Creates and sets the import rewrite used for this compilation unit.

Parameters:
  `astRoot` - the AST for the current CU
Returns:
  the created import rewrite
Restriction:
  This method is not intended to be re-implemented or extended by clients.

#### addEdits

    protected void addEdits​(IDocument document,
                            TextEdit editRoot)
                     throws CoreException

Description copied from class: `CUCorrectionProposal`
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

Overrides:
  `addEdits` in class `CUCorrectionProposal`
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.

#### getRewrite

    protected ASTRewrite getRewrite()
                             throws CoreException

Returns the rewrite that has been passed in the constructor. Implementors can override this method to create the rewrite lazily. This method will only be called once.

Returns:
  the rewrite to be used
Throws:
  `CoreException` - when the rewrite could not be created