Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Resolve proxies
Resolve proxies [message #973984] Tue, 06 November 2012 19:29 Go to next message
Zlatka Manas is currently offline Zlatka ManasFriend
Messages: 26
Registered: March 2012
Junior Member
Hi,
I am trying to resolve the proxies I get in my DSL.
The problem is that the resourceDescriptionsProvider is null so I cannot get the resource descriptions.
I am trying to define type check rules for my DSL, so I have a class DSLTypeSystem that extends from the Switch class. In one of the overridden methods I need to know the actual name of the referenced element.

Th part of the grammar related to my problem is the following:
PrimaryExpression: ((minusSign?='-') | '+')? primary=Primary (methodCall+=DataMethodCall)* ;
DataMethodCall: (useCaret?='^')? method=[DataMethod|IDENTIFIER] ('(' (arguments=ListOfExpressions)? ')')?;

I need to know the name of the method referenced in DataMethodCall.

Any idea why this is null?

Re: Resolve proxies [message #973989 is a reply to message #973984] Tue, 06 November 2012 19:39 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi,

can you elaborate on what you are actually doing?

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Resolve proxies [message #974009 is a reply to message #973989] Tue, 06 November 2012 19:55 Go to previous messageGo to next message
Zlatka Manas is currently offline Zlatka ManasFriend
Messages: 26
Registered: March 2012
Junior Member
@Inject
ResourceDescriptionsProvider resourceDescriptionsProvider;

Resource res = ex.eResource();
IResourceDescriptions index = resourceDescriptionsProvider.getResourceDescriptions(ex.eResource());

The provider is null so I cannot get the descriptions. ex is an Expression from the language.
I also have (different method)
IResourceDescription descr = index.getResourceDescription(myResource.getURI());
EObject object = null;
for(IContainer visibleContainer: manager.getVisibleContainers(descr, index)) {
for(IResourceDescription visibleResourceDesc: visibleContainer.getResourceDescriptions()) {
	System.out.println(visibleResourceDesc.getURI());
	}

	for (IEObjectDescription od : visibleContainer.getExportedObjectsByType(PooslPackage.Literals.DATA_METHOD_CALL)) {
	DataMethodCall sodModel = (DataMethodCall) od.getEObjectOrProxy();
		object = EcoreUtil2.resolve(sodModel, myResource);
			}
		}
}

[Updated on: Tue, 06 November 2012 19:58]

Report message to a moderator

Re: Resolve proxies [message #974032 is a reply to message #974009] Tue, 06 November 2012 20:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
The question is: how do you call the code. you have to make sure the class is created/injected with google guice.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Resolve proxies [message #974044 is a reply to message #974032] Tue, 06 November 2012 20:34 Go to previous messageGo to next message
Zlatka Manas is currently offline Zlatka ManasFriend
Messages: 26
Registered: March 2012
Junior Member
I hope this is the class you mean.
public class PooslTypeSystem extends PooslSwitch<String>{

public String getType(EObject eObject) {
		String result = doSwitch(eObject);
		if (result == null)
			result = new String("");

		return result;
	}
....

@Inject
    ResourceDescriptionsProvider resourceDescriptionsProvider;

@Override
	public String casePrimaryExpression(PrimaryExpression ex)
	{

		List<DataMethodCall> methodCalls = ex.getMethodCall();
		String primaryType = getType(ex.getPrimary());
		Resource res = ex.eResource();
		IResourceDescriptions index = resourceDescriptionsProvider.getResourceDescriptions(ex.eResource());

                for(DataMethodCall method: methodCalls)
		{
		DataMethod returnMethod = listVisibleResources(res, index);		
		}

}

@Inject
IContainer.Manager containerManager;

public void listVisibleResources(
        Resource myResource, IResourceDescriptions index) {
  IResourceDescription descr = 
        index.getResourceDescription(myResource.getURI());
  for(IContainer visibleContainer: manager.getVisibleContainers(descr)) { 
    for(IResourceDescription visibleResourceDesc:
            visibleContainer.getResourceDescription()) { 
      System.out.println(visibleResourceDesc.getURI());
    }
  }
}

Re: Resolve proxies [message #974155 is a reply to message #974044] Tue, 06 November 2012 22:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Still the question: how to you create/inject an instance of the
class. A simple new will not do the trick

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Resolve proxies [message #974658 is a reply to message #974155] Wed, 07 November 2012 08:22 Go to previous messageGo to next message
Zlatka Manas is currently offline Zlatka ManasFriend
Messages: 26
Registered: March 2012
Junior Member
I use a simple new for the TypeSystem class.
Re: Resolve proxies [message #974692 is a reply to message #974658] Wed, 07 November 2012 08:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
Hi you have to use guice for thst

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Resolve proxies [message #974693 is a reply to message #974692] Wed, 07 November 2012 08:53 Go to previous messageGo to next message
Zlatka Manas is currently offline Zlatka ManasFriend
Messages: 26
Registered: March 2012
Junior Member
How does that change impact the provider? Can you explain it briefly?

Thanks.
Re: Resolve proxies [message #974713 is a reply to message #974693] Wed, 07 November 2012 09:06 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33107
Registered: July 2009
Senior Member
Zlatka,

It ensures that all the fields you've marked with @Inject are actually
injected.

On 07/11/2012 9:53 AM, Zlatka Manas wrote:
> How does that change impact the provider? Can you explain it briefly?
>
> Thanks.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Resolve proxies [message #975181 is a reply to message #974713] Wed, 07 November 2012 17:11 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
In a world that's fully controlled by Guice injection works just fine, but sometimes I find myself in a situation where instances need to be created explicitly. Even "injector.getInstance(X.class)" doesn't always do the trick. In those cases I tend to say:
X x = new X(argFoo, argBar);
injector.injectMembers(x);

this seems to be the best compromise between "fully controlled by Guice" and "fully controlled by my code".

HTH,
Stephan
Previous Topic:Duplicate entries / namespace problems
Next Topic:inject extension not injected in JUnit test
Goto Forum:
  


Current Time: Tue Mar 19 07:53:29 GMT 2024

Powered by FUDForum. Page generated in 0.02882 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top