/** * This function obtains a list with the subexpressions of a given expressions * * @param expr The original expresion * @return the list with all the subexpressions */ public static List<Expr> getListExpr(Expr expr) throws IllegalArgumentException { List<Expr> list = new ArrayList<Expr>(); if (expr instanceof NumExpr) { list.add(expr); } else if (expr instanceof RefExpr) { RefExpr refExpr = (RefExpr) expr; String strRefExpr = refExpr.getZName().getWord(); // The \emptyset expression will be ignored if (!strRefExpr.equals(UtilSymbols.emptySetSymbol())) list.add(expr); } else if (expr instanceof SetExpr) { list = ((SetExpr) expr).getZExprList(); } else if (expr instanceof TupleExpr) { list = ((TupleExpr) expr).getZExprList(); } else if (expr instanceof ApplExpr) { if (((ApplExpr) expr).getMixfix()) { // es una secuencia ZExprListImpl applList = (ZExprListImpl) ((SetExpr) (((ApplExpr) expr).getRightExpr())).getZExprList(); for (int i = 0; i < applList.size(); i++) { Expr elem = (((TupleExpr) (applList.get(i))).getZExprList()).get(1); list.add(elem); } } else { // es un valor negativo list.add(expr); } } else { throw new IllegalArgumentException(); } return list; }
/** * This function obtains from a list of Equality's objects the Equality object which is related * with an identifier of the specification. The Equality's objects are used for refine one * variable in the specification to more than one variable in the specification. * * @param implID The identifier of a variable in the implementation * @param equalities A list of Equality's objects * @return the related equality */ public static Equality getAssociatedEquality(String implID, List<Equality> equalities) { for (int i = 0; i < equalities.size(); i++) { Equality equality = equalities.get(i); String plCode = equality.getPLCodeEquality(); plCode = plCode.trim(); plCode = plCode.substring(0, plCode.length() - 1); if (plCode.equals(implID)) return equality; } return null; }
public static String printCTCC(String testName, ConcreteTCase ctc) { String ctcString = ""; ctcString = ctcString.concat(ctc.getPreamble() + "\n"); ctcString += "main(){\n"; if (ctc.getInitDeclarations() != null) ctcString += ctc.getInitDeclarations(); List<TCaseAssignment> assigs = ctc.getAssigments(); Iterator<TCaseAssignment> iter = assigs.iterator(); while (iter.hasNext()) ctcString = ctcString.concat((iter.next()).getRefText() + "\n"); ctcString = ctcString.concat(ctc.getEpilogue() + "\n"); ctcString += "}\n"; return ctcString; }
public static void printRuleRefinement(RuleRefinement rule) { if (rule == null) { System.out.println("Rule NULL!!!"); } System.out.println(); System.out.println("Refinamiento"); System.out.println("Los nombres de los identificadores son:"); List<String> idsList = rule.getSpecIDs(); for (int i = 0; i < idsList.size(); i++) { System.out.println("id: " + idsList.get(i)); } // System.out.println("Nombre en Especificaión: " + rule.getSpecName()); CHANGE // System.out.println("Nombre en Implementación: " + rule.getRefName()); CHANGE // HACER ANALOGO AL ANTERIOR // System.out.print("Tipo: "); // printType(rule.getNodeType()); CHANGE // HACER ANALOGO ANTERIOR }
/** * This function obtains the refinement rule associated with a specification ID * * @param specID The identifier of a variable in the specification * @param rules A list with refinement rules * @return the rule associated with the variable */ public static RuleRefinement getRefinementRule(String specID, NodeRules rules) { RuleRefinement ruleRefinement = null; Set<String> setRuleNames = rules.getKeys(); Iterator<String> iterRuleNames = setRuleNames.iterator(); boolean found = false; while (iterRuleNames.hasNext() && !found) { String ruleName = iterRuleNames.next(); NodeRule rule = rules.getRule(ruleName); List<String> ruleSpecIDs = ((RuleRefinement) rule).getSpecIDs(); Iterator<String> iterRuleSpecIDs = ruleSpecIDs.iterator(); while (iterRuleSpecIDs.hasNext() && !found) { String ruleSpecID = iterRuleSpecIDs.next(); if (specID.equals(ruleSpecID)) { found = true; if (rule instanceof RuleRefinement) ruleRefinement = (RuleRefinement) rule; } } } return ruleRefinement; }
public static String printCTCJava(String testName, ConcreteTCase ctc) { String ctcString = ""; // EMPTY STRING // -------------------------------------------------------------------------------- // CONCATENATES the TESTNAME // -------------------------------------------------------------------------------- ctcString = ctcString.concat( "//--------------------------------------------------------------------------------" + "\n"); ctcString = ctcString.concat("// " + testName + "\n"); ctcString = ctcString.concat( "//--------------------------------------------------------------------------------" + "\n"); ctcString = ctcString.concat("\n"); // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- String preamble = ctc.getPreamble(); String preambleWithOutPackageAndImports = ""; BufferedReader preambleReader = new BufferedReader(new StringReader(preamble)); CharSequence packageChar = new StringBuffer("package"); CharSequence importChar = new StringBuffer("import"); String preambleLine; try { while ((preambleLine = preambleReader.readLine()) != null) { if (preambleLine.contains(packageChar) || preambleLine.contains(importChar)) { ctcString = ctcString.concat(preambleLine); ctcString = ctcString.concat("\n"); } else { preambleWithOutPackageAndImports = preambleWithOutPackageAndImports.concat(preambleLine) + "\n"; } } } catch (IOException e) { e.printStackTrace(); } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // PRINT the TEST CLASS HEADER // -------------------------------------------------------------------------------- ctcString = ctcString.concat("\n"); ctcString = ctcString.concat("public class "); ctcString = ctcString.concat(testName); // SCHEMA NAME ctcString = ctcString.concat("\n"); ctcString = ctcString.concat("{"); ctcString = ctcString.concat("\n"); // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // CONCATENATES the PREAMBLE WITHOUT PACKAGE and IMPORTS // -------------------------------------------------------------------------------- ctcString = ctcString.concat(preambleWithOutPackageAndImports); // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // PRINT the RUNTEST CLASS HEADER // -------------------------------------------------------------------------------- ctcString = ctcString.concat("\n"); ctcString = ctcString.concat("\t"); ctcString = ctcString.concat("public static void main(String[] args)"); // ctcString = ctcString.concat("public static void runTest_"); // ctcString = ctcString.concat(testName); // SCHEMA NAME // ctcString = ctcString.concat("_TCASE()"); ctcString = ctcString.concat("\n"); ctcString = ctcString.concat("\t"); ctcString = ctcString.concat("{"); ctcString = ctcString.concat("\n"); ctcString = ctcString.concat("try{\n"); // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // CONCATENATES the REFINEMENT TEXT of ALL ASSIGNMENTS // -------------------------------------------------------------------------------- List<TCaseAssignment> assignments = ctc.getAssigments(); Iterator<TCaseAssignment> iterAssignments = assignments.iterator(); TCaseAssignment assignment; String assignmentRefText; while (iterAssignments.hasNext()) { assignment = iterAssignments.next(); assignmentRefText = assignment.getRefText(); // CONCATS the REFIMENT TEXT of ASSIGNMENT ctcString = ctcString.concat( "\t\t" // INDENTATION + assignmentRefText + "\n" + "\n"); } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // CONCATS the EPILOGUE // -------------------------------------------------------------------------------- ctcString = ctcString.concat( "\t\t" + "//--------------------------------------------------------------------------------" + "\n"); ctcString = ctcString.concat("\t\t" + "// EPILOGUE" + "\n"); ctcString = ctcString.concat( "\t\t" + "//--------------------------------------------------------------------------------" + "\n"); String epilogue = ctc.getEpilogue(); BufferedReader epilogueReader = new BufferedReader(new StringReader(epilogue)); String epilogueLine; try { while ((epilogueLine = epilogueReader.readLine()) != null) { ctcString = ctcString.concat( "\t\t" // INDENTATION + epilogueLine + "\n"); } } catch (IOException e) { e.printStackTrace(); } // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // CLOSE the CATCH BLOCK. // -------------------------------------------------------------------------------- ctcString = ctcString.concat("}\n"); ctcString = ctcString.concat("catch(Exception e){\n"); ctcString = ctcString.concat("\te.printStackTrace(System.out);\n}"); // -------------------------------------------------------------------------------- // CLOSE the RUNTEST CLASS. // -------------------------------------------------------------------------------- ctcString = ctcString.concat("\t"); ctcString = ctcString.concat("}"); ctcString = ctcString.concat("\n"); // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- // CLOSE the TEST CLASS. // -------------------------------------------------------------------------------- ctcString = ctcString.concat("}"); // -------------------------------------------------------------------------------- return ctcString; }
public static void printType(NodeType type) { if (type instanceof NodeSynonym) { System.out.println("NodeSynonym: " + ((NodeSynonym) type).getID()); } // System.out.println("NodeSynonym: " + ((NodeSynonym)type).getType()); else if (type instanceof NodePLType) { System.out.println("PLType: " + ((NodePLType) type).getType()); } else if (type instanceof NodePointer) { System.out.println("Puntero a"); System.out.print(" "); printType(((NodePointer) type).getType()); } else if (type instanceof NodeArray) { System.out.print("Arreglo de tamaño " + ((NodeArray) type).getSize() + " de tipo: "); printType(((NodeArray) type).getType()); } else if (type instanceof NodeStructure) { NodeStructure structure = (NodeStructure) type; // List<NodeElement> elements = record.getElements(); CHANGE List<NodeElement> elements = structure.getElements(); Iterator<NodeElement> iter = elements.iterator(); // System.out.println("Estructura: " + "Nombre: " + record.getName()); CHANGE System.out.println("Estructura: " + "Nombre: " + structure.getName()); int i = 1; NodeElement element; while (iter.hasNext()) { element = iter.next(); System.out.println("Campo " + i + ": "); i++; // System.out.println("Nombre: " + (element.getName())); CHANGE System.out.println("Nombre: " + (element.getID())); System.out.print("Tipo: "); printType(element.getType()); } } else if (type instanceof NodeList) { NodeList list = (NodeList) type; // List<NodeField> fields = list.getFields(); CHANGE List<NodeElement> fields = list.getFields(); // Iterator<NodeField> iter = fields.iterator(); CHANGE Iterator<NodeElement> iter = fields.iterator(); System.out.println("Lista"); System.out.println("Nombre: " + list.getName()); System.out.println("LinkType: " + list.getLinkType()); System.out.println("LinkNexName: " + list.getLinkNextName()); if (list.getLinkPrevName() != null) { System.out.println("LinkPrevName: " + list.getLinkPrevName()); } int i = 1; NodeElement field; while (iter.hasNext()) { field = iter.next(); System.out.println("Campo " + i + ":"); i++; // System.out.println("Nombre: " + (field.getName())); CHANGE System.out.println("Nombre: " + (field.getID())); System.out.print("Tipo: "); printType(field.getType()); } // if (list.getMemalloc() != null ) CHANGE if (list.getMemAlloc() != null) { System.out.println("MemallocFunction: "); // System.out.println(list.getMemalloc()); CHANGE System.out.println(list.getMemAlloc()); } } else if (type instanceof NodeFile) { NodeFile file = (NodeFile) type; System.out.println("Archivo"); System.out.println("Nombre: " + file.getName()); System.out.println("Ruta: " + file.getPath()); System.out.println("Delimitador: " + file.getDelimiter()); if (file.getEof() != null) { System.out.println("EOF: " + file.getEof()); } if (file.getEol() != null) { System.out.println("EOL: " + file.getEol()); } if (file.getStructure() != null) { System.out.println("Estructura: " + file.getStructure()); } } else if (type instanceof NodeDB) { NodeDB db = (NodeDB) type; List<NodeDBColumn> regs = db.getColumns(); Iterator<NodeDBColumn> iter = regs.iterator(); System.out.println("Base de Datos"); System.out.println("DBMS: " + db.getDBMSID()); // System.out.println("connectionID " + db.getConnID()); CHANGE System.out.println("connectionID " + db.getConnectionID()); // System.out.println("Table name: " + db.getTable()); CHANGE System.out.println("Table name: " + db.getTableName()); System.out.println("Registros:"); int i = 1; while (iter.hasNext()) { NodeDBColumn rec = iter.next(); System.out.println( "Registro " + i + ": " + rec.getColType() + " tipo: " + rec.getColType()); i++; } } }