Skip to content

Commit a6bd9a5

Browse files
committed
Fixes corruption of e4xmi files when class is renamed
The corruption happens in a setup with a top level Maven project and plug-in projects in sub directories (eg bundles). If the name of a Java handler class is renamed in the Java file the e4xmi file is found twice with full workspace path plug-in project path This leads to 2 changes in one e4xmi file with the same text, offset and length. If the old and new names are of different length the corruption occurs. This fix skips the change if it is already included for renaming.
1 parent 9d2e85f commit a6bd9a5

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

e4tools/bundles/org.eclipse.e4.tools.emf.editor3x/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Bundle-Name
44
Bundle-SymbolicName: org.eclipse.e4.tools.emf.editor3x;singleton:=true
5-
Bundle-Version: 4.10.200.qualifier
5+
Bundle-Version: 4.10.300.qualifier
66
Bundle-RequiredExecutionEnvironment: JavaSE-21
77
Require-Bundle: org.eclipse.ui;bundle-version="3.6.0",
88
org.eclipse.core.runtime;bundle-version="3.29.0",

e4tools/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x/refactorparticipants/RefactorParticipantDelegate.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
******************************************************************************/
1616
package org.eclipse.e4.tools.emf.editor3x.refactorparticipants;
1717

18+
import java.net.URI;
1819
import java.util.HashMap;
1920
import java.util.Map;
21+
import java.util.Objects;
2022

2123
import org.eclipse.core.resources.IFile;
2224
import org.eclipse.core.resources.IProject;
@@ -35,6 +37,7 @@
3537
import org.eclipse.search.ui.text.FileTextSearchScope;
3638
import org.eclipse.text.edits.MultiTextEdit;
3739
import org.eclipse.text.edits.ReplaceEdit;
40+
import org.eclipse.text.edits.TextEdit;
3841
import org.eclipse.text.edits.TextEditGroup;
3942

4043
@SuppressWarnings("restriction")
@@ -62,6 +65,10 @@ public static CompositeChange createChange(IProgressMonitor pProgressMonitor, fi
6265
@Override
6366
public boolean acceptPatternMatch(TextSearchMatchAccess matchAccess) throws CoreException {
6467
final IFile file = matchAccess.getFile();
68+
if (isChangeAlreadyPresent(file, matchAccess)) {
69+
return false;
70+
}
71+
6572
TextFileChange change = changes.get(file);
6673

6774
if (change == null) {
@@ -103,8 +110,40 @@ public boolean acceptPatternMatch(TextSearchMatchAccess matchAccess) throws Core
103110
change.addEdit(edit);
104111
change.addTextEditGroup(new TextEditGroup(E4_MODEL_CHANGES,
105112
edit));
113+
106114
return true;
107115
}
116+
117+
/**
118+
* Tests whether the change created with the given {@link IFile} and
119+
* the given {@link TextSearchMatchAccess} is already present in the
120+
* {@code changes} map.
121+
*
122+
* @param file
123+
* the file that will be changed
124+
* @param ma
125+
* provides offset and length for the change
126+
* @return true if the change is already present and the location of
127+
* the file is not null otherwise false
128+
*/
129+
private boolean isChangeAlreadyPresent(IFile file, TextSearchMatchAccess ma) {
130+
final URI newFileLocation = file.getLocationURI();
131+
return newFileLocation != null && changes.entrySet().stream() //
132+
.anyMatch(e -> {
133+
final URI presentFileLocation = e.getValue().getFile().getLocationURI();
134+
for (final TextEdit te : e.getValue().getEdit().getChildren()) {
135+
if (te instanceof final ReplaceEdit re) {
136+
if (re.getLength() == ma.getMatchLength()
137+
&& re.getOffset() == ma.getMatchOffset()
138+
&& Objects.equals(re.getText(), pModel.getNewTextCurrentIndex())
139+
&& Objects.equals(newFileLocation, presentFileLocation)) {
140+
return true;
141+
}
142+
}
143+
}
144+
return false;
145+
});
146+
}
108147
};
109148

110149
CompositeChange result;

0 commit comments

Comments
 (0)