Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Inject xbasecompiler
Inject xbasecompiler [message #1698432] Mon, 15 June 2015 16:30 Go to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
I have a set of languages implemented with xtext. These languages also common aspects that are defined in a shared xtext language. The common language uses xbase to define variable and expression.

Then, in one language, I would like to process and compile the xbase variable and expression. The language itself does not use xbase directly but uses it through the common language.

When trying to use the XbaseCompiler, I then added a dependency with an injection like this (as defined in [1]):

@Inject XbaseCompiler xbaseCompiler

However, when starting my project, I got a long serie of exception (see below). How to know how to inject the appropriate class? And how to debug injected classes?

Thanks for any help or suggestion!

[1] http://www.rcp-vision.com/1796/xtext-2-1-using-xbase-variables/ and http://www.rcp-vision.com/1640/xtext-2-1-using-xbase-expressions/


Caused by: com.google.inject.internal.util.$ComputationException: com.google.inject.internal.util.$ComputationException: java.lang.StackOverflowError
at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:553)
at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:419)
at com.google.inject.internal.util.$CustomConcurrentHashMap$ComputingImpl.get(CustomConcurrentHashMap.java:2041)
at com.google.inject.internal.FailableCache.get(FailableCache.java:50)
at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:49)
at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:125)
at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:521)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:847)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:772)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:256)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:205)
at com.google.inject.internal.InjectorImpl.createImplementedByBinding(InjectorImpl.java:732)
at com.google.inject.internal.InjectorImpl.createUninitializedBinding(InjectorImpl.java:618)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:845)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:772)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:256)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:205)
at com.google.inject.internal.InjectorImpl.getInternalFactory(InjectorImpl.java:853)
at com.google.inject.internal.SingleFieldInjector.<init>(SingleFieldInjector.java:41)
at com.google.inject.internal.MembersInjectorStore.getInjectors(MembersInjectorStore.java:125)
at com.google.inject.internal.MembersInjectorStore.createWithListeners(MembersInjectorStore.java:95)
at com.google.inject.internal.MembersInjectorStore.access$000(MembersInjectorStore.java:34)
at com.google.inject.internal.MembersInjectorStore$1.create(MembersInjectorStore.java:42)
at com.google.inject.internal.MembersInjectorStore$1.create(MembersInjectorStore.java:39)
at com.google.inject.internal.FailableCache$1.apply(FailableCache.java:39)
at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:549)
... 6559 more
Caused by: com.google.inject.internal.util.$ComputationException: java.lang.StackOverflowError
at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:553)
at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:419)
at com.google.inject.internal.util.$CustomConcurrentHashMap$ComputingImpl.get(CustomConcurrentHashMap.java:2041)
at com.google.inject.internal.FailableCache.get(FailableCache.java:50)
at com.google.inject.internal.MembersInjectorStore.get(MembersInjectorStore.java:65)
at com.google.inject.internal.ConstructorInjectorStore.createConstructor(ConstructorInjectorStore.java:73)
at com.google.inject.internal.ConstructorInjectorStore.access$000(ConstructorInjectorStore.java:28)
at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:36)
at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:32)
at com.google.inject.internal.FailableCache$1.apply(FailableCache.java:39)
at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:549)
... 6584 more
Caused by: java.lang.StackOverflowError
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.defineClass(ModuleClassLoader.java:272)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.defineClass(ClasspathManager.java:632)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findClassImpl(ClasspathManager.java:588)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClassImpl(ClasspathManager.java:540)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:527)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:324)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:320)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:395)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:345)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:337)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:551)
at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:419)
at com.google.inject.internal.util.$CustomConcurrentHashMap$ComputingImpl.get(CustomConcurrentHashMap.java:2041)
at com.google.inject.internal.FailableCache.get(FailableCache.java:50)
at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:49)
at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:125)
at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:521)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:847)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:772)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:256)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:205)
at com.google.inject.internal.InjectorImpl.getInternalFactory(InjectorImpl.java:853)
at com.google.inject.internal.SingleFieldInjector.<init>(SingleFieldInjector.java:41)
at com.google.inject.internal.MembersInjectorStore.getInjectors(MembersInjectorStore.java:125)
at com.google.inject.internal.MembersInjectorStore.createWithListeners(MembersInjectorStore.java:95)
at com.google.inject.internal.MembersInjectorStore.access$000(MembersInjectorStore.java:34)
at com.google.inject.internal.MembersInjectorStore$1.create(MembersInjectorStore.java:42)
at com.google.inject.internal.MembersInjectorStore$1.create(MembersInjectorStore.java:39)
at com.google.inject.internal.FailableCache$1.apply(FailableCache.java:39)
at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:549)
... 6594 more
Re: Inject xbasecompiler [message #1698450 is a reply to message #1698432] Mon, 15 June 2015 18:53 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
Hi,

More generally, where is it possible to find example about how to use xbase and resolve types? I just want to be able to resolve types of declared types and compute/compile their values (when a variable has a pre-defined value associated with the declaration).

Thanks.
Re: Inject xbasecompiler [message #1698454 is a reply to message #1698450] Mon, 15 June 2015 19:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Hi,

unless you have own expressions:
you should not have to do that all. simply implement jvmmodelinferrer, the rest should be done by xbase yourself


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Inject xbasecompiler [message #1698468 is a reply to message #1698432] Mon, 15 June 2015 19:48 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1813
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 15/06/2015 18:30, Julien Delange wrote:
> I have a set of languages implemented with xtext. These languages also
> common aspects that are defined in a shared xtext language. The common
> language uses xbase to define variable and expression.
>
> Then, in one language, I would like to process and compile the xbase
> variable and expression. The language itself does not use xbase directly
> but uses it through the common language.
>
> When trying to use the XbaseCompiler, I then added a dependency with an
> injection like this (as defined in [1]):
>
> @Inject XbaseCompiler xbaseCompiler
>
> However, when starting my project, I got a long serie of exception (see
> below). How to know how to inject the appropriate class? And how to
> debug injected classes?
>
> Thanks for any help or suggestion!
>
> [1] http://www.rcp-vision.com/1796/xtext-2-1-using-xbase-variables/ and
> http://www.rcp-vision.com/1640/xtext-2-1-using-xbase-expressions/
>

Hi Julien

those blog posts I wrote are rather old now, and won't work anymore: you
should really use a JvmModelInferrer if you use Xbase :)

cheers
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: Inject xbasecompiler [message #1698470 is a reply to message #1698468] Mon, 15 June 2015 20:15 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
do you have any code example to use them? Obviously, this is very confusing and finding up to date examples/source code is hard!

Thanks for any help!
Re: Inject xbasecompiler [message #1698471 is a reply to message #1698470] Mon, 15 June 2015 20:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
have a look at the domain model example and https://www.eclipse.org/Xtext/documentation/201_sevenlang_introduction.html

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Inject xbasecompiler [message #1698484 is a reply to message #1698471] Mon, 15 June 2015 23:24 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
Just by curiosity, are the examples of the seven languages available online?
Re: Inject xbasecompiler [message #1698486 is a reply to message #1698484] Tue, 16 June 2015 00:00 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
Also, when looking at the domain model example, it seems that the ModelInferer is used mostly to generate code. Is there any method/helper to just get the type and compiled expression from a type declaration?
Re: Inject xbasecompiler [message #1698495 is a reply to message #1698486] Tue, 16 June 2015 03:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Can you be more specific

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Inject xbasecompiler [message #1698546 is a reply to message #1698484] Tue, 16 June 2015 10:59 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1813
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 16/06/2015 01:24, Julien Delange wrote:
> Just by curiosity, are the examples of the seven languages available
> online?

https://github.com/xtext/seven-languages-xtext

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
HOME: http://www.lorenzobettini.it
Xtext Book:
http://www.packtpub.com/implementing-domain-specific-languages-with-xtext-and-xtend/book


Re: Inject xbasecompiler [message #1698604 is a reply to message #1698546] Tue, 16 June 2015 15:37 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
@Christian, more specifically, I am trying to get the variable type from a XVariableDeclaration without having declared the type explicitly.
Let's say I have the following declarations:
val implicit = 5
val float explicit = "str"
The type for the explicit value is easy to get. But to get the type for the implicit value, I then have to find the inferred type. For that, I do something like:
val typeRef = xvar.inferredType
println ("var type implicit" + typeRef.simpleName)

But when I run this code, I got an exception (see below). That is why I am also wondering if there is a specific example to see how to infer/resolve types.

Sorry if the first question was too quick and not so detail and thanks for any suggestion!

java.lang.IllegalStateException: equivalent could not be computed
at org.eclipse.xtext.xbase.typesystem.InferredTypeIndicator.getTypeReference(InferredTypeIndicator.java:83)
at org.eclipse.xtext.xtype.impl.XComputedTypeReferenceImplCustom.getEquivalent(XComputedTypeReferenceImplCustom.java:46)
at org.eclipse.xtext.common.types.impl.JvmSpecializedTypeReferenceImplCustom.getSimpleName(JvmSpecializedTypeReferenceImplCustom.java:59)
Re: Inject xbasecompiler [message #1698607 is a reply to message #1698604] Tue, 16 June 2015 15:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
And why not use the inferrer?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Inject xbasecompiler [message #1698608 is a reply to message #1698607] Tue, 16 June 2015 16:00 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
I assume this is what I am trying to do, no?

than I am invoking xvar.inferredType, it should then return the inferred type, right? What I do not understand is why it cannot resolve the type and I got the exception.
Re: Inject xbasecompiler [message #1698610 is a reply to message #1698608] Tue, 16 June 2015 16:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
No. The basic idea on the jvmmodel inferrer is to map dsl concepts to java types and the expression or list of expressions (block) to method bodys or field initializers. The will automatically be generated at these places in the genersted java code

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Inject xbasecompiler [message #1698618 is a reply to message #1698610] Tue, 16 June 2015 17:00 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
I understand in case of use of special type. But what about general types such as int

For example, when I declare:
val implicit = 5

the Model Inferrer should report an int, no?
I understand I have to implement a type inferrer for my DSL types - but for generic types, it should be automatically supported by xbase, no?
Re: Inject xbasecompiler [message #1698619 is a reply to message #1698618] Tue, 16 June 2015 17:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Hi i think you confuse jvmmodelinferrer and type inference. Maybe you can give us a sample grammar and sample model with context

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Inject xbasecompiler [message #1698623 is a reply to message #1698619] Tue, 16 June 2015 17:54 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
Sure! Thanks for your help! I modified the domainmodel as follows:

grammar org.eclipse.xtext.example.domainmodel.Domainmodel with org.eclipse.xtext.xbase.Xbase

generate domainmodel "http://www.xtext.org/example/Domainmodel"

DomainModel:
	importSection=XImportSection?
	elements+=AbstractElement*;
	
AbstractElement:
	PackageDeclaration | Entity;

PackageDeclaration:
	'package' name=QualifiedName '{'
		elements+=AbstractElement*
	'}';

Entity:
	'entity' name=ValidID ('extends' superType=JvmParameterizedTypeReference)? '{'
	('features'
		features+=Feature*)?
	('vars'
		vars+=XVariableDeclaration*)?
	'}';

Feature:
	Property | Operation ;

Property:
	name=ValidID ':' type=JvmTypeReference;

Operation:
	'op' name=ValidID '(' (params+=FullJvmFormalParameter (',' params+=FullJvmFormalParameter)*)? ')' (':' type=JvmTypeReference)? 
		body=XBlockExpression;


Now, I have the following code

package blabla
{
	entity foo
	{
		features
			myprop : int
			op op1 (int param1, int param2) : int
			{
				return param1;
			}
		vars
			val implicit1 = 4
			val implicit2 = 5
			val float explicit = 5.0
			val Integer integerObject = new Integer(5)
			val foobar =  implicit1 + implicit2
	}
}   


With that, I have two goals:
1. Detect the type of variables that are not strongly types but have an expression. For example, for implicit1, return int
2. Compiles the expression. For example, for foobar, having something that returns 9 directly

So, I tried to dig the documentation but it seems that some of it is outdated, so, having some pointers on where I should look into will definitively help!

Thanks!

Julien.

Re: Inject xbasecompiler [message #1698625 is a reply to message #1698623] Tue, 16 June 2015 18:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
hi,

shall the vals be reassignable? are they stateful (reassignment)? or like fields in java?
(that what features already are?)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 16 June 2015 18:33]

Report message to a moderator

Re: Inject xbasecompiler [message #1698627 is a reply to message #1698625] Tue, 16 June 2015 18:34 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
The vals cannot be reassigned - they are static and fixed. Like a final field in java.
Re: Inject xbasecompiler [message #1698628 is a reply to message #1698627] Tue, 16 June 2015 18:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
so why not change grammar to:

('vars'
        vars+=Constant*)?
...
Constant:
    "val" (type=JvmParameterizedTypeReference)? name=ID "=" init=XExpression 
;


and use in the inferrer

for (v : entity.vars) {
			    members+=v.toField(v.name, v.type ?: inferredType) [
			         final = true
			        static = true
			        visibility = JvmVisibility.PUBLIC
			        initializer = v.init
			        
			    ]
			}


(5.0 is a double literal in xbase though)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 16 June 2015 18:47]

Report message to a moderator

Re: Inject xbasecompiler [message #1698632 is a reply to message #1698628] Tue, 16 June 2015 19:19 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
Thanks for the suggestion! On the other hand, how can I still infer the type when I do not specify it explicitly? Also, how to compute directly the value? For example, when having

val implicit1 = 4
val implicit2 = 5
val foobar = implicit1 + implicit2

how can I compile the expression associated with foobar and have an integer object which value is 9?
Re: Inject xbasecompiler [message #1698634 is a reply to message #1698632] Tue, 16 June 2015 19:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Hi,

i dont get that. isnt that equivalent? arent you mixing compiling and interpreting?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 16 June 2015 19:35]

Report message to a moderator

Re: Inject xbasecompiler [message #1698636 is a reply to message #1698634] Tue, 16 June 2015 19:45 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
I just want a feature that will give me the result of foobar directly - so, I guess it means compiling directly the expression
Re: Inject xbasecompiler [message #1698637 is a reply to message #1698636] Tue, 16 June 2015 19:47 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
Also, do you have any clue about how to find the type of a variable which has a value but NOT an explicit type?

Thanks for any help!
Re: Inject xbasecompiler [message #1698638 is a reply to message #1698637] Tue, 16 June 2015 19:52 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
of course i have, but this will not happen if you do not infer something from your stuff.
only then the type will be calculated by the type computer and the scope (for references) is set properly.

if this is the case you can access types. but only at generation time, not on inferral time.
org.eclipse.xtext.xbase.typesystem.IBatchTypeResolver.resolveTypes(EObject) would help you with that.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Inject xbasecompiler [message #1698639 is a reply to message #1698638] Tue, 16 June 2015 20:13 Go to previous messageGo to next message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
ok, I do not know if I explained the issue. I tried to put the project on https://github.com/juli1/xtext-debug (the domainmodel* projects).
Then, using the following file
package blabla
{
entity foo
{
features
myprop : int
op op1 (int param1, int param2) : int
{
return param1;
}
vars
val Integer implicit1 = new Integer (10)
val int implicit2 = 5
val Integer explicit = new Integer(5)
}
}


I added in the outline an action that is trying to compile/find the value of each value. And each time, with xtext 2.8.2, I got an exception. I am just trying to compile the xexpression assigned to the variable and get the result but did not get anything. This is where I have some issue for now and in fact, would like to have an Object as a result of the compilation of the right part
Re: Inject xbasecompiler [message #1698643 is a reply to message #1698639] Tue, 16 June 2015 21:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
hi,
still, if you do not use jvmmodel inferrer there will be no type calculation ?!? (XbaseTypeComputer will never be called by LogicalContainerAwareReentrantTypeResolver, variables will not be visible from each other)
thus i strictly recommend you to use that. e.g. as i proposed it.

or something like that

Entity:
	'entity' name=ValidID ('extends' superType=JvmParameterizedTypeReference)? '{'
	('features'
		features+=Feature*)?
	(vars=Vars)?
	'}';
	
	
	Vars returns xbase::XBlockExpression:
		{Vars}'vars'
		expressions+=XVariableDeclaration*
	;


if (entity.vars != null) {
				members+=entity.toMethod("vars", Void.TYPE.typeRef()) [
			         body = entity.vars
			        
			    ]
			}



still, compile and interpret is not the same at all ?!?

class ProcessLogicDefault implements IProcessLogic
{
	@Inject extension JvmTypesBuilder
	@Inject extension IQualifiedNameProvider
	
	@Inject XbaseInterpreter interpreter
	
	
	override process(PackageDeclaration pkg) {
		println ("package" + pkg)
		pkg.elements.filter(Entity).forEach[e | processEntity (e)]
	}
	
	def processEntity(Entity entity) {
		val ctx = new DefaultEvaluationContext()
		entity.vars.expressions.filter(XVariableDeclaration).forEach[v | processVar(v, ctx)]
	}
	
	def processVar(XVariableDeclaration v, IEvaluationContext ctx) {
		try {
			val IEvaluationResult r = interpreter.evaluate(v, ctx, CancelIndicator.NullImpl)
			println(v.name + " = " + ctx.getValue(QualifiedName.create(v.name)))
		} catch(Exception e) {
			e.printStackTrace
		}
		
	}
	
	
	

	
}



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Inject xbasecompiler [message #1698649 is a reply to message #1698643] Wed, 17 June 2015 00:23 Go to previous message
Julien Delange is currently offline Julien DelangeFriend
Messages: 82
Registered: October 2011
Member
Thank you a zillion of times - this is exactly what I was struggling with!

Thanks again a lot!

Julien.
Previous Topic:full gradle project
Next Topic:Grammar problems, "No viable alternative at input..."
Goto Forum:
  


Current Time: Wed Sep 25 09:56:33 GMT 2024

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

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

Back to the top