Skip to content

Commit

Permalink
[Genstar] fix generate validator with genstar_pop_generator
Browse files Browse the repository at this point in the history
  • Loading branch information
chapuisk committed Sep 17, 2021
1 parent ed62257 commit d122115
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
Expand Up @@ -35,6 +35,7 @@
import msi.gama.util.GamaMapFactory;
import msi.gaml.statements.Arguments;
import msi.gaml.types.IType;
import msi.gaml.types.Types;
import msi.gaml.variables.IVariable;

public class OldGenstarGenerator implements IGenstarGenerator {
Expand All @@ -43,9 +44,14 @@ public class OldGenstarGenerator implements IGenstarGenerator {
private static final OldGenstarGenerator INSTANCE = new OldGenstarGenerator();
public static OldGenstarGenerator getInstance() {return INSTANCE;}

private OldGenstarGenerator() { this.type = null; }

@SuppressWarnings("rawtypes")
IType type;

@SuppressWarnings("rawtypes")
@Override
public IType sourceType() { return new GamaPopGeneratorType(); }
public IType sourceType() { return this.type; }

@Override
public boolean sourceMatch(IScope scope, Object source) { return source instanceof GamaPopGenerator; }
Expand Down Expand Up @@ -136,7 +142,7 @@ public void generate(IScope scope, List<Map<String, Object>> inits, Integer max,
for (final ADemoEntity e : population) {
@SuppressWarnings("rawtypes")
final Map map = GamaMapFactory.create();
for (final Attribute<? extends IValue> attribute : gen.getInputAttributes().getAttributes()) {
for (final Attribute<? extends IValue> attribute : population.getPopulationAttributes()) {
IVariable var = gamaPop.getVar(attribute.getAttributeName());
map.put(attribute.getAttributeName(),
GenStarGamaUtils.toGAMAValue(scope, e.getValueForAttribute(attribute), true, var.getType()));
Expand Down
Expand Up @@ -317,19 +317,22 @@ public void validate(StatementDescription description) {
final IExpression exp = description.getFacetExpr(FROM);
if (exp != null) {
final IType type = exp.getGamlType();
boolean found = false;
List<IType> types = StreamEx.of(GenStarGamaUtils.getGamaGenerator())
.map(IGenstarGenerator::sourceType).collect(Collectors.toList());
for (final IType genType : types) {
found = genType.isAssignableFrom(type);
if (found) { break; }
}
if (type==Types.MATRIX) {
// TODO verify that x,y matrix match possible attributes values
}
if (!found) {
description.warning("Facet 'from' expects an expression with one of the following types: " + types,
WRONG_TYPE, FROM);

if (type.id()!=938373948) {
boolean found = false;
List<IType> types = StreamEx.of(GenStarGamaUtils.getGamaGenerator())
.map(IGenstarGenerator::sourceType).collect(Collectors.toList());
for (final IType genType : types) {
found = genType.isAssignableFrom(type);
if (found) { break; }
}
if (type==Types.MATRIX) {
// TODO verify that x,y matrix match possible attributes values
}
if (!found) {
description.warning("Facet 'from' expects an expression with one of the following types: " + types,
WRONG_TYPE, FROM);
}
}
}

Expand Down

0 comments on commit d122115

Please sign in to comment.