Skip to content

Commit

Permalink
Adds a constructor to easily build arguments (caller,map(string, value))
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed May 24, 2021
1 parent 5b0f1e1 commit 6ef7384
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions msi.gama.core/src/msi/gaml/statements/Arguments.java
Expand Up @@ -10,8 +10,11 @@
********************************************************************************************************/
package msi.gaml.statements;

import java.util.Map;

import msi.gama.metamodel.agent.IAgent;
import msi.gama.runtime.IScope;
import msi.gaml.descriptions.ConstantExpressionDescription;
import msi.gaml.expressions.IExpression;

/**
Expand All @@ -26,9 +29,16 @@ public class Arguments extends Facets {

public Arguments(final Arguments args) {
super(args);
if (args != null) {
setCaller(args.caller.get());
}
if (args != null) { setCaller(args.caller.get()); }
}

/*
* A constructor that takes a caller and arguments defined as a map <string, values>. Values are then transformed
* into a constant expression
*/
public Arguments(final IAgent caller, final Map<String, Object> args) {
setCaller(caller);
args.forEach((k, v) -> put(k, ConstantExpressionDescription.create(v)));
}

public Arguments() {}
Expand All @@ -48,9 +58,7 @@ public Arguments resolveAgainst(final IScope scope) {
result.setCaller(caller.get());
for (final Facet f : facets) {
final IExpression exp = getExpr(f.key);
if (exp != null) {
result.put(f.key, exp.resolveAgainst(scope));
}
if (exp != null) { result.put(f.key, exp.resolveAgainst(scope)); }
}
return result;
}
Expand Down

0 comments on commit 6ef7384

Please sign in to comment.