Home » Language IDEs » Java Development Tools (JDT) » Running JavaCode on-the-fly from String(Abstraction level : in the between....)
| | | | | |
Re: Running JavaCode on-the-fly from String [message #1690879 is a reply to message #1690864] |
Tue, 31 March 2015 14:04   |
Eclipse User |
|
|
|
Comments below.
On 31/03/2015 6:15 PM, Edoaurd Batot wrote:
> Well XCore doesn't fit as it seems I'll need months to get the meaning
> of that new tech.
Well of course you have to learn something new, and there's always the
feeling that you'll better understand what you do from scratch than some
complex thing someone else did.
> I really want to do the simple check :
> "this.name.length > 4" which is embedded in a String, and will be
> executed as-it-is.
In Xcore that would be an operation
> (we imagine the target properly built, and the code properly written -
> no exceptions).
> Well, if I can't, I'll build a DSL etc.
Using Xtext. That will be a few months too. Or from scratch, also
something that will grow until you wish you'd used Xtext.
> But it won't be much generic then.
class Thing
{
String name
op boolean hasValidName()
{
name.length > 4
}
}
>
> Executing this test on a dynamic instance is the final goal : e.g. I'm
> playing with DynamicEObjectImpl and their EStructuralFeature to go up
> and down the meta-hierarchy.
Xcore supports creating dynamic instance and you can use eInvoke to
invoke the operations.
>
> Writing this, I wonder whether it is possible without changing the
> whole structure (as with XCore :s).
>
> See you, and thanks again !
|
|
|
Re: Running JavaCode on-the-fly from String [message #1690894 is a reply to message #1690879] |
Tue, 31 March 2015 15:38   |
Eclipse User |
|
|
|
May I plug the few Xcore features you are talking about in a Java project without rebuilding the entire project ?
Otherwise, you have to understand I can't use it.
class Thing{
String name
op boolean hasValidName(){
name.length > 4
}
}
What's this ? I mean, I undertand it's Xcore code, and I understand it calculates the length of the name of the things. But well, what is it here for ?
I'm using Ecore instances upon which I'd like to execute the code. If the next input is "super.getSurname.startsWith("prefix")", how do I generate the "class Things etc" ?
THe name is also an example, as the type of the name. THe structure containing the checks is a "ramified" one (relax-augment-modify) but the application will act on the real instance : a name could be a class in itself, a reference, a supertype... I can't plug a pseudo class so easy... But I would love you to show me I'm wrong 
About JS, it is the same thing : how do I execute the semantics of JS lines into Java ? The "length<4" could be a "this.somethingelse instanceof AnotherClass".
I've never tried to mix java and JS, I'll have a look but from where I am, it seems tricky.
Abstraction is a nasty thing.
Thanks for your help.
[Updated on: Tue, 31 March 2015 15:40] by Moderator
|
|
|
Re: Running JavaCode on-the-fly from String [message #1690896 is a reply to message #1690894] |
Tue, 31 March 2015 15:44   |
Eclipse User |
|
|
|
It is totally easy to execute JavaScript inside Java and access
informations from Java to JavaScript and the other way round.
Same goes for groovy, jython, jruby they are all accessible through the
ScriptEngineManager which is JSRed, JavaScript is shipped with your VM
by default.
Tom
On 31.03.15 21:38, Edoaurd Batot wrote:
> XCore is a factory, I would need a hammer.
>
> May I plug the few lines you are talking about in a Java project without
> rebuilding the entire project ? Otherwise, you have to understand I
> can't use it.
>
> class Thing{
> String name
> op boolean hasValidName(){
> name.length > 4
> }
> }
>
> What's this ? I mean, I undertand it's Xcore code, and I understand it
> calculates the length of the name of the things. But well, what is it
> here for ? I'm using Ecore instances upon which I'd like to execute the
> code. If the next input is "super.getSurname.startsWith("prefix")", how
> do I generate the "class Things etc" ? THe name is also an example, as
> the type of the name. THe structure containing the checks is a
> "ramified" one (relax-augment-modify) but the application will act on
> the real instance : a name could be a class in itself, a reference, a
> supertype... I can't plug a pseudo class so easy... But I would love you
> to show me I'm wrong :s
>
>
> About JS, it is the same thing : how do I execute the semantics of JS
> lines into Java ? The "length<4" could be a "this.somethingelse
> instanceof AnotherClass".
> I've never tried to mix java and JS, I'll have a look but from where I
> am, it seems tricky.
>
> Abstraction is a nasty thing.
> Thanks for your help.
>
|
|
|
Re: Running JavaCode on-the-fly from String [message #1690936 is a reply to message #1690894] |
Wed, 01 April 2015 01:45  |
Eclipse User |
|
|
|
Comments below.
On 31/03/2015 9:38 PM, Edoaurd Batot wrote:
> XCore is a factory, I would need a hammer.
:-)
>
> May I plug the few lines you are talking about in a Java project
> without rebuilding the entire project ? Otherwise, you have to
> understand I can't use it.
>
> class Thing{
> String name
> op boolean hasValidName(){
> name.length > 4
> }
> }
>
> What's this ?
It's an XClass, an EClass, and a GenClass. Open a *.xcore file in the
reflective editor and you'll see it's all three
> I mean, I undertand it's Xcore code, and I understand it calculates
> the length of the name of the things. But well, what is it here for ?
It induces an EOperation that you can EObject.eInvoke.
> I'm using Ecore instances upon which I'd like to execute the code.
Dynamic ones as I understand it...
> If the next input is "super.getSurname.startsWith("prefix")", how do I
> generate the "class Things etc" ? THe name is also an example, as the
> type of the name. THe structure containing the checks is a "ramified"
> one (relax-augment-modify) but the application will act on the real
> instance : a name could be a class in itself, a reference, a
> supertype... I can't plug a pseudo class so easy... But I would love
> you to show me I'm wrong :s
Well, I certainly don't want to do your work for you, but I imagine it
helps to know that a DSL for Ecore has been built with Xtext and the
expression language it uses (Xbase) is as rich as (or arguably richer
then) Java...
>
>
> About JS, it is the same thing : how do I execute the semantics of JS
> lines into Java ? The "length<4" could be a "this.somethingelse
> instanceof AnotherClass".
> I've never tried to mix java and JS, I'll have a look but from where I
> am, it seems tricky.
Yes, that's an interesting idea as well.
>
> Abstraction is a nasty thing.
> Thanks for your help.
>
|
|
|
Goto Forum:
Current Time: Sun Apr 20 16:41:44 EDT 2025
Powered by FUDForum. Page generated in 0.03621 seconds
|