Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Error in extending xbase expressions
Error in extending xbase expressions [message #1043938] Thu, 18 April 2013 05:42 Go to next message
andrea rossi is currently offline andrea rossi
Messages: 23
Registered: April 2013
Junior Member
Hi ,

This is a part of my grammar :

grammar org.xtext.example.jade.Jade with  org.eclipse.xtext.xbase.Xbase

.....

Message returns xbase::XExpression: 
	SendMessage | Prova
;

SendMessage returns xbase::XExpression: 
	{SendMessage}
	'send message' name = ValidID  '{'
	
	(('sender' '=' sender = STRING)? &
	('content'  '=' content = STRING)? &
	//('language'  '=' language = STRING)? &
	//('ontology'  '=' ontology = STRING)? &
	('performative' '=' performative = Performative) &
	('receivers' '{' (receivers += (MessageReceivers)+) '}' ) )
	
	'}'
;

SimpleBehaviour : 
	'behaviour' name=ValidID 'is' typeSB = TypeSB '{'
	 (body=XExpressionInsideBlock ';'?)
	'}'
;

XExpressionInsideBlock returns xbase::XExpression:
	XVariableDeclaration | XExpression | Message;


Prova returns xbase::XExpression : 
  {Prova} 'receive message do' '{' campo = XExpressionInsideBlock '}'
;



I extend xbase expressions adding my expression(Message) in XExpressionInsideBlock
My expression Message is SendMessage expression or Prova expression.I extend xbase expression for use all xbase expressions and in additional my expression Messagge in SimpleBehaviour.

Then I extend AbstractModelInferrer and XbaseCompiler for translate my DSL in java.
This è my XbaseCompiler :


class JadeCompiler extends XbaseCompiler {

	override protected doInternalToJavaStatement(XExpression expr,ITreeAppendable it, boolean isReferenced) {
		switch expr {
			SendMessage : {
				newLine
				append('''
      				ACLMessage «expr.name» = new                ACLMessage(ACLMessage.«expr.performative»);
      				«IF expr.sender != null»
      					«expr.name».setSender(new AID ("«expr.sender»",AID.ISLOCALNAME));
      				«ENDIF»
      			        «IF expr.content != null»
      				    «expr.name».setContent("«expr.content»");
      				«ENDIF»
      				«FOR r : expr.receivers»
      					«expr.name».addReceiver(new AID ("«r.receiver»",AID.ISLOCALNAME));
      				«ENDFOR»
      				send(«expr.name»);
      						   	 		''')
				
			}
			
		Prova : {
			doInternalToJavaStatement(expr.campo, it, isReferenced)
			append('''
			ACLMessage msg = receive();
			if (msg!=null){}
			''')
			
			
			
		}


			default :
				super.doInternalToJavaStatement(expr, it, isReferenced)
		}
	}

	override protected internalToConvertedExpression(XExpression obj, ITreeAppendable it) {
		if (hasName(obj))
			append(getName(obj))
		else 
			super.internalToConvertedExpression(obj, it) 
	}

}



If i use SendMessage expression the translate is work but if i use Prova expression the translate don't work
Error is :
ERROR org.eclipse.xtext.builder.BuilderParticipant - Error during compilation of '..'
java.lang.NullPointerException



Re: Error in extending xbase expressions [message #1044314 is a reply to message #1043938] Thu, 18 April 2013 15:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6230
Registered: July 2009
Senior Member
Hi,

can you share a complete reproduceable example, stacktrace etc
Re: Error in extending xbase expressions [message #1044323 is a reply to message #1044314] Thu, 18 April 2013 15:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6230
Registered: July 2009
Senior Member
Btw i dont get a NPE with what i built myself from your stuff.
Re: Error in extending xbase expressions [message #1044375 is a reply to message #1044323] Thu, 18 April 2013 16:59 Go to previous messageGo to next message
andrea rossi is currently offline andrea rossi
Messages: 23
Registered: April 2013
Junior Member
thank you for you replies

my grammar :
grammar org.xtext.example.jade.Jade with  org.eclipse.xtext.xbase.Xbase
generate jade "htp://www.xtext.org/example/jade/Jade"

import 'htp://www.eclipse.org/xtext/xbase/Xbase' as xbase



Model:
	'package' name = QualifiedName 
	elements+=AbstractElement*;

	
AbstractElement :
	AbstractBehaviour | AgentJade
;
	
AgentJade:
	'agent' name=ValidID '{' 
	 behaviours += AddBehaviour*
	 messages += Message*
	'}';
	
AddBehaviour : 
	'add behaviour' name=ValidID 'type' type = [AbstractBehaviour|ValidID]
;

Message returns xbase::XExpression: 
	SendMessage | Prova
;

SendMessage returns xbase::XExpression: 
	{SendMessage}
	'send message' name = ValidID  '{'
	
	(('sender' '=' sender = STRING)? &
	('content'  '=' content = STRING)? &
	//('language'  '=' language = STRING)? &
	//('ontology'  '=' ontology = STRING)? &
	('performative' '=' performative = Performative) &
	('receivers' '{' (receivers += (MessageReceivers)+) '}' ) )
	
	'}'
;



MessageReceivers : 
	'receiver =' receiver = STRING  
;
enum Performative :
	REQUEST | INFORM | QUERY_IF | CFP | PROPOSE | ACCEPT_PROPOSAL | REJECT_PROPOSAL //da completare
;

AbstractBehaviour : 
  SimpleBehaviour | Behaviour
	;

Behaviour : 
	'behaviour' name=ValidID 'is' typeB = 'Behaviour' '{'
	 (body=XExpressionInsideBlock';'?)
	'}'
	;

SimpleBehaviour : 
	'behaviour' name=ValidID 'is' typeSB = TypeSB '{'
	 (body=XExpressionInsideBlock ';'?)
	'}'
;

enum TypeSB  : 
	OneShotBehaviour | CiclicBehaviour 
;

XExpressionInsideBlock returns xbase::XExpression:
	XVariableDeclaration | XExpression | Message;


Prova returns xbase::XExpression : 
  {Prova} 'receive message do' '{' campo = XExpressionInsideBlock '}'
;



my compiler :
class JadeCompiler extends XbaseCompiler {

	override protected doInternalToJavaStatement(XExpression expr, ITreeAppendable it, boolean isReferenced) {
		switch expr {
			SendMessage : {
				
				newLine
				
				append('''
      				ACLMessage «expr.name» = new ACLMessage(ACLMessage.«expr.performative»);
      				«IF expr.sender != null»
      					«expr.name».setSender(new AID ("«expr.sender»",AID.ISLOCALNAME));
      				«ENDIF»
      			    «IF expr.content != null»
      				    «expr.name».setContent("«expr.content»");
      				«ENDIF»
      				«FOR r : expr.receivers»
      					«expr.name».addReceiver(new AID ("«r.receiver»",AID.ISLOCALNAME));
      				«ENDFOR»
      				send(«expr.name»);
      						   	 		''')
			
			}
			
		Prova : {
			doInternalToJavaStatement(expr.campo, it, isReferenced)
			append('''
			ACLMessage msg = receive();
			if (msg!=null){}
			''')
			
			
			
		}


			default :
				super.doInternalToJavaStatement(expr, it, isReferenced)
		}
	}

	override protected internalToConvertedExpression(XExpression obj, ITreeAppendable it) {
		if (hasName(obj))
			append(getName(obj))
		else 
			super.internalToConvertedExpression(obj, it) 
	}

}


my AbstractModelInferrer :

class JadeJvmModelInferrer extends AbstractModelInferrer {
 
   @Inject extension JvmTypesBuilder
  
  @Inject extension IQualifiedNameProvider

  def dispatch void infer(Model element, 
                IJvmDeclaredTypeAcceptor acceptor, 
                boolean isPrelinkingPhase) {
    
    
    for (a : element.elements) {
    	switch a {
    		AbstractBehaviour : {
    			switch a {
    				SimpleBehaviour : {
    					acceptor.accept(a.toClass(a.fullyQualifiedName)).initializeLater [
    						superTypes += a.newTypeRef('jade.core.behaviours.'+ a.typeSB.toString)
    						members += a.toConstructor[
    							documentation = '''...'''
    							parameters += toParameter("agent", newTypeRef(a, 'jade.core.Agent'))
    							body = [
      									append('''
        								super(agent);
      									''')
    							]
  							]
    						members += a.toMethod("action",a.newTypeRef(Void::TYPE))[
    						body = a.body
    						]
    					]
    					
    				}
    			}
    		}
    		
    		
    		AgentJade : {
    			acceptor.accept(a.toClass(a.fullyQualifiedName)).initializeLater [
      				documentation = a.documentation
      				superTypes += a.newTypeRef('jade.core.Agent')
      				members += a.toMethod("setup",a.newTypeRef(Void::TYPE))[
      					body = [append('''   
      						«FOR b : a.behaviours»
      							«b.type.name» «b.name» = new «b.type.name»(this);
      							addBehaviour(«b.name»);
      						«ENDFOR»
      						''')
      						   for (m : a.messages) { 
      						   	 switch m {
      						   	 	SendMessage : { 
      						   	 		append('''
      						   	 		ACLMessage «m.name» = new ACLMessage(ACLMessage.«m.performative»);
      						   	 		«IF m.sender != null»
      						   	 			«m.name».setSender(new AID ("«m.sender»",AID.ISLOCALNAME));
      						   	 		«ENDIF»
      						   	 		«IF m.content != null»
      						   	 			«m.name».setContent("«m.content»");
      						   	 		«ENDIF»
      						   	 		«FOR r : m.receivers»
      						   	 			«m.name».addReceiver(new AID ("«r.receiver»",AID.ISLOCALNAME));
      						   	 		«ENDFOR»
      						   	 		send(«m.name»);
      						   	 		''')
      						   	    }//sendMe
      						   	   }//switch     						   	  
      						   	 }//for
      						   	
      						   	
      						 
      						 ]//body
      						 
      				
      				]
      				
      			]
    		}//agent jade
    }//switch
    
    
    
  }//for
  
  }//infer
  
  
}//class
  




my RuntimeModule :


public class JadeRuntimeModule extends org.xtext.example.jade.AbstractJadeRuntimeModule {
	
	
	
	public Class<? extends XbaseCompiler> bindXbaseCompiler() {
		return JadeCompiler.class;
		
	}
	
	@Override
	public Class<? extends ITypeComputer> bindITypeComputer() {
		return JadeTypeComputer.class;
	}

}





my TypeComputer :
class JadeTypeComputer extends XbaseTypeComputer {

	override computeTypes(XExpression expression, ITypeComputationState state) {
		if(expression instanceof SendMessage) {
			_computeTypes(expression as SendMessage, state);
		} else if (expression instanceof Prova){
			 _computeTypes(expression as Prova,state)}
			 else {
			super.computeTypes(expression, state)
		}
	}

	protected def _computeTypes(SendMessage expression, ITypeComputationState state) {
		//super._computeTypes(expression as XExpression, state)
		state.acceptActualType(getTypeForName(typeof(Void), state))
	}
	
	protected def _computeTypes(Prova expression, ITypeComputationState state) {
		//super.computeTypes(expression.campo, state)
		state.acceptActualType(getTypeForName(typeof(Void), state))
	}
	

	
}



Error :

at org.eclipse.xtext.xbase.compiler.TypeReferenceSerializer.serialize(TypeReferenceSerializer.java:90)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.serialize(AbstractXbaseCompiler.java:342)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.serialize(AbstractXbaseCompiler.java:338)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.serialize(AbstractXbaseCompiler.java:334)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler.appendVariableTypeAndName(XbaseCompiler.java:663)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler._toJavaStatement(XbaseCompiler.java:643)
	at org.eclipse.xtext.xbase.compiler.XbaseCompiler.doInternalToJavaStatement(XbaseCompiler.java:441)
	at org.xtext.example.jade.jvmmodel.JadeCompiler.doInternalToJavaStatement(JadeCompiler.java:93)
	at org.xtext.example.jade.jvmmodel.JadeCompiler.doInternalToJavaStatement(JadeCompiler.java:83)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.internalToJavaStatement(AbstractXbaseCompiler.java:297)
	at org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.compile(AbstractXbaseCompiler.java:236)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateExecutableBody(JvmModelGenerator.java:1111)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator._generateMember(JvmModelGenerator.java:809)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateMember(JvmModelGenerator.java:1777)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator$2.apply(JvmModelGenerator.java:286)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator$2.apply(JvmModelGenerator.java:1)
	at org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_doubleArrow(ObjectExtensions.java:139)
	at org.eclipse.xtext.xbase.compiler.LoopExtensions$1.apply(LoopExtensions.java:39)
	at org.eclipse.xtext.xbase.lib.IterableExtensions.forEach(IterableExtensions.java:399)
	at org.eclipse.xtext.xbase.compiler.LoopExtensions.forEach(LoopExtensions.java:42)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator._generateBody(JvmModelGenerator.java:290)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateBody(JvmModelGenerator.java:1751)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateType(JvmModelGenerator.java:209)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator._internalDoGenerate(JvmModelGenerator.java:200)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.internalDoGenerate(JvmModelGenerator.java:1734)
	at org.eclipse.xtext.xbase.compiler.JvmModelGenerator.doGenerate(JvmModelGenerator.java:181)
	at org.eclipse.xtext.builder.BuilderParticipant.handleChangedContents(BuilderParticipant.java:291)
	at org.eclipse.xtext.builder.BuilderParticipant.build(BuilderParticipant.java:221)
	at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant.build(RegistryBuilderParticipant.java:60)
	at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:170)
	at org.eclipse.xtext.builder.impl.XtextBuilder.incrementalBuild(XtextBuilder.java:146)
	at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:95)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:726)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)



Re: Error in extending xbase expressions [message #1044378 is a reply to message #1044323] Thu, 18 April 2013 17:01 Go to previous messageGo to next message
andrea rossi is currently offline andrea rossi
Messages: 23
Registered: April 2013
Junior Member
sorry for double post

[Updated on: Thu, 18 April 2013 17:03]

Report message to a moderator

Re: Error in extending xbase expressions [message #1044383 is a reply to message #1044378] Thu, 18 April 2013 17:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6230
Registered: July 2009
Senior Member
Hi,

can you share your test model as well?
Re: Error in extending xbase expressions [message #1044667 is a reply to message #1044383] Fri, 19 April 2013 03:25 Go to previous messageGo to next message
Claudio Heeg is currently offline Claudio Heeg
Messages: 75
Registered: April 2013
Member
I, for one, cannot reproduce that error with those settings. A concrete model would indeed be helpful.
Also, which version of Xtext are you using?

But may I give a somewhat unrelated hint towards improvement of your grammar? Keywords shouldn't have spaces. [1]

Also, when trying to format your ModelInferrer, I get a series of errors, org.eclipse.xtext.xbase.formatting.FormattableDocument - Conflicting TextEdits during formatting, for the areas around the comments on the closing brackets.
Is that only me? Because that does look like a bug to me.
--
[1] http://zarnekow.blogspot.de/2012/11/xtext-corner-9-about-keywords-again.html

[Updated on: Fri, 19 April 2013 03:51]

Report message to a moderator

Re: Error in extending xbase expressions [message #1044724 is a reply to message #1044667] Fri, 19 April 2013 04:47 Go to previous messageGo to next message
andrea rossi is currently offline andrea rossi
Messages: 23
Registered: April 2013
Junior Member
I use Xtext 2.4.1

I work on this example :


package agenti
 

behaviour HelloBehaviour is OneShotBehaviour {
	receive message do {
		val int i = 1
	}
	
	}
	
agent HelloAgent {
	add behaviour b1 type HelloBehaviour
	send message msg {
		performative = REQUEST
		receivers {
			receiver = "Pong"
		}
	}
}



Re: Error in extending xbase expressions [message #1044799 is a reply to message #1044724] Fri, 19 April 2013 07:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6230
Registered: July 2009
Senior Member
Hi,

cant reproduce it with 2.4.0
can reproduce it with 2.4.1

looks like the type of the int literal cannot be determined.

~Christian
Re: Error in extending xbase expressions [message #1044808 is a reply to message #1044799] Fri, 19 April 2013 07:16 Go to previous messageGo to next message
Claudio Heeg is currently offline Claudio Heeg
Messages: 75
Registered: April 2013
Member
Christian Dietrich wrote on Fri, 19 April 2013 13:05
Hi,

cant reproduce it with 2.4.0
can reproduce it with 2.4.1

looks like the type of the int literal cannot be determined.

~Christian

The problem also only seems to appear within a "Behaviour" block, with both SendMessage and Prova.
If I define either SendMessages and Provas in an "Agent" block, code is apprently generated as desired.
Re: Error in extending xbase expressions [message #1044812 is a reply to message #1044375] Fri, 19 April 2013 07:16 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
Hi Andrea,

your type computer looks bogus to me. According to the JavaDoc of
ITypeComputer, you are responsible to trigger the type computation for
all child expressions of your specialized cases. This is important since
you usually want to specialize the expected type for your contained
expressions.

Currently you don't do that for 'Prova'. You have to use something like
state.withExpection(..).computeTypes(prova.campo).

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 18.04.13 22:59, schrieb andrea rossi:
> thank you for you replies
>
> my grammar :
> grammar org.xtext.example.jade.Jade with org.eclipse.xtext.xbase.Xbase
> generate jade "htp://www.xtext.org/example/jade/Jade"
>
> import 'htp://www.eclipse.org/xtext/xbase/Xbase' as xbase
>
>
>
> Model:
> 'package' name = QualifiedName elements+=AbstractElement*;
>
>
> AbstractElement :
> AbstractBehaviour | AgentJade
> ;
>
> AgentJade:
> 'agent' name=ValidID '{' behaviours += AddBehaviour*
> messages += Message*
> '}';
>
> AddBehaviour : 'add behaviour' name=ValidID 'type' type =
> [AbstractBehaviour|ValidID]
> ;
>
> Message returns xbase::XExpression: SendMessage | Prova
> ;
>
> SendMessage returns xbase::XExpression: {SendMessage}
> 'send message' name = ValidID '{'
>
> (('sender' '=' sender = STRING)? &
> ('content' '=' content = STRING)? &
> //('language' '=' language = STRING)? &
> //('ontology' '=' ontology = STRING)? &
> ('performative' '=' performative = Performative) &
> ('receivers' '{' (receivers += (MessageReceivers)+) '}' ) )
>
> '}'
> ;
>
>
>
> MessageReceivers : 'receiver =' receiver = STRING ;
> enum Performative :
> REQUEST | INFORM | QUERY_IF | CFP | PROPOSE | ACCEPT_PROPOSAL |
> REJECT_PROPOSAL //da completare
> ;
>
> AbstractBehaviour : SimpleBehaviour | Behaviour
> ;
>
> Behaviour : 'behaviour' name=ValidID 'is' typeB = 'Behaviour' '{'
> (body=XExpressionInsideBlock';'?)
> '}'
> ;
>
> SimpleBehaviour : 'behaviour' name=ValidID 'is' typeSB = TypeSB '{'
> (body=XExpressionInsideBlock ';'?)
> '}'
> ;
>
> enum TypeSB : OneShotBehaviour | CiclicBehaviour ;
>
> XExpressionInsideBlock returns xbase::XExpression:
> XVariableDeclaration | XExpression | Message;
>
>
> Prova returns xbase::XExpression : {Prova} 'receive message do' '{'
> campo = XExpressionInsideBlock '}'
> ;
>
>
>
> my compiler :
> class JadeCompiler extends XbaseCompiler {
>
> override protected doInternalToJavaStatement(XExpression expr,
> ITreeAppendable it, boolean isReferenced) {
> switch expr {
> SendMessage : {
>
> newLine
>
> append('''
> ACLMessage «expr.name» = new
> ACLMessage(ACLMessage.«expr.performative»);
> «IF expr.sender != null»
> «expr.name».setSender(new AID
> ("«expr.sender»",AID.ISLOCALNAME));
> «ENDIF»
> «IF expr.content != null»
> «expr.name».setContent("«expr.content»");
> «ENDIF»
> «FOR r : expr.receivers»
> «expr.name».addReceiver(new AID
> ("«r.receiver»",AID.ISLOCALNAME));
> «ENDFOR»
> send(«expr.name»);
> ''')
>
> }
>
> Prova : {
> doInternalToJavaStatement(expr.campo, it, isReferenced)
> append('''
> ACLMessage msg = receive();
> if (msg!=null){}
> ''')
>
>
>
> }
>
>
> default :
> super.doInternalToJavaStatement(expr, it, isReferenced)
> }
> }
>
> override protected internalToConvertedExpression(XExpression obj,
> ITreeAppendable it) {
> if (hasName(obj))
> append(getName(obj))
> else super.internalToConvertedExpression(obj, it)
> }
>
> }
>
>
> my AbstractModelInferrer :
>
> class JadeJvmModelInferrer extends AbstractModelInferrer {
>
> @Inject extension JvmTypesBuilder
>
> @Inject extension IQualifiedNameProvider
>
> def dispatch void infer(Model element,
> IJvmDeclaredTypeAcceptor acceptor, boolean
> isPrelinkingPhase) {
> for (a : element.elements) {
> switch a {
> AbstractBehaviour : {
> switch a {
> SimpleBehaviour : {
>
> acceptor.accept(a.toClass(a.fullyQualifiedName)).initializeLater [
> superTypes +=
> a.newTypeRef('jade.core.behaviours.'+ a.typeSB.toString)
> members += a.toConstructor[
> documentation = '''...'''
> parameters += toParameter("agent",
> newTypeRef(a, 'jade.core.Agent'))
> body = [
> append('''
> super(agent);
> ''')
> ]
> ]
> members +=
> a.toMethod("action",a.newTypeRef(Void::TYPE))[
> body = a.body
> ]
> ]
>
> }
> }
> }
>
>
> AgentJade : {
>
> acceptor.accept(a.toClass(a.fullyQualifiedName)).initializeLater [
> documentation = a.documentation
> superTypes += a.newTypeRef('jade.core.Agent')
> members +=
> a.toMethod("setup",a.newTypeRef(Void::TYPE))[
> body = [append('''
> «FOR b : a.behaviours»
> «b.type.name» «b.name» = new
> «b.type.name»(this);
> addBehaviour(«b.name»);
> «ENDFOR»
> ''')
> for (m : a.messages) {
> switch m {
> SendMessage : {
> append('''
> ACLMessage «m.name» = new
> ACLMessage(ACLMessage.«m.performative»);
> «IF m.sender != null»
> «m.name».setSender(new
> AID ("«m.sender»",AID.ISLOCALNAME));
> «ENDIF»
> «IF m.content != null»
>
> «m.name».setContent("«m.content»");
> «ENDIF»
> «FOR r : m.receivers»
>
> «m.name».addReceiver(new AID ("«r.receiver»",AID.ISLOCALNAME));
> «ENDFOR»
> send(«m.name»);
> ''')
> }//sendMe
> }//switch
> }//for
>
>
> ]//body
>
> ]
>
> ]
> }//agent jade
> }//switch
> }//for
>
> }//infer
>
>
> }//class
>
>
>
>
>
> my RuntimeModule :
>
>
> public class JadeRuntimeModule extends
> org.xtext.example.jade.AbstractJadeRuntimeModule {
>
>
>
> public Class<? extends XbaseCompiler> bindXbaseCompiler() {
> return JadeCompiler.class;
>
> }
>
> @Override
> public Class<? extends ITypeComputer> bindITypeComputer() {
> return JadeTypeComputer.class;
> }
>
> }
>
>
>
>
>
> my TypeComputer :
> class JadeTypeComputer extends XbaseTypeComputer {
>
> override computeTypes(XExpression expression, ITypeComputationState
> state) {
> if(expression instanceof SendMessage) {
> _computeTypes(expression as SendMessage, state);
> } else if (expression instanceof Prova){
> _computeTypes(expression as Prova,state)}
> else {
> super.computeTypes(expression, state)
> }
> }
>
> protected def _computeTypes(SendMessage expression,
> ITypeComputationState state) {
> //super._computeTypes(expression as XExpression, state)
> state.acceptActualType(getTypeForName(typeof(Void), state))
> }
>
> protected def _computeTypes(Prova expression, ITypeComputationState
> state) {
> //super.computeTypes(expression.campo, state)
> state.acceptActualType(getTypeForName(typeof(Void), state))
> }
>
>
>
> }
>
>
>
> Error :
>
> at
> org.eclipse.xtext.xbase.compiler.TypeReferenceSerializer.serialize(TypeReferenceSerializer.java:90)
>
> at
> org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.serialize(AbstractXbaseCompiler.java:342)
>
> at
> org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.serialize(AbstractXbaseCompiler.java:338)
>
> at
> org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.serialize(AbstractXbaseCompiler.java:334)
>
> at
> org.eclipse.xtext.xbase.compiler.XbaseCompiler.appendVariableTypeAndName(XbaseCompiler.java:663)
>
> at
> org.eclipse.xtext.xbase.compiler.XbaseCompiler._toJavaStatement(XbaseCompiler.java:643)
>
> at
> org.eclipse.xtext.xbase.compiler.XbaseCompiler.doInternalToJavaStatement(XbaseCompiler.java:441)
>
> at
> org.xtext.example.jade.jvmmodel.JadeCompiler.doInternalToJavaStatement(JadeCompiler.java:93)
>
> at
> org.xtext.example.jade.jvmmodel.JadeCompiler.doInternalToJavaStatement(JadeCompiler.java:83)
>
> at
> org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.internalToJavaStatement(AbstractXbaseCompiler.java:297)
>
> at
> org.eclipse.xtext.xbase.compiler.AbstractXbaseCompiler.compile(AbstractXbaseCompiler.java:236)
>
> at
> org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateExecutableBody(JvmModelGenerator.java:1111)
>
> at
> org.eclipse.xtext.xbase.compiler.JvmModelGenerator._generateMember(JvmModelGenerator.java:809)
>
> at
> org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateMember(JvmModelGenerator.java:1777)
>
> at
> org.eclipse.xtext.xbase.compiler.JvmModelGenerator$2.apply(JvmModelGenerator.java:286)
>
> at
> org.eclipse.xtext.xbase.compiler.JvmModelGenerator$2.apply(JvmModelGenerator.java:1)
>
> at
> org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_doubleArrow(ObjectExtensions.java:139)
>
> at
> org.eclipse.xtext.xbase.compiler.LoopExtensions$1.apply(LoopExtensions.java:39)
>
> at
> org.eclipse.xtext.xbase.lib.IterableExtensions.forEach(IterableExtensions.java:399)
>
> at
> org.eclipse.xtext.xbase.compiler.LoopExtensions.forEach(LoopExtensions.java:42)
>
> at
> org.eclipse.xtext.xbase.compiler.JvmModelGenerator._generateBody(JvmModelGenerator.java:290)
>
> at
> org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateBody(JvmModelGenerator.java:1751)
>
> at
> org.eclipse.xtext.xbase.compiler.JvmModelGenerator.generateType(JvmModelGenerator.java:209)
>
> at
> org.eclipse.xtext.xbase.compiler.JvmModelGenerator._internalDoGenerate(JvmModelGenerator.java:200)
>
> at
> org.eclipse.xtext.xbase.compiler.JvmModelGenerator.internalDoGenerate(JvmModelGenerator.java:1734)
>
> at
> org.eclipse.xtext.xbase.compiler.JvmModelGenerator.doGenerate(JvmModelGenerator.java:181)
>
> at
> org.eclipse.xtext.builder.BuilderParticipant.handleChangedContents(BuilderParticipant.java:291)
>
> at
> org.eclipse.xtext.builder.BuilderParticipant.build(BuilderParticipant.java:221)
>
> at
> org.eclipse.xtext.builder.impl.RegistryBuilderParticipant.build(RegistryBuilderParticipant.java:60)
>
> at
> org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:170)
> at
> org.eclipse.xtext.builder.impl.XtextBuilder.incrementalBuild(XtextBuilder.java:146)
>
> at
> org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:95)
> at
> org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:726)
> at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
> at
> org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
>
> at
> org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
>
> at
> org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
> at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
> at
> org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
>
> at
> org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
>
> at
> org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
> at
> org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
>
> at
> org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
> at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
>
>
>
>
Re: Error in extending xbase expressions [message #1045147 is a reply to message #1044812] Fri, 19 April 2013 17:11 Go to previous message
andrea rossi is currently offline andrea rossi
Messages: 23
Registered: April 2013
Junior Member
Hi,

Thank you for help

Sebastian i did as you said and it seem work...
Previous Topic:Compile Xbase expression at arbitrary position using JvmModelInferrer and XbaseCompiler in Xtext 2.4
Next Topic:Two questions with regards to plantuml?
Goto Forum:
  


Current Time: Fri Aug 29 06:27:34 EDT 2014

Powered by FUDForum. Page generated in 0.03054 seconds