Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » RenameParticipant and change conflicts
RenameParticipant and change conflicts [message #235774] Sun, 10 September 2006 10:18 Go to next message
Eclipse UserFriend
Situation. I have some type A1 that uses type B1. When user renames
A1 to A2, my rename participant should rename B1 to B2. However my
B1->B2 rename modifies also A1 (renamed to A2), so I see following
exception:


org.eclipse.text.edits.MalformedTreeException: End position lies outside
document range
at
org.eclipse.text.edits.TextEditProcessor.checkIntegrityDo(Te xtEditProcessor.java:169)


I've read in documentation that in 3.1 it is possible to change same
text file in participant and getTextChange() should be used. However I
don't understand how I should use it. I don't see any example of its
invocation in Eclipse itself. :-(

So, is it possible at all? Can you give me example or point where I
can get example?

To rename type B2 I use following method:

private static Change createTypeRenameChange(IType type, String
newName, IProgressMonitor pm) throws CoreException {
JavaRenameProcessor renameProcessor = new RenameTypeProcessor(type);
renameProcessor.setNewElementName(newName);
//
RenameRefactoring renameRefactoring = new
RenameRefactoring(renameProcessor);
RefactoringStatus status = renameRefactoring.checkAllConditions(pm);
if (status.hasError()) {
System.out.println("Hm...");
}
//
return renameRefactoring.createChange(pm);
}

May be problem with this method?



--
SY, Konstantin.
Advanced Eclipse SWT Designer (http://www.swt-designer.com)
Re: RenameParticipant and change conflicts [message #235780 is a reply to message #235774] Mon, 11 September 2006 03:35 Go to previous message
Eclipse UserFriend
Konstantin Scheglov wrote:

Ok, I think I found some solution. Can anybody comment if it is good/bad?


/**
* Merges given change (possible composite) with currently existing
text changes (from main refactoring).
* Removes merged parts from given change.
*/
private void mergeTextChange(Change change) throws JavaModelException {
if (change instanceof CompositeChange) {
CompositeChange compositeChange = (CompositeChange) change;
Change[] changeChildren = compositeChange.getChildren();
for (int i = 0; i < changeChildren.length; i++) {
Change changeChild = changeChildren[i];
mergeTextChange(changeChild);
}
} else if (change instanceof TextFileChange) {
TextFileChange textFileChange = (TextFileChange) change;
// if we have existing change for this file, merge text edits
TextChange existingTextChange = getTextChange(textFileChange.getFile());
if (existingTextChange != null) {
TextEdit rootEdit = textFileChange.getEdit();
existingTextChange.addEdit(rootEdit);
((CompositeChange) textFileChange.getParent()).remove(textFileChange);
}
}
}



> Situation. I have some type A1 that uses type B1. When user renames A1
> to A2, my rename participant should rename B1 to B2. However my B1->B2
> rename modifies also A1 (renamed to A2), so I see following exception:
>
>
> org.eclipse.text.edits.MalformedTreeException: End position lies outside
> document range
> at
> org.eclipse.text.edits.TextEditProcessor.checkIntegrityDo(Te xtEditProcessor.java:169)
>
>
>
> I've read in documentation that in 3.1 it is possible to change same
> text file in participant and getTextChange() should be used. However I
> don't understand how I should use it. I don't see any example of its
> invocation in Eclipse itself. :-(
>
> So, is it possible at all? Can you give me example or point where I
> can get example?
>
> To rename type B2 I use following method:
>
> private static Change createTypeRenameChange(IType type, String
> newName, IProgressMonitor pm) throws CoreException {
> JavaRenameProcessor renameProcessor = new
> RenameTypeProcessor(type);
> renameProcessor.setNewElementName(newName);
> //
> RenameRefactoring renameRefactoring = new
> RenameRefactoring(renameProcessor);
> RefactoringStatus status =
> renameRefactoring.checkAllConditions(pm);
> if (status.hasError()) {
> System.out.println("Hm...");
> }
> //
> return renameRefactoring.createChange(pm);
> }
>
> May be problem with this method?
>
>
>


--
SY, Konstantin.
Advanced Eclipse SWT Designer (http://www.swt-designer.com)
Previous Topic:"ASTRewrite removes comments" state
Next Topic:University Research: Survey about searching for open source code on the Internet
Goto Forum:
  


Current Time: Sun Jul 27 07:39:34 EDT 2025

Powered by FUDForum. Page generated in 0.19727 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top