Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was able to get my code working by using createPreChange(...). This allows me to return a change which is executed on the source BEFORE the main refactoring is performed. This means that the changes computed by my code are still accurate at the time when they are actually applied.</p> <p><a href="http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fltk%2Fcore%2Frefactoring%2Fparticipants%2FRefactoringParticipant.html" rel="nofollow">http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fltk%2Fcore%2Frefactoring%2Fparticipants%2FRefactoringParticipant.html</a></p> <p><strong>EDIT</strong> : Using createPreChange(...) was really just a workaround as my change could still conflict with another PreChange. I have come up with a better solution by going back to using createChange(...) and calling getTextChange(...) to get the existing text edits object and adding my edits to this object. This seems to make the offsets work correctly.</p> <pre><code>public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException { ICompilationUnit unit = element.getCompilationUnit(); TextChange change = getTextChange(unit); // Failed to find existing change to add our changes to if (change == null) return null; // Find the AST version of the method being changed CompilationUnit astCompUnit = parse(unit, pm); ASTNode astElement = NodeFinder.perform(astCompUnit, element.getNameRange()); MethodDeclaration astMethod = (MethodDeclaration)getParent(astElement, MethodDeclaration.class); // Visit the contents of the method to find changes to make String newName = getArguments().getNewName(); List&lt;TraceFnFixOperation&gt; ops = new ArrayList&lt;TraceFnFixOperation&gt;(1); TraceFnCtorFinder finder = new TraceFnCtorFinder(newName, ops); astMethod.accept(finder); // Add identified edits to the overall change for (TraceFnFixOperation op : ops) { change.addEdit(new ReplaceEdit(op.startPosition, op.length, "\"" + op.methodName + "\"")); } // Don't return a dedicated change return null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload