/** @see ast.ATKScriptParserVisitor#visit(ast.ASTLOOP, java.lang.Object) */ public Object visit(ASTLOOP node, Object data) { Integer nbLoop = null; // int nbNodes = node.jjtGetNumChildren(); // On obtient le nombre de loop (=n) // puis on repetera n fois children.Accept node.jjtGetChild(0).jjtAccept(this, data); nbLoop = stack.popInteger(); if (nbLoop < 0) { getMainLogger() .addErrorToDocumentLogger( LOOP_VALUE_IS_NEGATIVE, node.getLineNumber(), getInternalState().getCurrentScript()); } // Logger.getLogger(this.getClass() ).debug("Loop n = " + nbLoop); int previousLoopValue = internalState.getLoopValue(); // number of loop specified for the loop for (int i = 0; i < nbLoop; i++) { // childs are visited, excepted the first one (the number of // loop) // Logger.getLogger(this.getClass() ).debug("NbLoop = " + i); internalState.setLoopValue(i); for (int j = 1; j < node.jjtGetNumChildren(); j++) { Object res = node.jjtGetChild(j).jjtAccept(this, data); if (res != null) { if (!((Boolean) res).booleanValue()) { return Boolean.FALSE; } } } } internalState.setLoopValue(previousLoopValue); return Boolean.TRUE; }
/** * Constructor * * @param p phone tested * @param l logger used to store information * @param currentScript current script tested * @param logDir folder where result files are stored * @param includeDir folder where include file are stored */ public JATKInterpreter( PhoneInterface p, ResultLogger l, String currentScript, String logDir, String includeDir) { internalState.setCurrentScript(currentScript); internalState.setLogDir(logDir + Platform.FILE_SEPARATOR); phoneInterface = p; mainLogger = l; mainLogger.setInterpreter(this); actions = new ActionToExecute(this); }
/** @see ast.ATKScriptParserVisitor#visit(ast.ASTVARIABLE, java.lang.Object) */ public Object visit(ASTVARIABLE node, Object data) { // check if the referenced value has been previously defined if (!getVariables().isVariable(node.getValue().trim())) { getMainLogger() .addErrorToDocumentLogger( node.getValue() + IS_NOT_A_VARIABLE, node.getLineNumber(), internalState.getCurrentScript()); return Boolean.FALSE; } // if yes, get the value and return it Variable var = getVariables().getVariable(node.getValue().trim()); if (var.isInteger()) { stack.pushInteger(var.getInteger()); } else if (var.isString()) { stack.pushString(var.getString()); } /* * else { mainLogger.addErrorToLog("Unknown type... ", * node.getLineNumber(), internalState.getCurrentScript()); return * Boolean.FALSE; } */ return Boolean.TRUE; }
private Object runAction(SimpleNode node, Object data) { // visit children node.childrenAccept(this, data); // analyze the name part String functionName = node.getValue(); if ((phoneInterface.getCnxStatus() != PhoneInterface.CNX_STATUS_AVAILABLE) || (mainLogger.isStopATK())) { Logger.getLogger(this.getClass()).debug("[" + this.getClass().getName() + "] Close JATK "); mainLogger.interrupt(); return Boolean.FALSE; } // get variables Variable[] tablevariables = new Variable[stack.size()]; tablevariables = stack.toArray(tablevariables); // empty stack while (!stack.empty()) stack.pop(); // SEARCH function in action class and invoke it. Method[] functions = actions.getClass().getMethods(); for (Method function : functions) if (function.getName().toLowerCase().equals("action" + functionName.toLowerCase())) { try { return function.invoke(actions, node, tablevariables); } catch (Exception e) { Logger.getLogger(this.getClass()) .debug("erreur during execution of " + function.getName()); e.printStackTrace(); } } // we don't have found the function getMainLogger() .addErrorToDocumentLogger( functionName + " is not a valid function", node.getLineNumber(), internalState.getCurrentScript()); return Boolean.FALSE; /* * Could not happens anymore due to control in actions class } catch * (ClassCastException ex) { mainLogger.addErrorToLog("Invalid given * argument", node .getLineNumber(), internalState.getCurrentScript()); * ex.printStackTrace(); return Boolean.FALSE; } */ }