use of spoon.support.SerializationModelStreamer in project spoon by INRIA.
the class SerializableTest method testSerializationModelStreamer.
@Test
public void testSerializationModelStreamer() throws Exception {
Factory factory = build("spoon.test.serializable", "Dummy").getFactory();
ByteArrayOutputStream outstr = new ByteArrayOutputStream();
new SerializationModelStreamer().save(factory, outstr);
Factory loadedFactory = new SerializationModelStreamer().load(new ByteArrayInputStream(outstr.toByteArray()));
assertFalse(factory.Type().getAll().isEmpty());
assertFalse(loadedFactory.Type().getAll().isEmpty());
assertEquals(factory.getModel().getRootPackage(), loadedFactory.getModel().getRootPackage());
}
use of spoon.support.SerializationModelStreamer in project spoon by INRIA.
the class SourcePositionTest method saveFactory.
private static void saveFactory(Factory factory, File file) throws IOException {
ByteArrayOutputStream outstr = new ByteArrayOutputStream();
new SerializationModelStreamer().save(factory, outstr);
OutputStream fileStream = new FileOutputStream(file);
outstr.writeTo(fileStream);
}
use of spoon.support.SerializationModelStreamer in project spoon by INRIA.
the class SpoonModelTree method getMenu.
private JPopupMenu getMenu() {
if (menu == null) {
menu = new JPopupMenu();
JMenuItem item = new JMenuItem("Save");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
boolean cont = chooser.showSaveDialog(SpoonModelTree.this) == JFileChooser.APPROVE_OPTION;
if (cont) {
SerializationModelStreamer ser = new SerializationModelStreamer();
try {
ser.save(factory, new FileOutputStream(chooser.getSelectedFile()));
} catch (IOException e1) {
Launcher.LOGGER.error(e1.getMessage(), e1);
}
}
}
});
menu.add(item);
menu.addSeparator();
// show reflect table
item = new JMenuItem("Reflect");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree.getLastSelectedPathComponent();
if (node == null) {
node = root;
}
new SpoonObjectFieldsTable(node.getUserObject());
}
});
menu.add(item);
menu.addSeparator();
// Search value
item = new JMenuItem("Search");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
search();
}
});
menu.add(item);
// Search value
item = new JMenuItem("Search next");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
next();
}
});
menu.add(item);
menu.addSeparator();
// Expand all
item = new JMenuItem("Expand all");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) jTree.getLastSelectedPathComponent();
if (node == null) {
node = root;
}
expandAll(node);
}
});
menu.add(item);
}
return menu;
}
Aggregations