Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: do not install proxy node models on the complete AST #1067

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
package com.avaloq.tools.ddk.xtext.resource.persistence;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.WrappedException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
Expand Down Expand Up @@ -75,39 +73,40 @@ static void installProxyNodeModel(final Resource resource) {
return;
}

ArrayList<EObject> idToEObjectMap = Lists.newArrayList(); // NOPMD LooseCoupling
EObject root = resource.getContents().get(0);

ProxyCompositeNode rootNode = installProxyNodeModel(root, idToEObjectMap);
idToEObjectMap.trimToSize();
rootNode.idToEObjectMap = idToEObjectMap;
ProxyCompositeNode rootNode = installProxyNodeModel(root);
rootNode.idToEObjectMap = Lists.newArrayList();

if (resource instanceof XtextResource) {
((XtextResource) resource).setParseResult(new ParseResult(root, rootNode, false));
}
}

private static ProxyCompositeNode installProxyNodeModel(final EObject eObject, final List<EObject> map) {
private static ProxyCompositeNode installProxyNodeModel(final EObject eObject) {
ProxyCompositeNode result = new ProxyCompositeNode();
eObject.eAdapters().add(result);
return result;
}

private static void installMap(final EObject eObject, final List<EObject> map) {
map.add(eObject);

FeatureIterator<EObject> iterator = (FeatureIterator<EObject>) eObject.eContents().iterator();
if (iterator instanceof Filterable filterable) {
filterable.filter(f -> !f.isTransient());
for (FeatureIterator<EObject> it = iterator; it.hasNext();) {
installProxyNodeModel(it.next(), map);
installMap(it.next(), map);
}
} else {
// post-filter the iterator, which is extra work
for (FeatureIterator<EObject> it = iterator; it.hasNext();) {
EObject child = it.next();
if (!it.feature().isTransient()) {
installProxyNodeModel(child, map);
installMap(child, map);
}
}
}
return result;
}

/**
Expand All @@ -124,9 +123,7 @@ static List<EObject> uninstallProxyNodeModel(final Resource resource) {
ProxyCompositeNode proxyNode = uninstallProxyNode(root);
if (proxyNode != null) {
result = proxyNode.idToEObjectMap;
for (TreeIterator<EObject> it = root.eAllContents(); it.hasNext();) {
uninstallProxyNode(it.next());
}
installMap(root, result);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;

import com.avaloq.tools.ddk.xtext.linking.LazyLinkingResource2;
import com.google.common.collect.Iterables;


Expand Down Expand Up @@ -143,6 +144,14 @@ public static String getParsedString(final EObject object, final String featureN
*/
public static String getParsedStringUnchecked(final EObject object, final EStructuralFeature feature, final boolean convert) {
INode node = Iterables.getFirst(NodeModelUtils.findNodesForFeature(object, feature), null);

if (node == null && object.eResource() instanceof LazyLinkingResource2 resource && resource.isLoadedFromStorage()) {
EObject root = resource.getContents().get(0);
if (NodeModelUtils.getNode(root) instanceof ICompositeNode composite) {
composite.getText(); // side-effect on removing com.avaloq.tools.ddk.xtext.resource.persistence.ProxyCompositeNode
node = Iterables.getFirst(NodeModelUtils.findNodesForFeature(object, feature), null);
}
}
if (node != null) {
if (convert) {
final LazyLinkingResource res = (LazyLinkingResource) object.eResource();
Expand Down