Skip to content

Commit

Permalink
Further updates related to event handling #25
Browse files Browse the repository at this point in the history
 * Ignore events received when event firing is disabled
 * Explicitly mark feature names starting with '_' as unindexable
  • Loading branch information
ujhelyiz committed Mar 4, 2019
1 parent d668958 commit 9a82bf5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.stream.Collectors;

import org.apache.log4j.Logger;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
Expand All @@ -18,6 +19,7 @@
import org.eclipse.viatra.query.runtime.base.api.NavigationHelper;
import org.eclipse.viatra.query.runtime.base.api.filters.IBaseIndexObjectFilter;
import org.eclipse.viatra.query.runtime.base.api.filters.IBaseIndexResourceFilter;
import org.eclipse.viatra.query.runtime.base.core.NavigationHelperContentAdapter;
import org.eclipse.viatra.query.runtime.base.core.NavigationHelperImpl;
import org.eclipse.viatra.query.runtime.base.exception.ViatraBaseException;
import org.eclipse.viatra.query.runtime.emf.DynamicEMFQueryRuntimeContext;
Expand Down Expand Up @@ -76,6 +78,16 @@ private class MagicDrawProjectNavigationHelper extends NavigationHelperImpl {

public MagicDrawProjectNavigationHelper(Notifier emfRoot, BaseIndexOptions options, Logger logger) {
super(emfRoot, options, logger);
this.contentAdapter = new NavigationHelperContentAdapter(this) {

@Override
public void notifyChanged(Notification notification) {
if (scope.getProject().getRepository().getEventSupport().isEnableEventFiring()) {
super.notifyChanged(notification);
}
}

};
}

Set<Notifier> getModelRoots() {
Expand Down Expand Up @@ -113,7 +125,7 @@ public void removeRoot(Notifier root) {
notifyBaseIndexChangeListeners();
}
}
public MagicDrawProjectEngineContext(MagicDrawProjectScope scope, ViatraQueryEngine engine, IIndexingErrorListener taintListener, Logger logger) {
this.scope = scope;
this.engine = engine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ public class MagicDrawProjectScope extends EMFScope {
// XXX Omitting references can cause semantic errors (so far we are in the clear though)
// these references are only present in UML profiles, typically their contents are equal to the original references inherited from the UML type hierarchy, however there are some cases when this might not be the case.
private static final BaseIndexOptions BASE_OPTIONS = new BaseIndexOptions()
.withFeatureFilterConfiguration(reference -> reference instanceof EReference
&& ((EReference) reference).isContainment() && reference.getName().contains("_from_"))
.withFeatureFilterConfiguration(reference -> reference instanceof EReference && isReferenceToBeFiltered((EReference) reference))
.withStrictNotificationMode(false);

private static boolean isReferenceToBeFiltered(EReference reference) {
String name = reference.getName();
return (reference.isContainment() && name.contains("_from_"))
||
name.startsWith("_");
}

static Stream<? extends Notifier> getProjectModels(Project projectModel) {
Package primaryModel = projectModel.getPrimaryModel();
return projectModel.getModels().stream().filter(pkg -> pkg == primaryModel || !EcoreUtil.isAncestor(primaryModel, pkg));
Expand Down

0 comments on commit 9a82bf5

Please sign in to comment.