/** * Method validate() * * @see msi.gaml.compilation.IDescriptionValidator#validate(msi.gaml.descriptions.IDescription) */ @Override public void validate(final IDescription description) { // Verify that the state is inside a species with fsm control SpeciesDescription species = description.getSpeciesContext(); String keyword = description.getKeyword(); IArchitecture control = species.getControl(); // String control = species.getControlName(); if (!(control instanceof FsmArchitecture)) { if (keyword.equals(STATE)) { description.error( "A state can only be defined in an fsm-controlled or user-controlled species", IGamlIssue.WRONG_CONTEXT); return; } else if (control.getClass() == FsmArchitecture.class) { description.error( "A " + description.getKeyword() + " can only be defined in a user-controlled species (one of" + AllowedArchitectures + ")", IGamlIssue.WRONG_CONTEXT); return; } } if (!Assert.nameIsValid(description)) { return; } Facets ff = description.getFacets(); IExpression expr = ff.getExpr(INITIAL); if (IExpressionFactory.TRUE_EXPR.equals(expr)) { assertNoOther(description, INITIAL); } else { expr = ff.getExpr(FINAL); if (IExpressionFactory.TRUE_EXPR.equals(expr)) { assertNoOther(description, FINAL); } else { assertAtLeastOne(description, INITIAL); } } }
@Override public void setChildren(final List<? extends ISymbol> children) { // First we verify the control architecture final IArchitecture control = getArchitecture(); if (control == null) { throw GamaRuntimeException.error( "The control of species " + description.getName() + " cannot be computed"); } // Then we classify the children in their categories for (final ISymbol s : children) { if (s instanceof ISpecies) { final ISpecies oneMicroSpecies = (ISpecies) s; oneMicroSpecies.setMacroSpecies(this); microSpecies.put(oneMicroSpecies.getName(), oneMicroSpecies); } else if (s instanceof IVariable) { variables.put(s.getName(), (IVariable) s); } else if (s instanceof AspectStatement) { aspects.put(s.getName(), (AspectStatement) s); } else if (s instanceof ActionStatement) { if (!s.getDescription().isBuiltIn()) { String name = s.getName(); if (name.equals(initActionName)) { isInitOverriden = true; } else if (name.equals(stepActionName)) { isStepOverriden = true; } } actions.put(s.getName(), (ActionStatement) s); } else if (s instanceof UserCommandStatement) { userCommands.put(s.getName(), (UserCommandStatement) s); } else if (s instanceof IStatement) { behaviors.add((IStatement) s); // reflexes, states or tasks } } control.setChildren(behaviors); control.verifyBehaviors(this); }