From 46e12e295e17fa5fc661535fd9e807fa2f0c443a Mon Sep 17 00:00:00 2001 From: s_yevtushenko <> Date: Tue, 14 Nov 2006 11:21:00 +0000 Subject: [PATCH] Changed generation of lattice labels in dot export --- .../frontend/latticeeditor/DotExporter.java | 26 ++++++++++++++++--- .../latticeeditor/tests/DotExporterTest.java | 16 +++++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/conexp/frontend/latticeeditor/DotExporter.java b/src/conexp/frontend/latticeeditor/DotExporter.java index 80b2dfb..f0d8a29 100644 --- a/src/conexp/frontend/latticeeditor/DotExporter.java +++ b/src/conexp/frontend/latticeeditor/DotExporter.java @@ -1,5 +1,6 @@ package conexp.frontend.latticeeditor; +import conexp.core.ContextEntity; import conexp.core.Lattice; import conexp.core.LatticeElement; import util.FileNameMangler; @@ -9,6 +10,7 @@ import java.io.IOException; import java.io.PrintStream; import java.util.Hashtable; +import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Set; @@ -139,15 +141,31 @@ public static final String getArcList( // ------------------------------------------------------------------------ + public static final String asStringNodeDot(LatticeElement latticeElement) { StringBuffer string = new StringBuffer(); + writeContextEntities(latticeElement.ownAttribsIterator(), string); + string.append("\\n"); + writeContextEntities(latticeElement.ownObjectsIterator(), string); + return string.toString(); + } - string.append(latticeElement.getAttribs()); + private static void writeContextEntities(Iterator entityIterator, StringBuffer string) { + boolean first = true; + for (Iterator iterator = entityIterator; iterator.hasNext();) { + ContextEntity entity = (ContextEntity) iterator.next(); + if (first) { + first = false; + } else { + string.append(","); + } + string.append(escapeString(entity.getName())); - string.append("\\n"); + } + } - string.append(latticeElement.getObjects()); - return string.toString(); + public static String escapeString(String name) { + return name.replaceAll("\"", "\\\\\""); } } diff --git a/src/conexp/frontend/latticeeditor/tests/DotExporterTest.java b/src/conexp/frontend/latticeeditor/tests/DotExporterTest.java index d8c4532..03ba095 100644 --- a/src/conexp/frontend/latticeeditor/tests/DotExporterTest.java +++ b/src/conexp/frontend/latticeeditor/tests/DotExporterTest.java @@ -12,10 +12,10 @@ public class DotExporterTest extends TestCase { "\tratio=fill;\n" + "\tsize=\"7.5,10\";\n" + "\n" + - "\tnode_1 [label=\"{1, 0, 0}\\n{1, 1}\"];\n" + - "\tnode_2 [label=\"{1, 0, 1}\\n{1, 0}\"];\n" + - "\tnode_3 [label=\"{1, 1, 1}\\n{0, 0}\"];\n" + - "\tnode_4 [label=\"{1, 1, 0}\\n{0, 1}\"];\n" + + "\tnode_1 [label=\"Attr 1\\n\"];\n" + + "\tnode_2 [label=\"Attr 3\\nObj 1\"];\n" + + "\tnode_3 [label=\"\\n\"];\n" + + "\tnode_4 [label=\"Attr 2\\nObj 2\"];\n" + "\n" + "\t{\n" + "\tnode_2;\n" + @@ -33,8 +33,8 @@ public class DotExporterTest extends TestCase { "\tratio=fill;\n" + "\tsize=\"7.5,10\";\n" + "\n" + - "\tnode_1 [label=\"{1, 0, 0}\\n{1, 1}\"];\n" + - "\tnode_2 [label=\"{1, 1, 0}\\n{0, 1}\"];\n" + + "\tnode_1 [label=\"Attr 1\\nObj 1\"];\n" + + "\tnode_2 [label=\"Attr 2\\nObj 2\"];\n"+ "\n" + "\t{\n" + "\tnode_2;\n" + @@ -66,4 +66,8 @@ private static Context makeTestContext() { } + public void testEscapeString() throws Exception { + assertEquals("abc", DotExporter.escapeString("abc")); + assertEquals("a\\\"b", DotExporter.escapeString("a\"b")); + } } \ No newline at end of file