Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 331816

Summary: Find references only consider resource exported elements
Product: [Modeling] TMF Reporter: Samantha Chan <chanskw>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: sebastian.zarnekow
Version: 1.0.1   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Samantha Chan CLA 2010-12-03 15:28:09 EST
In my understanding, resource descriptions consists of a list of EObjectDescriptions that are exported from the resource.  i.e. these objects can be referenced from outside of the current resource.

There is also a concept of local scoping where the EObjectDescriptions are constructed on the fly when trying to determine the local scope.

In the FindReferencesHandler, it seems to me that we can only find references that are part of a resource description.  In other words, we can only locate references to objects that are exported, but no to objects that are only visible in the current resource.

I cannot find a way to override this behavior, and I am wondering if EObjectResolver from FindReferencesHandler should be changed to construct a new EObjectDescription if a name attribute is present.  

I changed my local dev environment to this and was able to find references for local elements as well.  Is this the right way of going about it?  Is it expected that FindReferences should only work for exported elements?


Here's the proposed change:

		public IEObjectDescription exec(XtextResource state) throws Exception {
			EObject element = EObjectAtOffsetHelper.resolveElementAt(state, selection.getOffset(), null);
			if (element != null) {
				final URI eObjectURI = EcoreUtil.getURI(element);
				IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(eObjectURI
						.trimFragment());
				if (resourceDescription != null) {
					Iterator<IEObjectDescription> eObjectDescriptions = Iterables.filter(
							resourceDescription.getExportedObjects(), new Predicate<IEObjectDescription>() {
								public boolean apply(IEObjectDescription input) {
									return input.getEObjectURI().equals(eObjectURI);
								}
							}).iterator();
					if (eObjectDescriptions.hasNext()) {
						return eObjectDescriptions.next();
					}
				}
			}
			
			SimpleAttributeResolver<EObject, String> resolver = SimpleAttributeResolver.newResolver(String.class, "name");
			EAttribute attribute = resolver.getAttribute(element);
			String name = attribute.toString();
			if (name != null)
				return new EObjectDescription(name, element, null);
			return null;
		}
Comment 1 Sebastian Zarnekow CLA 2010-12-03 15:40:11 EST
Seems to be a duplicate of bug 301275

*** This bug has been marked as a duplicate of bug 301275 ***