got "Cyclic resolution of lazy links" when nested object access parent object [message #1690924] |
Tue, 31 March 2015 21:07  |
Eclipse User |
|
|
|
I got "Cyclic resolution of lazy links" when nested object access parent object .I try to solve this problem many days.
I have a grammar,like this:
grammar com.huawei.cs.ucl.Ucl with org.eclipse.xtext.common.Terminals
generate ucl "this is a url"
UclProgram:
(package=PackageDeclaration)?
(imports+=ImportDeclaration)*
(classes+=UclClass)*
(instances+=UclInstance)*
;
ModuleDeclaration:
'module' name= QualifiedName id=INT
;
PackageDeclaration:
'package' name = [ModuleDeclaration | QualifiedName]
;
ImportDeclaration:
'import' importedNamespace = QualifiedName | importedNamespace= QualifiedNameWithWildcard
;
QualifiedName:
ID ('.' ID)*
;
QualifiedNameWithWildcard:
QualifiedName ('.*')?
;
UclClass:
'class' name=ID
'{'
(members+=UclClassMember)*
'}';
UclClassMember:
UclClassField
;
UclClassField:
type=[UclClass] name=ID ('[' minSize=INT ',' maxSize=ArrayUpperLimit ']')? ';'
;
ArrayUpperLimit:
INT | '*'
;
UclInstance:
clazz=[UclClass] name=ID
'{'
(attributes+=UclInstanceAttribute)*
'}'
;
UclInstanceAttribute:
iafield=[UclClassField] iavalue=UclInstanceAttributeValue
;
UclInstanceAttributeValue:
UclBasicValue | UclObjectValue | UclArrayValue
;
UclBasicValue:
':' value=UclValueObject ';'
;
UclObjectValue:
'{'
(attributes+=UclInstanceAttribute)*
'}'
;
UclValueObject:
INT | STRING
;
UclArrayValue:
'['
(elements+=UclArrayElement (',' elements+=UclArrayElement)*)?
']'
;
UclArrayElement:
INT | STRING |UclObjectValue
;
I found, if a feature is a cross reference, I will got a exception when I call the cross reference object 's member.
whatever I modify the grammar, I can't avoid this exception.
org.eclipse.xtext.linking.lazy.LazyLinkingResource$CyclicLinkingException: Cyclic resolution of lazy links : UclInstanceAttribute.iafield->UclInstanceAttribute.iafield in resource 'platform:/resource/project3/src/file3.ucl'.
at org.eclipse.xtext.linking.lazy.LazyLinkingResource.handleCyclicResolution(LazyLinkingResource.java:303)
org.eclipse.xtext.linking.lazy.LazyLinkingResource$CyclicLinkingException: Cyclic resolution of lazy links : UclInstanceAttribute.iafield->UclInstanceAttribute.iafield in resource 'platform:/resource/project3/src/file3.ucl'.
at org.eclipse.xtext.linking.lazy.LazyLinkingResource.handleCyclicResolution(LazyLinkingResource.java:303)
this is my dsl example :
class string{}
class int{}
class javascript{}
class Product
{
int prodID;
string prodName;
string attributes[0,10];
Price prices[0,*];
}
class Price
{
int priceID;
int amount;
}
class Customer
{
int id;
string name;
Product offer;
javascript init;
}
Customer cust
{
id:123;
name:'cust1';
offer {
prodID:23;
prodName:"prod1";
prices[
Price price1{
....
}
Price price2{
....
}
]
}
}
public IScope scope_UclInstanceAttribute_iafield(
UclInstanceAttribute parentAttribute, EReference reference) {
System.out.println("scope_UclInstanceAttribute_iafield:"
+ parentAttribute.toString());
ArrayList<UclClassField> fields = new ArrayList<UclClassField>();
if (parentAttribute.getIafield()!=null) {
StringBuffer sb=new StringBuffer();
sb.append(parentAttribute.getIafield().eCrossReferences().toString());
System.out.println(sb);
UclClass clazz = (UclClass) parentAttribute.getIafield().getType();
EList<UclClassMember> members = clazz.getMembers();
for (UclClassMember member : members) {
if (member instanceof UclClassField) {
UclClassField field = (UclClassField) member;
fields.add(field);
}
}
}
return Scopes.scopeFor(fields);
}
I have to access the class member's type to support content assistant and link.
For example I have to get offer class type and members inside offer instance.
I guess I could use different method to access context and get the class type.
could you help me solve this problem?
thanks!
[Updated on: Tue, 31 March 2015 21:33] by Moderator
|
|
|
|
|
Re: got "Cyclic resolution of lazy links" when nested object access parent object [message #1696873 is a reply to message #1691070] |
Fri, 29 May 2015 04:01  |
Eclipse User |
|
|
|
Calling 'parentAttribute.getIafield()' will trigger resolution of the attribute you are currently trying to resolve (it is cyclic, and no framework in the world can deal with that).
What you wanted to do is:
parentAttribute = EcoreUtil2.getContainerOfType(parentAttribute, UclInstanceAttribute.class);
// .. your code here...
That could should be more robust of course and you probably also want to rename the parameter name.
Hope that helps,
Sven
[Updated on: Fri, 29 May 2015 04:03] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.04206 seconds