Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Restricting Java-like statements in method bodies
Restricting Java-like statements in method bodies [message #1691499] Tue, 07 April 2015 16:18 Go to next message
Som 2015 is currently offline Som 2015Friend
Messages: 16
Registered: March 2015
Junior Member
Hello,

I have a DSL, which allows Java-like classes to be defined. I have some methods with a special semantics: they must not be able to invoke local methods defined within the class. How can we implement such a restriction? I use Xbase...

Thanks
Re: Restricting Java-like statements in method bodies [message #1691512 is a reply to message #1691499] Tue, 07 April 2015 17:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

what about inferring a separate class with a single method and delegate to it from the main class


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Restricting Java-like statements in method bodies [message #1691535 is a reply to message #1691512] Tue, 07 April 2015 23:37 Go to previous messageGo to next message
Som 2015 is currently offline Som 2015Friend
Messages: 16
Registered: March 2015
Junior Member
Hello,

Can you please elaborate more on this? I am not an expert on this.

This is how my code should look like (access to both class-level methods and variables must be reported as error, however, the access to local variables defined in the method is fine)

myClass{

int my_var;
my_normal_method(){...}

my_especial_method (){
int i;

//it is OK to invoke on external methods defined in other classes
Helper.method();

//it is OK to access local variables
i = 10;

// this must be reported as an error; there should be no access to local variables
my_var = 10;

// this must be reported as an error, there should be no access to local methods
my_normal_method();

}

}

Thanks

[Updated on: Wed, 08 April 2015 00:53]

Report message to a moderator

Re: Restricting Java-like statements in method bodies [message #1691547 is a reply to message #1691535] Wed, 08 April 2015 05:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

this is something different. i think the only way to prevent this is to write a custom validation. (adapt yourdslvalidator)


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

[Updated on: Wed, 08 April 2015 05:18]

Report message to a moderator

Re: Restricting Java-like statements in method bodies [message #1691619 is a reply to message #1691547] Wed, 08 April 2015 13:57 Go to previous messageGo to next message
Som 2015 is currently offline Som 2015Friend
Messages: 16
Registered: March 2015
Junior Member
Hello

This could also be seen as an scoping issue: the class-level variables and methods must not be visible inside my_especial_method.

I have already payed around validators. The issue here is to be able to validate individual statements within XExpressionOrVarDeclaration. Any idea how to do this? I could not find an example usage of validator for XExpressionOrVarDeclaration.

Thanks
Re: Restricting Java-like statements in method bodies [message #1691623 is a reply to message #1691619] Wed, 08 April 2015 14:10 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

have a look at XFeatureCall.

P.S:

if class level stuff shall not be visible then my first approach will work! it does not work if some stuff shall be visible and some not

if you have following dsl

class X {
   var y : String
   def z() {
   }
   special a() {
       println("hello")
   }
  
}


Then infer following java code and it will work automatically

public class X {
    String y;
    public void z() {
    }
    public static void a() {
          X_A_Delegate.a(); // body = '''/* code here */'''
    }
}

public class X_A_Delegate {
public static void a() {
   System.out.println("Hello"); //body = XExpression
}
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Missing constraint on Eclipse product configuaration
Next Topic:Custom Serialization
Goto Forum:
  


Current Time: Tue Apr 23 11:43:42 GMT 2024

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

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

Back to the top