use of com.rockwellcollins.atc.agree.agree.impl.DoubleDotRefImpl in project AMASE by loonwerks.
the class SafetyValidator method checkInput.
/**
* Checks fault def name is valid,
* expressions passed into node match parameter types,
* and correct number of arguments passed in.
*
* @param inputs
*/
@Check(CheckType.FAST)
public void checkInput(InputStatement inputs) {
EObject container = inputs.eContainer();
NamedElement defNameSub;
List<Expr> exprList = inputs.getNom_conn();
List<String> inputList = inputs.getFault_in();
ArrayList<String> argNames = new ArrayList<String>();
if (container instanceof FaultStatement) {
FaultStatement faultStatement = (FaultStatement) container;
DoubleDotRef defName = faultStatement.getFaultDefName();
defNameSub = defName.getElm();
// Make sure we have a NodeDefExpr
if (defNameSub instanceof NodeDef) {
List<Arg> nodeArgs = ((NodeDef) defNameSub).getArgs();
for (Arg arg : nodeArgs) {
argNames.add(arg.getFullName());
if (arg.getType() instanceof DoubleDotRefImpl) {
if ((((DoubleDotRefImpl) arg.getType()).getElm() instanceof PropertyImpl) || (((DoubleDotRefImpl) arg.getType()).getElm() instanceof DataTypeImpl)) {
error(inputs, "Fault node parameters are not recognized: a possible issue is that the keyword 'float' is used instead of 'real.'");
}
}
}
// If the sizes are accurate, make sure names match
if (nodeArgs.size() - 1 == (inputList.size())) {
// Go through input list and make sure each name is in the arg list
for (String inputName : inputList) {
if (!argNames.contains(inputName)) {
error(inputs, "Input names must match fault node definition names. " + "The input name " + inputName + " is not an input in the node definition. " + "All possible input names are: " + argNames.toString());
}
}
} else {
argNames.remove("trigger");
error(inputs, "With this fault definition, you must have " + (argNames.size() - 1) + " inputs." + " These are called: " + argNames.toString());
}
if (inputListHasRepeats(inputList)) {
error(inputs, "There is a repeated name in the input list: " + inputList.toString());
}
if (!checkInputTypes(exprList, nodeArgs)) {
error(inputs, "Types of inputs do not match types of node parameters");
}
} else {
// Not a node def expr
error(defName, "Fault definition: " + defNameSub.getFullName() + " must be a valid agree node definition name.");
}
} else {
error(inputs, "Fault inputs must be defined within a fault statement.");
}
}
Aggregations