Skip to content

Commit 10e1c82

Browse files
committed
Use IQualifiedNameProvider if possible
If possible, do not look for the qualified names in the resource descriptor, asking the IQualifiedNameProvider for the values is much faster, as the lookup involve very expensive operations (specially the second one): - Create a collection with all the resource descriptions of the referenced resource (only first lookup). - Iterate through the list every time and compare the fragments. Asking the IQualifiedNameProvider has the extra advantage that it can return a name even the target object has not yet been exported, this happens in the second phase when: - a resource is loaded on demand - liking to an inferred object which was not inferred in the pre-linking phase is done. - the resource loaded on demand has not yet been processed in the second phase under this circumstances the IResourceDescriptions.getExportedObjectsByObject will not find the element we have linked right before.
1 parent fc7b271 commit 10e1c82

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/linking/LinkingService.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
import org.eclipse.emf.ecore.EClass;
1818
import org.eclipse.emf.ecore.EObject;
1919
import org.eclipse.emf.ecore.EReference;
20+
import org.eclipse.emf.ecore.resource.Resource;
2021
import org.eclipse.xtext.linking.impl.DefaultLinkingService;
2122
import org.eclipse.xtext.linking.impl.ImportedNamesAdapter;
2223
import org.eclipse.xtext.naming.IQualifiedNameConverter;
24+
import org.eclipse.xtext.naming.IQualifiedNameProvider;
2325
import org.eclipse.xtext.naming.QualifiedName;
2426
import org.eclipse.xtext.nodemodel.INode;
2527
import org.eclipse.xtext.resource.IEObjectDescription;
@@ -82,13 +84,22 @@ private void registerNamedType(final EObject context, final QualifiedName name,
8284
* the lookup type, may be {@code null}
8385
*/
8486
public void importObject(final EObject context, final EObject target, final EClass type) {
85-
final IResourceDescriptions resourceDescriptions = provider.getResourceDescriptions(context.eResource());
86-
Iterator<IEObjectDescription> exports = resourceDescriptions.getExportedObjectsByObject(target).iterator();
87-
if (exports.hasNext()) {
88-
QualifiedName targetName = exports.next().getName();
89-
if (targetName != null && !targetName.isEmpty()) {
90-
registerNamedType(context, targetName.toLowerCase(), type); // NOPMD targetName not a String!
87+
Resource eResource = target.eResource();
88+
QualifiedName targetName = null;
89+
if (eResource instanceof LazyLinkingResource2) {
90+
IQualifiedNameProvider nameProvider = ((LazyLinkingResource2) eResource).getService(IQualifiedNameProvider.class);
91+
if (nameProvider != null) {
92+
targetName = nameProvider.getFullyQualifiedName(target);
9193
}
94+
} else {
95+
final IResourceDescriptions resourceDescriptions = provider.getResourceDescriptions(context.eResource());
96+
Iterator<IEObjectDescription> exports = resourceDescriptions.getExportedObjectsByObject(target).iterator();
97+
if (exports.hasNext()) {
98+
targetName = exports.next().getName();
99+
}
100+
}
101+
if (targetName != null && !targetName.isEmpty()) {
102+
registerNamedType(context, targetName.toLowerCase(), type); // NOPMD targetName not a String!
92103
}
93104
}
94105

0 commit comments

Comments
 (0)