an already existing code fragment within a new context Empirical SE research characterized EE as a software activity Ohad Barzilay, Orit Hazzan, Amiram Yehudai, “Characterizing Example Embedding as a Software Activity”, 2009 Motivation derived from Refactoring Using examples is not new
of fine grained techniques, which together assemble an abstract key notion in software development Analysis Programming Debugging Coding Refactoring Search Example Embedding Code Comprehension Testing Design Taken from “Example Embedding by Ohad Barzilay” slides
more than just a collection of examples It has to be part of the Example Embedding software activity In order for the repository to support the example embedding eco-system we must define the requirements for a repository
Rating ◦ Tags ◦ Author / Source of the Example ◦ Input / Output type / Signature ◦ Programming Language ◦ Security ◦ Example View History These properties will allow to: ◦ Filter the search results ◦ Use an advanced searching algorithm based on these properties and not only based on similarity of keywords
an example from the search results and embed it into his code automatically Allow the developer to choose where he wants embed the example Similar to how refactoring works Automatic Embedding will improve code quality by following Embedding Patterns
Allow to create and submit new examples directly from IDE Support conversion for existing examples ◦ SourceForge.net Conversion will contribute to the acceptance of the repository framework Automated tool
Otavio Lemos, Sushil Bajracharya, Joel Ossher, Ricardo Morla, Paulo Masiero, Pierre Baldi, Cristina Lopes, “Using Test-Cases to Search and Reuse Source Code“, 2007 Based on the Sourcerer search engine ◦ Search is based on Keywords, Structural properties and Relations among program elements Code Search Repository Access Slicing
cases can be used to define a software feature in TDD, they can also be used to describe a desired feature in a code search 1. Construct test cases 2. Search for code and integrate 3. Refactor
the results by weaving / testing and unweaving them To do that, a program slicing service to provide self-contained code pieces related to the desired feature, and a repository access service must be available at the code services side.
Extract information: ◦ Extract interface of the missing method and the names of the missing method and of the class it belongs to, by analyzing compiler errors present in the test cases ◦ The AST is explored to extract the return type and argument types Weaving: ◦ Merge by name strategy as used as used in Hyper/J ◦ The merging is done by a union operation on the structures of the classes ◦ Uses java annotations to track the woven structers Sourcerer
Integrate into IDE • Allows Searching but only by use cases • No option for filtering by any of the parameters Searching • Allows running the code from the IDE using slices Run-able in IDE • Allows weaving but it is not real code embedding Automatic Embedding • Doesn’t allow adding examples from the IDE New & Existing Examples • Only allows access to the code the sourcerer has access to – SourceForge.net Repository Framework • Only searchable by using test cases • Not intuitive Simple to Use
plug-in) Reid Holmes, Gail C. Murphy, “Using Structural Context to Recommend Source Code Examples”, 2005 Locating code in an example repository based on heuristically matching the structure of the code under development to the example code ◦ Structural Context extracted automatically ◦ The repository is extracted automatically from existing applications
Calls Heuristic Basic Calls – call the same targets Calls Best fit – best ration match/unmatched call targets Calls with inheritance – with at least one parent ◦ Uses Heuristic Basic Uses – use the same types Uses with inheritance – with at least one parent
code being edited ◦ The ability to return useful examples dependent upon the quality of the seed code used in the query Searches only the extracted code in the repository More limitations: ◦ Repository code must be parse-able by eclipse compiler ◦ Repository code should represent good usage of the framework
Integrate into IDE • Allows Searching but only by code being edited • No option for filtering by any of the parameters Searching • Returns the source code of the example Run-able in IDE • Only returns the source code of the example without embedding Automatic Embedding • Based on the source code extracted into the repository only New & Existing Examples • Supports mostly local repository • Requires improvements to support public rep. Repository Framework • Only searchable by using edited code seed • Not intuitive Simple to Use
browser Integrate into IDE • Allows keyword searching and supports most of the properties described earlier Searching • Doesn’t allow running the code from the IDE Run-able in IDE • The developer has to manually insert the code into his project Automatic Embedding • The repository only supports adding new examples • Manually fill a form in order to add new examples New & Existing Examples • Only allows access to the code on the repository itself Repository Framework • The interface is very simple and is intuitive since it is similar to other popular search engines Simple to Use
browser Integrate into IDE • Allows keyword searching, but the repository has only a small number of code examples Searching • Doesn’t allow running the code from the IDE Run-able in IDE • The developer has to manually insert the code into his project Automatic Embedding • The repository only supports adding new examples • Manually fill a form in order to add new examples New & Existing Examples • Only allows access to the code on the repository itself Repository Framework • The interface is very simple and is intuitive since it is similar to other popular search engines Simple to Use