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

Bug 311337

Summary: Cyclic resolution error in cross-reference chain
Product: [Modeling] TMF Reporter: Tim <noreply>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: sebastian.zarnekow, sven.efftinge
Version: unspecifiedFlags: sebastian.zarnekow: helios+
Target Milestone: RC1   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Tim CLA 2010-05-03 04:00:31 EDT
Build Identifier: I20100312-1448

http://www.eclipse.org/forums/index.php?t=msg&goto=530561&#msg_530561

This grammar rule produces a cyclic resolution but does its job well:

Reference:
'(ref)' refChild=[Child] (':'{NestedRef.left=current} refChild=[Child])*
;

Goal is to adress a child like child1:child2:child3

Sources:

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
			(def+=Definition)+
;

Definition:
			'(def)'name=ID ':' (child+=Child) (ref+=Reference)?
;

Child:
			'(child)'name=ID ':' link=[Definition]?
;

Reference:
			'(ref)' refChild=[Child] (':'{NestedRef.left=current} refChild=[Child])*
			
;

================================
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.scoping.Scopes;
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider;
import org.xtext.example.mydsl.myDsl.Child;
import org.xtext.example.mydsl.myDsl.Definition;
import org.xtext.example.mydsl.myDsl.NestedRef;
import org.xtext.example.mydsl.myDsl.Reference;

/**
 * This class contains custom scoping description.
 * 
 * see : http://www.eclipse.org/Xtext/documentation/latest/xtext.html#scoping
 * on how and when to use it 
 *
 */
public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
	
	public IScope scope_Reference_refChild(NestedRef context,
			EReference ref) {
		EList<Child> childList = null;
		
		Child child = context.getLeft().getRefChild();
		childList = child.getLink().getChild();
		
		IScope newScope = Scopes.scopeFor(childList);
		return newScope;

	}
	
	public IScope scope_Reference_refChild(Reference context, EReference ref) {
		
		Definition localClass = null;
		EList<Child> childList = null;
		localClass = EcoreUtil2.getContainerOfType(context, Definition.class);		
		childList = localClass.getChild();

		IScope newScope = Scopes.scopeFor(childList);
		return newScope;
	}
	
	

}

===================================
/************************************/

(def) local :
(child) local_Child : def_depth1
(ref) local_Child:depth1_Child:

/************************************/

(def) def_depth1 :
(child) depth1_Child : def_depth2

/************************************/

(def) def_depth2 :
(child) depth2_Child :

Reproducible: Always

Steps to Reproduce:
1. new Xtext Project
2. replace with attached grammar
3. replace ScopeProvider
4. try to lookup references in testfile (project->clean sometimes needed)
Comment 1 Sven Efftinge CLA 2010-05-07 09:01:06 EDT
I have added a test case using the code snippets you have provided. Tests are green.
The problem has already been fixed in a previous milestone (M6).
Please reopen if the problem still exists.
Comment 2 Karsten Thoms CLA 2017-09-19 16:35:19 EDT
Closing bug which were set to RESOLVED before Eclipse Neon.0.