Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » How to get expression as string in Java?(This question is regarding the Epsilon back-end execution engine's AST)
How to get expression as string in Java? [message #1760592] Fri, 28 April 2017 17:14 Go to next message
Sina Madani is currently offline Sina MadaniFriend
Messages: 78
Registered: November 2015
Location: York, UK
Member
Hello,

I am trying to get the name of all of the dependencies in EVL through "satisfies" calls. However, I found that the type "Expression" does not provide any way to retrieve the expression as text. I have attached the relevant code.

Apologies if this is not a suitable place for asking this or there is insufficient detail.
Re: How to get expression as string in Java? [message #1760608 is a reply to message #1760592] Fri, 28 April 2017 19:24 Go to previous messageGo to next message
Sina Madani is currently offline Sina MadaniFriend
Messages: 78
Registered: November 2015
Location: York, UK
Member
After examining the type hierarchy of "Expression", I managed to fix this by casting the Expression to a StringLiteral and calling getValue().
Re: How to get expression as string in Java? [message #1760615 is a reply to message #1760608] Fri, 28 April 2017 21:55 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1605
Registered: July 2009
Location: York, UK
Senior Member

Hi Sina,

The argument of "satisfies" may not always be a StringLiteral so it's probably a good idea to check before casting if you're not already doing this.

Cheers,
Dimitris
Re: How to get expression as string in Java? [message #1760619 is a reply to message #1760615] Fri, 28 April 2017 22:30 Go to previous messageGo to next message
Sina Madani is currently offline Sina MadaniFriend
Messages: 78
Registered: November 2015
Location: York, UK
Member
Hi Dimitris,

Thanks for pointing that out. Would you happen to know what would be the expression type for multiple parameters? I presume that arguments to "satisfies" are always the names of the NamedRule to be checked.

Thanks,
Sina
Re: How to get expression as string in Java? [message #1760620 is a reply to message #1760619] Fri, 28 April 2017 22:32 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1605
Registered: July 2009
Location: York, UK
Senior Member

Hi Sina,

Calls to "satisfies" are OperationCallExpressions so getParameterExpressions() should return their parameters.

Cheers,
Dimitris
Re: How to get expression as string in Java? [message #1760621 is a reply to message #1760620] Fri, 28 April 2017 22:46 Go to previous messageGo to next message
Sina Madani is currently offline Sina MadaniFriend
Messages: 78
Registered: November 2015
Location: York, UK
Member
Hi Dimitris,

In my code I already call getParameterExpressions(), and then cast every element of the resulting List<Expression> to List<StringLiteral>, so presumably this can never fail, since the parameters are guaranteed to be literals? Or could they be something else?

For reference, this is my current solution:

protected static Set<String> getDependencies(ModuleElement ast) {
	return ast.getChildren()
		.stream()
		.filter(me -> me instanceof ExecutableBlock)
		.map(eb -> (ExecutableBlock<?>) eb)
		.filter(EvlGraph::isDependencyWord)
		.map(eb -> eb.getChildren()
				.stream()
				.filter(bc -> bc instanceof OperationCallExpression)
				.map(oce -> (OperationCallExpression) oce)
				.filter(bc -> bc.getOperationName().equals("satisfies"))
				.collect(Collectors.toList()))
		.flatMap(List::stream)
		.map(OperationCallExpression::getParameterExpressions)
		.flatMap(List::stream)
		.map(expr -> (StringLiteral) expr)
		.map(StringLiteral::getValue)
		.collect(Collectors.toSet());
}

Re: How to get expression as string in Java? [message #1760623 is a reply to message #1760621] Fri, 28 April 2017 23:32 Go to previous messageGo to next message
Sina Madani is currently offline Sina MadaniFriend
Messages: 78
Registered: November 2015
Location: York, UK
Member
Apologies for the misunderstanding.

Having read section 4.4.1 of the Epsilon Book ("Capturing Dependencies Between Invariants"), the specification of "satisfies" operations take a string as parameter(s), however admittedly this may not be a StringLiteral. Therefore, I may have to resort to manually resolving all potential expressions to get the eventual string, or make an assumption that all parameters to "satisfies" operations will be StringLiterals. For example:

    //Stream<Expression> satisfiesParams
    .map(expr -> {
	if (expr instanceof StringLiteral)
             return ((StringLiteral) expr).getValue();
	if (expr instanceof NameExpression)
            return ((NameExpression) expr).getName();
        return expr.execute(context);
    })


Thanks,
Sina

[Updated on: Fri, 28 April 2017 23:34]

Report message to a moderator

Re: How to get expression as string in Java? [message #1760632 is a reply to message #1760623] Sat, 29 April 2017 08:17 Go to previous messageGo to next message
Dimitris Kolovos is currently offline Dimitris KolovosFriend
Messages: 1605
Registered: July 2009
Location: York, UK
Senior Member

Hi Sina,

This is correct. Bear in mind that the name of a constraint is not unique so in order to compute a precise dependency graph, in the general case you'd need to do full static analysis (including type inference etc.). To avoid going down that road at this stage you may want to limit your analysis to calls to satisfies() on the self built-in variable.

Cheers,
Dimitris
Re: How to get expression as string in Java? [message #1760637 is a reply to message #1760632] Sat, 29 April 2017 10:21 Go to previous message
Sina Madani is currently offline Sina MadaniFriend
Messages: 78
Registered: November 2015
Location: York, UK
Member
Hi Dimitris,

Thank you for the insight and advice. I didn't know constraint names may be duplicated, though for the time being this approach should suffice.

Thanks,
Sina
Previous Topic:Code refactoring
Next Topic:EVL: Problem on configuring a UML model
Goto Forum:
  


Current Time: Tue Nov 13 01:03:54 GMT 2018

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

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

Back to the top