ASTRewrite for QuickFix: how to place the cursor?
I am working on an Eclipse plugin and building a QuickFix using ASTRewrite. In short, it was built as follows:
public class MyQFXProcessor implements IQuickFixProcessor {
public IJavaCompletionProposal[] getCorrections(IInvocationContext context,
IProblemLocation[] locations) {
AST ast = context.getASTRoot().getAST();
ASTRewrite rw = ASTRewrite.create(ast);
ASTNode replacement = ast.newSimpleName("Test");
rewrite.replace(context.getCoveringNode(), replacement);
IJavaCompletionProposal p = new ASTRewriteCorrectionProposal("My QFX",
context.getCompilationUnit(), rw, 10);
return new IJavaCompletionProposal[]{p};
}
}
So far, that's fine. But something has not been achieved yet - setting the desired cursor position after applying the sentence. For example, this is how it was solved in the JDT to quickly fix the arguments:
I think there must be an API for this, because Eclipse uses this type of behavior for different use cases (in autocomplete among others). Does anyone know how to implement this?
source to share
You can check the internal implementation and usage org.eclipse.jdt.internal.ui.text.correction.proposals.LinkedCorrectionProposal
, which sets the end position of the bound mode in quick fix or quick help with org.eclipse.jdt.internal.ui.text.correction.proposals.LinkedCorrectionProposal.setEndPosition(ITrackedNodePosition position)
.
source to share