Skip to content

Commit

Permalink
[lang] Add the missed "return" keyword when generating default-value-…
Browse files Browse the repository at this point in the history
…parameter function.

see #276

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Jan 8, 2015
1 parent 1786ea4 commit 94c29a4
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 2 deletions.
Expand Up @@ -116,9 +116,9 @@ class SARLJvmModelInferrer extends AbstractModelInferrer {

@Inject private CommonTypeComputationServices services

@Inject private JvmTypeExtensions typeExtensions;
@Inject private JvmTypeExtensions typeExtensions

@Inject private SARLExtendedEarlyExitComputer earlyExitComputer;
@Inject private SARLExtendedEarlyExitComputer earlyExitComputer

/**
* The dispatch method {@code infer} is called for each instance of the
Expand Down Expand Up @@ -912,6 +912,9 @@ class SARLJvmModelInferrer extends AbstractModelInferrer {
)
if (!isAbstract) {
body = [
if (returnValueType.identifier != "void") {
append("return ")
}
append(name)
append("(")
append(args.join(", "))
Expand Down
Expand Up @@ -428,6 +428,65 @@ class ArgDefaultValueCompilerTest extends AbstractSarlTest {
''')
}

@Test
def void inAgentAction_1p_returnValue() {
'''
agent A1 {
def myaction(arg : int=4) : boolean {
System.out.println(arg)
return true
}
}
'''.assertCompilesTo('''
import io.sarl.lang.annotation.DefaultValue;
import io.sarl.lang.annotation.DefaultValueSource;
import io.sarl.lang.annotation.DefaultValueUse;
import io.sarl.lang.annotation.Generated;
import io.sarl.lang.core.Agent;
import java.util.UUID;
@SuppressWarnings("all")
public class A1 extends Agent {
/**
* Default value for the parameter arg
*/
@Generated("4")
private final static int ___FORMAL_PARAMETER_DEFAULT_VALUE_0_0 = 4;
@DefaultValueSource
public boolean myaction(@DefaultValue("0_0") final int arg) {
System.out.println(arg);
return true;
}
@DefaultValueUse("int")
@Generated
public final boolean myaction() {
return myaction(___FORMAL_PARAMETER_DEFAULT_VALUE_0_0);
}
/**
* Construct an agent.
* @param parentID - identifier of the parent. It is the identifier of the parent agent and the enclosing contect, at the same time.
*/
@Generated
public A1(final UUID parentID) {
super(parentID, null);
}
/**
* Construct an agent.
* @param parentID - identifier of the parent. It is the identifier of the parent agent and the enclosing contect, at the same time.
* @param agentID - identifier of the agent. If <code>null</code> the agent identifier will be computed randomly.
*/
@Generated
public A1(final UUID parentID, final UUID agentID) {
super(parentID, agentID);
}
}
''')
}

@Test
def void inAgentAction_5p_0() {
'''
Expand Down Expand Up @@ -780,6 +839,65 @@ class ArgDefaultValueCompilerTest extends AbstractSarlTest {
''')
}

@Test
def void inAgentAction_5p_returnValue() {
'''
agent A1 {
def myaction(arg0 : int=4, arg1 : String, arg2 : int, arg3 : int, arg4 : String) : boolean {
System.out.println(arg0)
return true
}
}
'''.assertCompilesTo('''
import io.sarl.lang.annotation.DefaultValue;
import io.sarl.lang.annotation.DefaultValueSource;
import io.sarl.lang.annotation.DefaultValueUse;
import io.sarl.lang.annotation.Generated;
import io.sarl.lang.core.Agent;
import java.util.UUID;
@SuppressWarnings("all")
public class A1 extends Agent {
/**
* Default value for the parameter arg0
*/
@Generated("4")
private final static int ___FORMAL_PARAMETER_DEFAULT_VALUE_0_0 = 4;
@DefaultValueSource
public boolean myaction(@DefaultValue("0_0") final int arg0, final String arg1, final int arg2, final int arg3, final String arg4) {
System.out.println(arg0);
return true;
}
@DefaultValueUse("int,java.lang.String,int,int,java.lang.String")
@Generated
public final boolean myaction(final String arg1, final int arg2, final int arg3, final String arg4) {
return myaction(___FORMAL_PARAMETER_DEFAULT_VALUE_0_0, arg1, arg2, arg3, arg4);
}
/**
* Construct an agent.
* @param parentID - identifier of the parent. It is the identifier of the parent agent and the enclosing contect, at the same time.
*/
@Generated
public A1(final UUID parentID) {
super(parentID, null);
}
/**
* Construct an agent.
* @param parentID - identifier of the parent. It is the identifier of the parent agent and the enclosing contect, at the same time.
* @param agentID - identifier of the agent. If <code>null</code> the agent identifier will be computed randomly.
*/
@Generated
public A1(final UUID parentID, final UUID agentID) {
super(parentID, agentID);
}
}
''')
}

@Test
def void inAgentAction_3p_vararg_1() {
'''
Expand Down Expand Up @@ -959,6 +1077,65 @@ class ArgDefaultValueCompilerTest extends AbstractSarlTest {
''')
}

@Test
def void inAgentAction_3p_vararg_returnValue() {
'''
agent A1 {
def myaction(arg0 : int, arg1 : int=45, arg2 : int*) : boolean {
System.out.println(arg0)
return true
}
}
'''.assertCompilesTo('''
import io.sarl.lang.annotation.DefaultValue;
import io.sarl.lang.annotation.DefaultValueSource;
import io.sarl.lang.annotation.DefaultValueUse;
import io.sarl.lang.annotation.Generated;
import io.sarl.lang.core.Agent;
import java.util.UUID;
@SuppressWarnings("all")
public class A1 extends Agent {
/**
* Default value for the parameter arg1
*/
@Generated("45")
private final static int ___FORMAL_PARAMETER_DEFAULT_VALUE_0_1 = 45;
@DefaultValueSource
public boolean myaction(final int arg0, @DefaultValue("0_1") final int arg1, final int... arg2) {
System.out.println(arg0);
return true;
}
@DefaultValueUse("int,int,int*")
@Generated
public final boolean myaction(final int arg0, final int... arg2) {
return myaction(arg0, ___FORMAL_PARAMETER_DEFAULT_VALUE_0_1, arg2);
}
/**
* Construct an agent.
* @param parentID - identifier of the parent. It is the identifier of the parent agent and the enclosing contect, at the same time.
*/
@Generated
public A1(final UUID parentID) {
super(parentID, null);
}
/**
* Construct an agent.
* @param parentID - identifier of the parent. It is the identifier of the parent agent and the enclosing contect, at the same time.
* @param agentID - identifier of the agent. If <code>null</code> the agent identifier will be computed randomly.
*/
@Generated
public A1(final UUID parentID, final UUID agentID) {
super(parentID, agentID);
}
}
''')
}

@Test
def void inAgentAction_4p_0_1_2_3() {
'''
Expand Down
Expand Up @@ -87,6 +87,20 @@ class ArgDefaultValueParsingTest extends AbstractSarlTest {
"mismatched input '*=' expecting ')'")
}

@Test
def void inAgentAction_1p_returnValue() {
val mas = '''
agent A1 {
def myaction(arg : int=4) : boolean {
System.out.println(arg)
return true
}
}
'''.parse
mas.assertNoErrors
assertEquals(1, mas.elements.size)
}

@Test
def void inAgentAction_5p_0() {
val mas = '''
Expand Down

0 comments on commit 94c29a4

Please sign in to comment.