public void updatedNode(VarNode vn) { Object r = vn.getVariable(); if (!(r instanceof Local)) return; final Local receiver = (Local) r; final Context context = vn.context(); PointsToSetInternal p2set = vn.getP2Set().getNewSet(); if (ofcgb.wantTypes(receiver)) { p2set.forall( new P2SetVisitor() { public final void visit(Node n) { ofcgb.addType(receiver, context, n.getType(), (AllocNode) n); } }); } if (ofcgb.wantStringConstants(receiver)) { p2set.forall( new P2SetVisitor() { public final void visit(Node n) { if (n instanceof StringConstantNode) { String constant = ((StringConstantNode) n).getString(); ofcgb.addStringConstant(receiver, context, constant); } else { ofcgb.addStringConstant(receiver, context, null); } } }); } }
public static String generate(List<VarNode> nodes) { try { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); // root elements Document doc = docBuilder.newDocument(); doc.setXmlStandalone(true); Element rootElement = doc.createElement("vars"); doc.appendChild(rootElement); for (VarNode varNode : nodes) { // staff elements Element nodeElement = doc.createElement("var"); rootElement.appendChild(nodeElement); nodeElement.setAttribute("name", varNode.getName()); nodeElement.setAttribute("nodetype", varNode.getNodeType()); nodeElement.setAttribute("javatype", varNode.getJavaType()); nodeElement.setAttribute("value", varNode.getValue()); nodeElement.setAttribute("uuid", varNode.getUuid()); } // write the content into xml file TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(doc); StringWriter writer = new StringWriter(); transformer.transform(source, new StreamResult(writer)); String output = writer.getBuffer().toString().replaceAll("\n|\r", ""); return output; } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (TransformerException tfe) { tfe.printStackTrace(); } return ""; }