Skip to content

Commit c15f2c8

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 the combination of attributes (file, text, offset, length) is already included for renaming.
1 parent d2ec358 commit c15f2c8

2 files changed

Lines changed: 32 additions & 4 deletions

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: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
******************************************************************************/
1616
package org.eclipse.e4.tools.emf.editor3x.refactorparticipants;
1717

18+
import java.net.URI;
1819
import java.util.HashMap;
20+
import java.util.HashSet;
1921
import java.util.Map;
22+
import java.util.Set;
2023

2124
import org.eclipse.core.resources.IFile;
2225
import org.eclipse.core.resources.IProject;
@@ -57,11 +60,22 @@ public static CompositeChange createChange(IProgressMonitor pProgressMonitor, fi
5760
final FileTextSearchScope scope = FileTextSearchScope.newWorkspaceScope(filenames, false);
5861

5962
final Map<IFile, TextFileChange> changes = new HashMap<>();
63+
final Set<ChangeAttributes> uniqueChangeAttributes = new HashSet<>();
6064
final TextSearchRequestor searchRequestor = new TextSearchRequestor() {
6165

6266
@Override
6367
public boolean acceptPatternMatch(TextSearchMatchAccess matchAccess) throws CoreException {
6468
final IFile file = matchAccess.getFile();
69+
70+
final ChangeAttributes changeAttributes = new ChangeAttributes(
71+
file.getLocationURI(),
72+
pModel.getNewTextCurrentIndex(),
73+
matchAccess.getMatchOffset(),
74+
matchAccess.getMatchLength());
75+
if (!uniqueChangeAttributes.add(changeAttributes)) {
76+
return false;
77+
}
78+
6579
TextFileChange change = changes.get(file);
6680

6781
if (change == null) {
@@ -97,12 +111,13 @@ public boolean acceptPatternMatch(TextSearchMatchAccess matchAccess) throws Core
97111
}
98112

99113
final ReplaceEdit edit = new ReplaceEdit(
100-
matchAccess.getMatchOffset(),
101-
matchAccess.getMatchLength(),
102-
pModel.getNewTextCurrentIndex());
114+
changeAttributes.offset(),
115+
changeAttributes.length(),
116+
changeAttributes.text());
103117
change.addEdit(edit);
104118
change.addTextEditGroup(new TextEditGroup(E4_MODEL_CHANGES,
105119
edit));
120+
106121
return true;
107122
}
108123
};
@@ -131,4 +146,17 @@ public boolean acceptPatternMatch(TextSearchMatchAccess matchAccess) throws Core
131146
}
132147
return result;
133148
}
149+
150+
/**
151+
* This record contains attributes for a single change. A change has to be
152+
* unique.
153+
* <p>
154+
* The {@code location} is an {@link IFile#getLocationURI()}, which may be
155+
* {@code null} for files without a local file-system location. A
156+
* {@code null} location is treated like any other value: two records with
157+
* {@code null} locations and otherwise equal fields are considered
158+
* duplicates. For e4xmi files on disk this case does not arise in practice.
159+
*/
160+
private static record ChangeAttributes(URI location, String text, int offset, int length) {
161+
}
134162
}

0 commit comments

Comments
 (0)