[XTEXT] Referencing Model Objects from Memory (no Resource associated) [message #760007] |
Wed, 30 November 2011 21:46  |
Michael Ernst Messages: 49 Registered: July 2010 |
Member |
|
|
Hi,
I want to provide global available functions which should be configured separately. I started as mentioned in the documentation with inheriting from DefaultGlobalScopeProvider and overriding the getScope method (see the snippet below).
In the Editor the auto completion works fine with this setup, but than I get an Error Marker with the following message:
Quote:The feature 'feature' of '...FeatureCallImpl@ a238d1{platform:/resource/test/test.test#// @ childElements.1/@ assignments.1/@ rightOperand/@ ruleExpression}' contains a dangling reference '...FunctionImpl@ 6a22a{#//}'
Any hints how to fix this.
Thanks in advance!
Kind regards
Michael
public IScope getScope( Resource resource, EReference reference, Predicate<IEObjectDescription> filter )
{
EClass referenceType = getEReferenceType( resource, reference );
if( EcoreUtil2.isAssignableFrom( CommonPackage.Literals.IDENTIFIABLE_ELEMENT, referenceType ) )
{
return new SimpleScope( IScope.NULLSCOPE, FunctionsHolder.DESCRIPTIONS );
}
return super.getScope( resource, reference, filter );
}
The DESCRIPTIONS field is filled using this pattern:
Function myFirstFunction = globalFactory.createFunction();
myFirstFunction.setName( "helloWorld" );
myFirstFunction.setType( commonFactory.createStringType() );
...
DESCRIPTIONS.add( EObjectDescription.create( "helloWorld", myFirstFunction ) );
|
|
|
|
|
|
|
Re: [XTEXT] Referencing Model Objects from Memory (no Resource associated) [message #760701 is a reply to message #760479] |
Sun, 04 December 2011 12:14  |
Michael Ernst Messages: 49 Registered: July 2010 |
Member |
|
|
Ok, I've got it!
For all who are intrested in, here my solution.
I had to implement my own IQualifiedNameProvider.
I had to override the ID method of DefaultTerminalConverters and my own Linking Service. Here are the missing snippets:
public class MyValueConverterService extends DefaultTerminalConverters
{
@Inject
private AbstractIDValueConverter idValueConverter;
public class FeatureCallValueConverter implements IValueConverter<String>
{
@Override
public String toValue( String string, INode node ) throws ValueConverterException
{
return idValueConverter.toValue( string, node );
}
@Override
public String toString( String value ) throws ValueConverterException
{
if( value.contains( "." ) )
{
String[] split = value.split( "\\." );
return split[0] + "()";
}
return value;
}
}
private FeatureCallValueConverter valueConverter = new FeatureCallValueConverter();
@Override
public IValueConverter<String> ID()
{
return valueConverter;
}
}
public class MyLinkingService extends DefaultLinkingService
{
@Override
public List<EObject> getLinkedObjects( EObject context, EReference ref, INode node ) throws IllegalNodeException
{
List<EObject> linkedObjects = super.getLinkedObjects( context, ref, node );
if( linkedObjects.isEmpty() && context instanceof FeatureCall
&& ( (FeatureCall) context ).isExplicitFunctionCall() )
{
IScope scope = getScope( context, ref );
Iterable<IEObjectDescription> allElements = scope.getAllElements();
// find the best matching function based on name and parameters and the parameters type
EObject result = bestMatch( (FeatureCall) context, allElements, node );
if( result != null )
{
return Lists.newArrayList( result );
}
}
return linkedObjects;
}
...
Thanks for all replies.
Kind regards
Michael
|
|
|
Powered by
FUDForum. Page generated in 0.02442 seconds