diff options
| author | Mickael LANOE | 2014-10-29 10:43:37 +0000 |
|---|---|---|
| committer | Laurent Redor | 2014-11-06 08:50:03 +0000 |
| commit | 598005f9b99bcdb0446393b899f217a783f5754e (patch) | |
| tree | daa78a378380e0a7d84ad09533197e22404af9a9 | |
| parent | 9cd34d12a5fe4d235e9d8ad95e987e556dfb3155 (diff) | |
| download | org.eclipse.sirius-598005f9b99bcdb0446393b899f217a783f5754e.tar.gz org.eclipse.sirius-598005f9b99bcdb0446393b899f217a783f5754e.tar.xz org.eclipse.sirius-598005f9b99bcdb0446393b899f217a783f5754e.zip | |
The anonymous class in
"DAnalysisSessionImpl.getSemanticCrossReferencer()" is replaced by the
new class "SessionLazyCrossReferencer".
The method
"createSemanticCrossReferencer()" is added to instantiate the
"SessionLazyCrossReferencer" and can be overridden to allow the creation
of a specific ECrossReferenceAdapter
The JUnit test "SiriusControlAndCrossReferenceTest" is modified to allow
the use of semantic cross referencer without internal member class.
This commit is a cherry-peak of fix of bug 449045.
Bug: 450227
Change-Id: Iafa3e0b59e6fd3892319b7c6155403f6b102ca36
Signed-off-by: Mickael LANOE <mickael.lanoe@obeo.fr>
3 files changed, 100 insertions, 38 deletions
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/tools/SiriusControlAndCrossReferenceTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/tools/SiriusControlAndCrossReferenceTest.java index 347d149548..2ed941298e 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/tools/SiriusControlAndCrossReferenceTest.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/api/tools/SiriusControlAndCrossReferenceTest.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.sirius.tests.unit.api.tools; -import java.lang.reflect.Field; import java.util.Collections; import org.eclipse.core.runtime.NullProgressMonitor; @@ -20,13 +19,14 @@ import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.util.ECrossReferenceAdapter; import org.eclipse.sirius.business.api.control.SiriusControlCommand; import org.eclipse.sirius.business.api.dialect.DialectManager; import org.eclipse.sirius.business.api.session.danalysis.DAnalysisSession; import org.eclipse.sirius.business.api.session.danalysis.SimpleAnalysisSelector; -import org.eclipse.sirius.common.tools.api.util.LazyCrossReferencer; import org.eclipse.sirius.common.tools.api.util.ReflectionHelper; import org.eclipse.sirius.ext.base.Option; +import org.eclipse.sirius.tests.SiriusTestsPlugin; import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase; import org.eclipse.sirius.tools.api.command.ui.NoUICallback; import org.eclipse.sirius.tools.api.command.ui.UICallBack; @@ -34,8 +34,6 @@ import org.eclipse.sirius.viewpoint.DAnalysisSessionEObject; import org.eclipse.sirius.viewpoint.DRepresentation; import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; -import org.eclipse.sirius.tests.SiriusTestsPlugin; - public class SiriusControlAndCrossReferenceTest extends SiriusDiagramTestCase { private static final String PATH = "/data/unit/control/vp-2824/"; @@ -88,10 +86,17 @@ public class SiriusControlAndCrossReferenceTest extends SiriusDiagramTestCase { assertEquals(2, session.getAllSessionResources().size()); // Check cross referencer installation on the new aird. - LazyCrossReferencer semanticCrossReferencer = (LazyCrossReferencer) session.getSemanticCrossReferencer(); - Option<Field> adapterField = ReflectionHelper.setFieldVisibleWithoutException(LazyCrossReferencer.class, "adapter"); - Object internalXReferencer = adapterField.get().get(semanticCrossReferencer); - assertTrue("The semantic cross referencer should stay installed on the controlled package", packageToControl.eAdapters().contains(internalXReferencer)); + ECrossReferenceAdapter semanticCrossReferencer = session.getSemanticCrossReferencer(); + Option<Object> internalXReferencer = ReflectionHelper.getFieldValueWithoutException(semanticCrossReferencer, "adapter"); + if (internalXReferencer.some()) { + // The lazy cross referencer has an internal cross referencer + assertTrue("The semantic internal cross referencer should stay installed on the controlled package", packageToControl.eAdapters().contains(internalXReferencer.get())); + } else { + // The lazy cross referencer does not have an internal cross + // referencer + assertTrue("The semantic cross referencer should stay installed on the controlled package", packageToControl.eAdapters().contains(semanticCrossReferencer)); + } + for (Resource res : session.getAllSessionResources()) { assertTrue("The semantic cross referencer should be installed on all aird", res.eAdapters().contains(semanticCrossReferencer)); } diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java index 7085b249df..a1a4b53f31 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionImpl.java @@ -166,7 +166,7 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements private boolean deferSaveToPostCommit; private boolean saveInExclusiveTransaction; - + private AtomicBoolean domainDisposed = new AtomicBoolean(false); private AtomicBoolean saveOnPostCommit = new AtomicBoolean(false); @@ -185,7 +185,7 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements public void transactionClosed(TransactionalEditingDomainEvent event) { disarm(); } - + @Override public void editingDomainDisposing(TransactionalEditingDomainEvent event) { domainDisposed.set(true); @@ -444,7 +444,7 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements registerResourceInCrossReferencer(newAnalysis.eResource()); for (DAnalysis dAnalysis : new DAnalysisQuery(newAnalysis).getAllReferencedAnalyses()) { addAdaptersOnAnalysis(dAnalysis); - registerResourceInCrossReferencer(dAnalysis.eResource()); + registerResourceInCrossReferencer(dAnalysis.eResource()); } notifyListeners(SessionListener.REPRESENTATION_CHANGE); } else { @@ -477,7 +477,7 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements * * @return all valid(i.e. not null) owned and referenced analyses. */ - Collection<DAnalysis> allAnalyses() { + public Collection<DAnalysis> allAnalyses() { return new DAnalysisesInternalQuery(super.getAnalyses()).getAllAnalyses(); } @@ -1293,28 +1293,8 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements if (crossReferencer == null) { // use a lazy cross referencer to avoid big memory consumption on // session load - crossReferencer = new LazyCrossReferencer() { - @Override - protected void initialize() { - super.initialize(); - for (Resource res : getSemanticResources()) { - List<Adapter> adapters = res.eAdapters(); - // add only if it was not added between creation and - // initialization - if (!adapters.contains(crossReferencer)) { - adapters.add(crossReferencer); - } - } - for (DAnalysis analysis : allAnalyses()) { - List<Adapter> adapters = analysis.eResource().eAdapters(); - // add only if it was not added between creation and - // initialization - if (!adapters.contains(crossReferencer)) { - adapters.add(crossReferencer); - } - } - } - }; + crossReferencer = createSemanticCrossReferencer(); + // Precondition expression prevents a diagram to be // created when creating the session // Update the interpreter @@ -1326,6 +1306,15 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements } /** + * Create the semantic cross referencer. + * + * @return a new cross referencer adapter + */ + protected ECrossReferenceAdapter createSemanticCrossReferencer() { + return new SessionLazyCrossReferencer(this); + } + + /** * Uncached EObjects IDs of the given resources. * * @param resources @@ -1935,7 +1924,10 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements mainDAnalysis = null; } - private void disableAndRemoveECrossReferenceAdapters() { + /** + * Disable & Remove all ECrossReferencerAdapter adapters. + */ + protected void disableAndRemoveECrossReferenceAdapters() { ResourceSet resourceSet = getTransactionalEditingDomain().getResourceSet(); // Disable resolution of proxy for AirDCrossReferenceAdapter of // session and for semanticCrossReferencer during the closing @@ -1966,7 +1958,10 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements } } - private void reenableECrossReferenceAdaptersBeforeEndOfClosing() { + /** + * Enable all ECrossReferencerAdapter adapters before the end of closing. + */ + protected void reenableECrossReferenceAdaptersBeforeEndOfClosing() { ResourceSet resourceSet = getTransactionalEditingDomain().getResourceSet(); // Enable resolution for AirdCrossReferenceAdapter of session at the end // of closing @@ -2102,7 +2097,7 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements public void setDeferSaveToPostCommit(boolean deferSaveOnPostCommit) { this.saver.deferSaveToPostCommit = deferSaveOnPostCommit; } - + public boolean isDeferSaveToPostCommit() { return this.saver.deferSaveToPostCommit; } @@ -2110,7 +2105,7 @@ public class DAnalysisSessionImpl extends DAnalysisSessionEObjectImpl implements public void setSaveInExclusiveTransaction(boolean saveInExclusiveTransaction) { this.saver.saveInExclusiveTransaction = saveInExclusiveTransaction; } - + public boolean isSaveInExclusiveTransaction() { return this.saver.saveInExclusiveTransaction; } diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/SessionLazyCrossReferencer.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/SessionLazyCrossReferencer.java new file mode 100644 index 0000000000..e599edc9ee --- /dev/null +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/SessionLazyCrossReferencer.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2014 THALES GLOBAL SERVICES. + * 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 + *******************************************************************************/ +package org.eclipse.sirius.business.internal.session.danalysis; + +import java.util.List; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.sirius.common.tools.api.util.LazyCrossReferencer; +import org.eclipse.sirius.viewpoint.DAnalysis; + +/** + * A LazyCrossReferencer for the session. + * {@link LazyCrossReferencer#initialize()} is overridden in order to only add + * the adapter at the first use. + * + * @author <a href="mailto:mickael.lanoe@obeo.fr">Mickael LANOE</a> + * + */ +public class SessionLazyCrossReferencer extends LazyCrossReferencer { + private DAnalysisSessionImpl session; + + /** + * Construct from an opened session. + * + * @param session + * an opened session + */ + public SessionLazyCrossReferencer(DAnalysisSessionImpl session) { + this.session = session; + } + + @Override + protected void initialize() { + super.initialize(); + for (Resource res : session.getSemanticResources()) { + List<Adapter> adapters = res.eAdapters(); + // add only if it was not added between creation and + // initialization + if (!adapters.contains(this)) { + adapters.add(this); + } + } + + for (DAnalysis analysis : session.allAnalyses()) { + List<Adapter> adapters = analysis.eResource().eAdapters(); + // add only if it was not added between creation and + // initialization + if (!adapters.contains(this)) { + adapters.add(this); + } + } + } +} |
