Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Langer2016-05-12 12:39:05 -0400
committerLaurent Delaigue2016-09-12 11:00:22 -0400
commitd46e8c85b4cdbb7b79c05d43cf77b411dcd9f71a (patch)
treef36a42048a25f5317625c6035b02939765f54095
parent10679ac6b633f8877a0ed83c2cfd6d44ed791cbc (diff)
downloadorg.eclipse.emf.compare-d46e8c85b4cdbb7b79c05d43cf77b411dcd9f71a.tar.gz
org.eclipse.emf.compare-d46e8c85b4cdbb7b79c05d43cf77b411dcd9f71a.tar.xz
org.eclipse.emf.compare-d46e8c85b4cdbb7b79c05d43cf77b411dcd9f71a.zip
Fix and optimize usage of StorageTraversal.getStorages()
StorageTraversal.getStorages() returns a mutable copy of the internal set of storages. This was, however, wrongly communicated its JavaDoc and has hence also been used here and there under the assumption that this is the actual set of storages rather than a copy leading to non-ideal usages. This change fixes the JavaDoc and improves the usages of this method. Change-Id: I556a1fa6e497bdc0852c59515840d4eb9907eb23 Signed-off-by: Philip Langer <planger@eclipsesource.com>
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/CompareTestCase.java14
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/logical/synchronizationmodel/SynchronizationModelDiagnosticTest.java44
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/DependenciesTest.java70
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/TestBug459131.java63
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/EMFResourceMappingMerger.java2
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/IdenticalResourceMinimizer.java28
-rw-r--r--plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/utils/ResourceUtil.java38
-rw-r--r--plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/utils/StorageTraversal.java11
8 files changed, 107 insertions, 163 deletions
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/CompareTestCase.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/CompareTestCase.java
index bf1e4a410..4d9134cdb 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/CompareTestCase.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/CompareTestCase.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (C) 2013, 2015 Obeo and others.
+ * Copyright (C) 2013, 2016 Obeo and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -11,6 +11,7 @@ package org.eclipse.emf.compare.ide.ui.tests;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterators.filter;
import static org.eclipse.emf.ecore.util.EcoreUtil.getAllProperContents;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
@@ -23,14 +24,17 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.compare.ide.ui.tests.workspace.TestProject;
+import org.eclipse.emf.compare.ide.utils.StorageTraversal;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
@@ -303,4 +307,12 @@ public class CompareTestCase {
fileInputStream.close();
fileOutputStream.close();
}
+
+ protected static void assertContainsExclusively(StorageTraversal traversal, IFile... files) {
+ Set<? extends IStorage> storages = traversal.getStorages();
+ assertEquals(files.length, storages.size());
+ for (IFile file : files) {
+ assertTrue(storages.contains(file));
+ }
+ }
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/logical/synchronizationmodel/SynchronizationModelDiagnosticTest.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/logical/synchronizationmodel/SynchronizationModelDiagnosticTest.java
index c3951244e..7eb13d65d 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/logical/synchronizationmodel/SynchronizationModelDiagnosticTest.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/logical/synchronizationmodel/SynchronizationModelDiagnosticTest.java
@@ -22,6 +22,7 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collections;
import java.util.HashSet;
+import java.util.Set;
import org.eclipse.core.internal.resources.ResourceStatus;
import org.eclipse.core.resources.IFile;
@@ -96,12 +97,14 @@ public class SynchronizationModelDiagnosticTest extends CompareTestCase {
new NullProgressMonitor());
/* sanity checks */
- assertEquals(2, synchronizationModel.getLeftTraversal().getStorages().size());
- assertTrue(synchronizationModel.getLeftTraversal().getStorages().contains(left));
- assertTrue(synchronizationModel.getLeftTraversal().getStorages().contains(m2));
+ Set<? extends IStorage> leftStorages = synchronizationModel.getLeftTraversal().getStorages();
+ assertEquals(2, leftStorages.size());
+ assertTrue(leftStorages.contains(left));
+ assertTrue(leftStorages.contains(m2));
- assertEquals(1, synchronizationModel.getRightTraversal().getStorages().size());
- assertTrue(synchronizationModel.getRightTraversal().getStorages().contains(right));
+ Set<? extends IStorage> rightStorages = synchronizationModel.getRightTraversal().getStorages();
+ assertEquals(1, rightStorages.size());
+ assertTrue(rightStorages.contains(right));
/* verify */
Diagnostic diagnostic = synchronizationModel.getDiagnostic();
@@ -139,12 +142,14 @@ public class SynchronizationModelDiagnosticTest extends CompareTestCase {
new NullProgressMonitor());
/* sanity checks */
- assertEquals(2, synchronizationModel.getLeftTraversal().getStorages().size());
- assertTrue(synchronizationModel.getLeftTraversal().getStorages().contains(left));
- assertTrue(synchronizationModel.getLeftTraversal().getStorages().contains(m2));
+ Set<? extends IStorage> leftStorages = synchronizationModel.getLeftTraversal().getStorages();
+ assertEquals(2, leftStorages.size());
+ assertTrue(leftStorages.contains(left));
+ assertTrue(leftStorages.contains(m2));
- assertEquals(1, synchronizationModel.getRightTraversal().getStorages().size());
- assertTrue(synchronizationModel.getRightTraversal().getStorages().contains(right));
+ Set<? extends IStorage> rightStorages = synchronizationModel.getRightTraversal().getStorages();
+ assertEquals(1, rightStorages.size());
+ assertTrue(rightStorages.contains(right));
/* verify */
Diagnostic diagnostic = synchronizationModel.getDiagnostic();
@@ -183,9 +188,9 @@ public class SynchronizationModelDiagnosticTest extends CompareTestCase {
new NullProgressMonitor());
/* sanity checks */
- assertEquals(2, synchronizationModel.getLeftTraversal().getStorages().size());
- IStorage[] storages = Iterators
- .toArray(synchronizationModel.getLeftTraversal().getStorages().iterator(), IStorage.class);
+ Set<? extends IStorage> leftStorages = synchronizationModel.getLeftTraversal().getStorages();
+ assertEquals(2, leftStorages.size());
+ IStorage[] storages = Iterators.toArray(leftStorages.iterator(), IStorage.class);
if (storages[0].equals(m1)) {
assertTrue(storages[1].getFullPath().toString().contains("model2.ecore"));
} else {
@@ -193,8 +198,9 @@ public class SynchronizationModelDiagnosticTest extends CompareTestCase {
assertTrue(storages[0].getFullPath().toString().contains("model2.ecore"));
}
- assertEquals(1, synchronizationModel.getRightTraversal().getStorages().size());
- assertTrue(synchronizationModel.getRightTraversal().getStorages().contains(m3));
+ final Set<? extends IStorage> rightStorages = synchronizationModel.getRightTraversal().getStorages();
+ assertEquals(1, rightStorages.size());
+ assertTrue(rightStorages.contains(m3));
/* verify */
Diagnostic diagnostic = synchronizationModel.getDiagnostic();
@@ -239,12 +245,8 @@ public class SynchronizationModelDiagnosticTest extends CompareTestCase {
new NullProgressMonitor());
/* sanity checks */
- assertEquals(2, synchronizationModel.getLeftTraversal().getStorages().size());
- assertTrue(synchronizationModel.getLeftTraversal().getStorages().contains(m1));
- assertTrue(synchronizationModel.getLeftTraversal().getStorages().contains(m2));
-
- assertEquals(1, synchronizationModel.getRightTraversal().getStorages().size());
- assertTrue(synchronizationModel.getRightTraversal().getStorages().contains(m3));
+ assertContainsExclusively(synchronizationModel.getLeftTraversal(), m1, m2);
+ assertContainsExclusively(synchronizationModel.getRightTraversal(), m3);
/* verify */
Diagnostic diagnostic = synchronizationModel.getDiagnostic();
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/DependenciesTest.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/DependenciesTest.java
index 8f4c1914e..fff1f7f98 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/DependenciesTest.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/DependenciesTest.java
@@ -1,16 +1,17 @@
/*******************************************************************************
- * Copyright (c) 2013 Obeo.
+ * Copyright (c) 2013, 2016 Obeo and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ * Philip Langer - refactoring
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.tests.unit;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import java.io.File;
import org.eclipse.core.resources.IFile;
@@ -97,16 +98,13 @@ public class DependenciesTest extends CompareTestCase {
@Test
public void testScopeNoDependencies() throws Exception {
StorageTraversal traversal = resolver.resolveLocalModel(iFile1, monitor);
- assertEquals(1, traversal.getStorages().size());
- assertTrue(traversal.getStorages().contains(iFile1));
+ assertContainsExclusively(traversal, iFile1);
traversal = resolver.resolveLocalModel(iFile2, monitor);
- assertEquals(1, traversal.getStorages().size());
- assertTrue(traversal.getStorages().contains(iFile2));
+ assertContainsExclusively(traversal, iFile2);
traversal = resolver.resolveLocalModel(iFile3, monitor);
- assertEquals(1, traversal.getStorages().size());
- assertTrue(traversal.getStorages().contains(iFile3));
+ assertContainsExclusively(traversal, iFile3);
}
@Test
@@ -115,14 +113,10 @@ public class DependenciesTest extends CompareTestCase {
save(resourceSet);
StorageTraversal traversal = resolver.resolveLocalModel(iFile1, monitor);
- assertEquals(2, traversal.getStorages().size());
- assertTrue(traversal.getStorages().contains(iFile1));
- assertTrue(traversal.getStorages().contains(iFile2));
+ assertContainsExclusively(traversal, iFile1, iFile2);
traversal = resolver.resolveLocalModel(iFile2, monitor);
- assertEquals(2, traversal.getStorages().size());
- assertTrue(traversal.getStorages().contains(iFile1));
- assertTrue(traversal.getStorages().contains(iFile2));
+ assertContainsExclusively(traversal, iFile1, iFile2);
}
@Test
@@ -134,12 +128,10 @@ public class DependenciesTest extends CompareTestCase {
save(resourceSet);
StorageTraversal traversal = resolver.resolveLocalModel(iFile1, monitor);
- assertEquals(1, traversal.getStorages().size());
- assertTrue(traversal.getStorages().contains(iFile1));
+ assertContainsExclusively(traversal, iFile1);
traversal = resolver.resolveLocalModel(iFile2, monitor);
- assertEquals(1, traversal.getStorages().size());
- assertTrue(traversal.getStorages().contains(iFile2));
+ assertContainsExclusively(traversal, iFile2);
}
@Test
@@ -149,22 +141,13 @@ public class DependenciesTest extends CompareTestCase {
save(resourceSet);
StorageTraversal traversal = resolver.resolveLocalModel(iFile1, monitor);
- assertEquals(3, traversal.getStorages().size());
- assertTrue(traversal.getStorages().contains(iFile1));
- assertTrue(traversal.getStorages().contains(iFile2));
- assertTrue(traversal.getStorages().contains(iFile3));
+ assertContainsExclusively(traversal, iFile1, iFile2, iFile3);
traversal = resolver.resolveLocalModel(iFile2, monitor);
- assertEquals(3, traversal.getStorages().size());
- assertTrue(traversal.getStorages().contains(iFile1));
- assertTrue(traversal.getStorages().contains(iFile2));
- assertTrue(traversal.getStorages().contains(iFile3));
+ assertContainsExclusively(traversal, iFile1, iFile2, iFile3);
traversal = resolver.resolveLocalModel(iFile3, monitor);
- assertEquals(3, traversal.getStorages().size());
- assertTrue(traversal.getStorages().contains(iFile1));
- assertTrue(traversal.getStorages().contains(iFile2));
- assertTrue(traversal.getStorages().contains(iFile3));
+ assertContainsExclusively(traversal, iFile1, iFile2, iFile3);
}
@Test
@@ -174,39 +157,28 @@ public class DependenciesTest extends CompareTestCase {
save(resourceSet);
StorageTraversal traversal = resolver.resolveLocalModel(iFile1, monitor);
- assertEquals(3, traversal.getStorages().size());
- assertTrue(traversal.getStorages().contains(iFile1));
- assertTrue(traversal.getStorages().contains(iFile2));
- assertTrue(traversal.getStorages().contains(iFile3));
+ assertContainsExclusively(traversal, iFile1, iFile2, iFile3);
breakCrossReferences(resource2, resource1);
save(resourceSet);
traversal = resolver.resolveLocalModel(iFile1, monitor);
- assertEquals(1, traversal.getStorages().size());
- assertTrue(traversal.getStorages().contains(iFile1));
+ assertContainsExclusively(traversal, iFile1);
traversal = resolver.resolveLocalModel(iFile2, monitor);
- assertEquals(2, traversal.getStorages().size());
- assertTrue(traversal.getStorages().contains(iFile2));
- assertTrue(traversal.getStorages().contains(iFile3));
+ assertContainsExclusively(traversal, iFile2, iFile3);
breakCrossReferences(resource3, resource2);
makeCrossReference(resource3, resource1);
save(resourceSet);
traversal = resolver.resolveLocalModel(iFile1, monitor);
- assertEquals(2, traversal.getStorages().size());
- assertTrue(traversal.getStorages().contains(iFile1));
- assertTrue(traversal.getStorages().contains(iFile3));
+ assertContainsExclusively(traversal, iFile1, iFile3);
traversal = resolver.resolveLocalModel(iFile2, monitor);
- assertEquals(1, traversal.getStorages().size());
- assertTrue(traversal.getStorages().contains(iFile2));
+ assertContainsExclusively(traversal, iFile2);
traversal = resolver.resolveLocalModel(iFile3, monitor);
- assertEquals(2, traversal.getStorages().size());
- assertTrue(traversal.getStorages().contains(iFile1));
- assertTrue(traversal.getStorages().contains(iFile3));
+ assertContainsExclusively(traversal, iFile1, iFile3);
}
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/TestBug459131.java b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/TestBug459131.java
index 4ea46e83f..5d8375901 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/TestBug459131.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui.tests/src/org/eclipse/emf/compare/ide/ui/tests/unit/TestBug459131.java
@@ -11,10 +11,6 @@
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.tests.unit;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import java.io.File;
import java.net.URL;
@@ -28,7 +24,6 @@ import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
import org.eclipse.emf.compare.ide.ui.logical.IModelResolver;
import org.eclipse.emf.compare.ide.ui.logical.SynchronizationModel;
import org.eclipse.emf.compare.ide.ui.tests.CompareTestCase;
-import org.eclipse.emf.compare.ide.utils.StorageTraversal;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -125,37 +120,16 @@ public class TestBug459131 extends CompareTestCase {
// 1 change in R2 fragment and 1 change in R3 fragment
SynchronizationModel syncModel = resolver.resolveLocalModels(iLeftFile1, iRightFile1, null, monitor);
-
- StorageTraversal leftTraversal = syncModel.getLeftTraversal();
- assertEquals(3, leftTraversal.getStorages().size());
- assertTrue(leftTraversal.getStorages().contains(iLeftFile1));
- assertTrue(leftTraversal.getStorages().contains(iLeftFile2));
- assertTrue(leftTraversal.getStorages().contains(iLeftFile3));
-
- StorageTraversal rightTraversal = syncModel.getRightTraversal();
- assertEquals(3, rightTraversal.getStorages().size());
- assertTrue(rightTraversal.getStorages().contains(iRightFile1));
- assertTrue(rightTraversal.getStorages().contains(iRightFile2));
- assertTrue(rightTraversal.getStorages().contains(iRightFile3));
+ assertContainsExclusively(syncModel.getLeftTraversal(), iLeftFile1, iLeftFile2, iLeftFile3);
+ assertContainsExclusively(syncModel.getRightTraversal(), iRightFile1, iRightFile2, iRightFile3);
// Update R3 right model
// 1 change in R2 fragment and no change in R3 fragment
iRightFile3.setContents(iLeftFile3.getContents(), IResource.FORCE, monitor);
syncModel = resolver.resolveLocalModels(iLeftFile1, iRightFile1, null, monitor);
-
- leftTraversal = syncModel.getLeftTraversal();
- assertEquals(3, leftTraversal.getStorages().size());
- assertTrue(leftTraversal.getStorages().contains(iLeftFile1));
- assertTrue(leftTraversal.getStorages().contains(iLeftFile2));
- assertTrue(leftTraversal.getStorages().contains(iLeftFile3));
-
- rightTraversal = syncModel.getRightTraversal();
- assertEquals(3, rightTraversal.getStorages().size());
- assertTrue(rightTraversal.getStorages().contains(iRightFile1));
- assertTrue(rightTraversal.getStorages().contains(iRightFile2));
- assertTrue(rightTraversal.getStorages().contains(iRightFile3));
-
+ assertContainsExclusively(syncModel.getLeftTraversal(), iLeftFile1, iLeftFile2, iLeftFile3);
+ assertContainsExclusively(syncModel.getRightTraversal(), iRightFile1, iRightFile2, iRightFile3);
}
/**
@@ -229,35 +203,14 @@ public class TestBug459131 extends CompareTestCase {
// 1 change in R2 fragment and 1 change in R3 fragment
SynchronizationModel syncModel = resolver.resolveLocalModels(iLeftFile4, iRightFile4, null, monitor);
-
- StorageTraversal leftTraversal = syncModel.getLeftTraversal();
- assertEquals(3, leftTraversal.getStorages().size());
- assertTrue(leftTraversal.getStorages().contains(iLeftFile4));
- assertTrue(leftTraversal.getStorages().contains(iLeftFile5));
- assertTrue(leftTraversal.getStorages().contains(iLeftFile6));
-
- StorageTraversal rightTraversal = syncModel.getRightTraversal();
- assertEquals(3, rightTraversal.getStorages().size());
- assertTrue(rightTraversal.getStorages().contains(iRightFile4));
- assertTrue(rightTraversal.getStorages().contains(iRightFile5));
- assertTrue(rightTraversal.getStorages().contains(iRightFile6));
+ assertContainsExclusively(syncModel.getLeftTraversal(), iLeftFile4, iLeftFile5, iLeftFile6);
+ assertContainsExclusively(syncModel.getRightTraversal(), iRightFile4, iRightFile5, iRightFile6);
// Brake dependency between R5 & R6 right models.
iRightFile5.setContents(newIRightFile5.getContents(), IResource.FORCE, monitor);
syncModel = resolver.resolveLocalModels(iLeftFile4, iRightFile4, null, monitor);
-
- leftTraversal = syncModel.getLeftTraversal();
- assertEquals(3, leftTraversal.getStorages().size());
- assertTrue(leftTraversal.getStorages().contains(iLeftFile4));
- assertTrue(leftTraversal.getStorages().contains(iLeftFile5));
- assertTrue(leftTraversal.getStorages().contains(iLeftFile6));
-
- rightTraversal = syncModel.getRightTraversal();
- assertEquals(2, rightTraversal.getStorages().size());
- assertTrue(rightTraversal.getStorages().contains(iRightFile4));
- assertTrue(rightTraversal.getStorages().contains(iRightFile5));
- assertFalse(rightTraversal.getStorages().contains(iRightFile6));
-
+ assertContainsExclusively(syncModel.getLeftTraversal(), iLeftFile4, iLeftFile5, iLeftFile6);
+ assertContainsExclusively(syncModel.getRightTraversal(), iRightFile4, iRightFile5);
}
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/EMFResourceMappingMerger.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/EMFResourceMappingMerger.java
index 1ec7b6e3a..b4a33adf0 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/EMFResourceMappingMerger.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/EMFResourceMappingMerger.java
@@ -296,7 +296,7 @@ public class EMFResourceMappingMerger implements IResourceMappingMerger {
* The traversal to remove non-existing storages from.
*/
private void removeNonExistingStorages(StorageTraversal traversal) {
- for (IStorage storage : Sets.newHashSet(traversal.getStorages())) {
+ for (IStorage storage : traversal.getStorages()) {
if (storage instanceof IFile && !((IFile)storage).exists()) {
traversal.removeStorage(storage);
}
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/IdenticalResourceMinimizer.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/IdenticalResourceMinimizer.java
index 9e5d53ec3..babe114b8 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/IdenticalResourceMinimizer.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/IdenticalResourceMinimizer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013, 2015 Obeo.
+ * Copyright (c) 2013, 2016 Obeo.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,13 +7,12 @@
*
* Contributors:
* Obeo - initial API and implementation
+ * Philip Langer - fix use of StorageTraversal.getStorages()
*******************************************************************************/
package org.eclipse.emf.compare.ide.ui.internal.logical;
import static org.eclipse.emf.compare.ide.utils.ResourceUtil.binaryIdentical;
-import com.google.common.collect.Sets;
-
import java.util.Iterator;
import java.util.Set;
@@ -53,18 +52,19 @@ public class IdenticalResourceMinimizer implements IModelMinimizer {
final StorageTraversal rightTraversal = syncModel.getRightTraversal();
final StorageTraversal originTraversal = syncModel.getOriginTraversal();
- final boolean threeWay = !originTraversal.getStorages().isEmpty();
- // Copy the sets to update them as we go.
- final Set<IStorage> leftCopy = Sets.newLinkedHashSet(leftTraversal.getStorages());
- final Set<IStorage> rightCopy = Sets.newLinkedHashSet(rightTraversal.getStorages());
- final Set<IStorage> originCopy = Sets.newLinkedHashSet(originTraversal.getStorages());
+ // StorageTraversal.getStorages() already creates a mutable copy. To change the underlying set, we
+ // need to use StorageTraversal.removeStorage().
+ final Set<? extends IStorage> leftCopy = leftTraversal.getStorages();
+ final Set<? extends IStorage> rightCopy = rightTraversal.getStorages();
+ final Set<? extends IStorage> originCopy = originTraversal.getStorages();
+
+ final boolean threeWay = !originCopy.isEmpty();
SubMonitor subMonitor = progess.newChild(98).setWorkRemaining(leftCopy.size());
for (IStorage left : leftCopy) {
final IStorage right = removeLikeNamedStorageFrom(left, rightCopy);
if (right != null && threeWay) {
final IStorage origin = removeLikeNamedStorageFrom(left, originCopy);
-
if (origin != null && equals(left, right, origin)) {
leftTraversal.removeStorage(left);
rightTraversal.removeStorage(right);
@@ -75,10 +75,10 @@ public class IdenticalResourceMinimizer implements IModelMinimizer {
rightTraversal.removeStorage(right);
} else if (right == null && isIgnoredStorage(left)) {
/*
- * This has no match and is in plugins. We would detect an insane number of false positives on
- * it (every element "added"), so remove it from the scope.
+ * Left has no match in right and is in plugins, so remove it from the scope. Otherwise, we
+ * would unnecessarily include added models that should be ignored.
*/
- leftTraversal.getStorages().remove(left);
+ leftTraversal.removeStorage(left);
}
subMonitor.worked(1);
}
@@ -157,9 +157,9 @@ public class IdenticalResourceMinimizer implements IModelMinimizer {
* @return The first storage from the set of candidates that matches the {@code reference}, if any.
* <code>null</code> if none match.
*/
- protected IStorage removeLikeNamedStorageFrom(IStorage reference, Set<IStorage> candidates) {
+ protected IStorage removeLikeNamedStorageFrom(IStorage reference, Set<? extends IStorage> candidates) {
final String referenceName = reference.getName();
- final Iterator<IStorage> candidatesIterator = candidates.iterator();
+ final Iterator<? extends IStorage> candidatesIterator = candidates.iterator();
while (candidatesIterator.hasNext()) {
final IStorage candidate = candidatesIterator.next();
final String candidateName = candidate.getName();
diff --git a/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/utils/ResourceUtil.java b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/utils/ResourceUtil.java
index 69d74e8d2..fa437a633 100644
--- a/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/utils/ResourceUtil.java
+++ b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/utils/ResourceUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2015 Obeo and others.
+ * Copyright (c) 2012, 2016 Obeo and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* Obeo - initial API and implementation
* Michael Borkowski - bug 467677
+ * Philip Langer - optimize use of StorageTraversal.getStorages()
*******************************************************************************/
package org.eclipse.emf.compare.ide.utils;
@@ -473,8 +474,16 @@ public final class ResourceUtil {
// Change "platform:/resource/relativePath" URIs of non-workspace resources into "file:/absolutePath"
// URIs
+ final Set<? extends IStorage> leftStorages = leftTraversal.getStorages();
+ final Set<? extends IStorage> rightStorages = rightTraversal.getStorages();
+ final Set<? extends IStorage> originStorages;
+ if (originTraversal != null) {
+ originStorages = originTraversal.getStorages();
+ } else {
+ originStorages = null;
+ }
for (Resource resource : nonWsResources) {
- String absolutePath = getAbsolutePath(resource, leftTraversal, rightTraversal, originTraversal);
+ String absolutePath = getAbsolutePath(resource, leftStorages, rightStorages, originStorages);
URI fileURI = URI.createFileURI(absolutePath);
resource.setURI(fileURI);
}
@@ -490,24 +499,23 @@ public final class ResourceUtil {
*
* @param resource
* The resource for which we seek an absolute path.
- * @param leftTraversal
- * The traversal corresponding to the left side.
- * @param rightTraversal
- * The traversal corresponding to the right side.
- * @param originTraversal
- * The traversal corresponding to the common ancestor of both other side. Can be
- * <code>null</code>.
+ * @param leftStorages
+ * The storages of the left traversal.
+ * @param rightStorages
+ * The storages of the right traversal.
+ * @param originStorages
+ * The storages of the common ancestor traversal. Can be <code>null</code>.
* @return the absolute path of the given resource if found, null otherwise.
*/
- private static String getAbsolutePath(Resource resource, StorageTraversal leftTraversal,
- StorageTraversal rightTraversal, StorageTraversal originTraversal) {
+ private static String getAbsolutePath(Resource resource, Set<? extends IStorage> leftStorages,
+ Set<? extends IStorage> rightStorages, Set<? extends IStorage> originStorages) {
URI uri = resource.getURI();
- String absolutePath = getAbsolutePath(uri, leftTraversal.getStorages());
+ String absolutePath = getAbsolutePath(uri, leftStorages);
if (absolutePath == null) {
- absolutePath = getAbsolutePath(uri, rightTraversal.getStorages());
+ absolutePath = getAbsolutePath(uri, rightStorages);
}
- if (absolutePath == null && originTraversal != null) {
- absolutePath = getAbsolutePath(uri, originTraversal.getStorages());
+ if (absolutePath == null && originStorages != null) {
+ absolutePath = getAbsolutePath(uri, originStorages);
}
return absolutePath;
}
diff --git a/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/utils/StorageTraversal.java b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/utils/StorageTraversal.java
index 857cfdd07..4f903b16a 100644
--- a/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/utils/StorageTraversal.java
+++ b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/utils/StorageTraversal.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2015 Obeo.
+ * Copyright (c) 2011, 2016 Obeo and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* Obeo - initial API and implementation
+ * Philip Langer - improve JavaDoc
*******************************************************************************/
package org.eclipse.emf.compare.ide.utils;
@@ -67,13 +68,9 @@ public class StorageTraversal implements IAdaptable, IDiagnosable {
}
/**
- * Returns the set of resources that are part of this traversal.
- * <p>
- * Note that this is the original set, and that any modification on the returned {@link Set} will affect
- * this traversal.
- * </p>
+ * Returns a mutable copy of the set of resources that are part of this traversal.
*
- * @return The set of resources that are part of this traversal.
+ * @return A mutable copy of the set of resources that are part of this traversal.
*/
public Set<? extends IStorage> getStorages() {
return new LinkedHashSet<IStorage>(storages);

Back to the top