Question

I have the next JInvocation:

JInvocation jInvoke = JExpr.invoke(anotherPageInstance, method);

where anotherPageInstance is JVar and method is JMethod.

I do some actions on this JInvocation, and then I want to add it to test.body().invoke where test is JMethod.

The main problem is that I can't, because test.body().invoke has no option to get JInvocation as argument.

I can do the next: test.body().invoke(anotherPageInstance, method), but this doesn't help me, because I want to save the JInvocation, and just when some conditions are taking place, add this Jinvocation to the body (and as I mentions before, meanwhile I do some action on this JInvocation).

Any help?

Was it helpful?

Solution

You can add an invocation the body (JBlock) by using the add() method:

test.body().add(jInvoke);

OTHER TIPS

Instead of instantiating JInvocation with JExpr.invoke(), use the JExpr factory methods:

public static JInvocation invoke(JExpression lhs,
                                 JMethod method)
public static JInvocation invoke(JExpression lhs,
                                 String method)

See JExpr.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top