Skip to main content



      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 12:18 Go to next message
Eclipse UserFriend
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 13:48 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

what about inferring a separate class with a single method and delegate to it from the main class
Re: Restricting Java-like statements in method bodies [message #1691535 is a reply to message #1691512] Tue, 07 April 2015 19:37 Go to previous messageGo to next message
Eclipse UserFriend
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: Tue, 07 April 2015 20:53] by Moderator

Re: Restricting Java-like statements in method bodies [message #1691547 is a reply to message #1691535] Wed, 08 April 2015 01:16 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

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

[Updated on: Wed, 08 April 2015 01:18] by Moderator

Re: Restricting Java-like statements in method bodies [message #1691619 is a reply to message #1691547] Wed, 08 April 2015 09:57 Go to previous messageGo to next message
Eclipse UserFriend
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 10:10 Go to previous message
Eclipse UserFriend
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
}
}
Previous Topic:Missing constraint on Eclipse product configuaration
Next Topic:Custom Serialization
Goto Forum:
  


Current Time: Wed Jul 23 13:25:33 EDT 2025

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

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

Back to the top