Search in sources :

Example 1 with SerializationModelStreamer

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Factory(spoon.reflect.factory.Factory) DefaultCoreFactory(spoon.support.DefaultCoreFactory) SerializationModelStreamer(spoon.support.SerializationModelStreamer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 2 with SerializationModelStreamer

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);
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) SerializationModelStreamer(spoon.support.SerializationModelStreamer) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with SerializationModelStreamer

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;
}
Also used : ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionEvent(java.awt.event.ActionEvent) FileOutputStream(java.io.FileOutputStream) SerializationModelStreamer(spoon.support.SerializationModelStreamer) IOException(java.io.IOException) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Aggregations

SerializationModelStreamer (spoon.support.SerializationModelStreamer)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 JFileChooser (javax.swing.JFileChooser)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 Test (org.junit.Test)1 Factory (spoon.reflect.factory.Factory)1 DefaultCoreFactory (spoon.support.DefaultCoreFactory)1