|
1 | | -# SequenceExtractor |
2 | | -Statement Sequence Extractor for Java Source Code Snippets |
| 1 | +SequenceExtractor: Statement Sequence Extractor for Java Source Code Snippets |
| 2 | +============================================================================= |
| 3 | +SequenceExtractor is a statement sequence extractor for Java source code snippets. |
| 4 | +The tool allows exporting the sequence of statements of snippets in a list format. |
| 5 | +It can be used as a library either from Java or from Python using the Python binding. |
| 6 | + |
| 7 | +Using as a library |
| 8 | +------------------ |
| 9 | +Import the library in your code. Then, you can parse snippets as follows: |
| 10 | +<pre><code>ArrayList<String> sequence = SequenceExtractor.extractSequence("" |
| 11 | + + "JFrame frame = new JFrame(\"myframe\");\n" |
| 12 | + + "JPanel panel = new JPanel()\n;" |
| 13 | + + "Container pane = frame.getContentPane();\n" |
| 14 | + + "GridLayout layout = new GridLayout(2,2);\n" |
| 15 | + + "panel.setLayout(layout);\n" |
| 16 | + + "panel.add(upperLeft);\n" |
| 17 | + + "panel.add(upperRight);\n" |
| 18 | + + "panel.add(lowerLeft);\n" |
| 19 | + + "panel.add(lowerRight);\n" |
| 20 | + + "pane.add(panel);\n" |
| 21 | + );</code></pre> |
| 22 | +The result is a list with the sequence of calls for the snippet. For the above example the result is: |
| 23 | +<pre><code>[CI_JFrame, CI_JPanel, FC_Container, CI_GridLayout, FC_void, FC_void, FC_void, FC_void, FC_void, FC_void]</code></pre> |
| 24 | + |
| 25 | +There are three types of commands: |
| 26 | +- object instantiations (<code>CI</code>) |
| 27 | +- assignments (<code>AM</code>) |
| 28 | +- function calls (<code>FC</code>) |
| 29 | + |
| 30 | +There are also certain options when extracting the snippets provided asparameters of the <code>extractSequence</code> function. These are: |
| 31 | +- keepFunctionCallTypes: denotes whether to output also the objects performing the function calls (instead of only the return types), default is false. |
| 32 | +- keepLiterals denotes if commands with literals (primitive types) should be extracted, or discarded, default is false. |
| 33 | + |
| 34 | +Using in Python |
| 35 | +--------------- |
| 36 | +SequenceExtractor also has python bindings. Using the python wrapper is simple. At first, the library |
| 37 | +has to be imported and the SequenceExtractor object has to be initialized given the path to the jar |
| 38 | +of the library and the options to keep function call types (<code>keep_function_call_types</code>) |
| 39 | +and keep literals (<code>keep_literals</code>): |
| 40 | +<pre><code>sequence_extractor = SequenceExtractor("path/to/SequenceExtractor-0.1.jar", True, False)</code></pre> |
| 41 | +After that, you can parse snippets as follows: |
| 42 | +<pre><code>sequence = sequence_extractor.parse_snippet( |
| 43 | + "JFrame frame = new JFrame(\"myframe\");\n" + |
| 44 | + "JPanel panel = new JPanel();\n" + |
| 45 | + "Container pane = frame.getContentPane();\n" + |
| 46 | + "GridLayout layout = new GridLayout(2,2);\n" + |
| 47 | + "panel.setLayout(layout);\n" + |
| 48 | + "panel.add(upperLeft);\n" + |
| 49 | + "panel.add(upperRight);\n" + |
| 50 | + "panel.add(lowerLeft);\n" + |
| 51 | + "panel.add(lowerRight);\n" + |
| 52 | + "pane.add(panel)\n;" |
| 53 | + )</code></pre> |
| 54 | + |
| 55 | +Note that after using the library, you have to close the SequenceExtractor object using function <code>close</code>, i.e.:<pre><code>sequence_extractor.close()</code></pre> |
| 56 | + |
| 57 | + |
0 commit comments