Title: Using Structural Context to Recommend Source Code Examples
1Using Structural Context to Recommend Source
Code Examples
- Reid Holmes and Gail C. Murphy
2The Problem A Concrete Example
- Frameworks can improve developer productivity.
But developers can become stuck trying to use the
APIs - Imagine trying to use the Eclipse APIs to place
text in the status line of the Eclipse IDE - Eclipse has 38,000 public methods
3The Problem A Concrete Example
Search the documentation status line eclipse
4The Problem A Concrete Example
- An expert might reveal
- How can we deliver this kind of example to a
developer?
5Previous Approaches
- Past approaches have tried to deliver examples
- Reuse View Matcher Rosson Carroll 91
- Provide constructed examples to developers
- Framework developer must explicitly create
examples - CodeFinder Henninger 91
- Help developers construct effective queries
- Developer needs to construct query manually
- CodeBroker Ye Fischer 01,02
- Locate similar code using comments and method
signatures - Intent is to locate similar code, not usage
6Our Approach An Overview
Development Environment
7Strathcona User Perspective
Write Code Fragment
Extract Structural Context
Browse Examples
Integrate Relevant Code
User Actions
Strathcona Actions
8Strathcona Extract Structural Context
ViewPart
9Strathcona Example Navigation
- Visual representation
- Highlights key relationships between example and
query - Multiple examples can be quickly viewed
10Strathcona Viewing Example Source
- Code view
- Example shows how to get a status line manager
- Example is not a perfect match, but good enough
to help
11Strathcona Server Side
- Repository consists of existing projects
- Structural context is automatically extracted
- Examples are not pre-computed
- Relevant source is located by heuristics
- Example is built from relevant code
- Eclipse example repository consists of source for
release 3.0 - 17,456 classes
- 124,359 methods
- 1,066,838 calls
- 15,187 inheritance links
Write Code Fragment
Existing Projects
Project Repository
Strathcona Server
Browse Examples
Integrate Relevant Code
12Strathcona Heuristics
- Six heuristics locate structurally relevant
examples - Inheritance
- Calls
- Calls with inheritance
- Uses
- Uses with inheritance
- Calls best fit
- Inspired by how a developer might manually search
- Each heuristic generates a set of examples
- Results from each are combined
- Top ten examples are returned
-
13Heuristics Example
Structural Context
14Calls Heuristic
- Locate examples that make similar method calls
Matched Example
Structural Context
15Calls With Inheritance Heuristic
- Locate examples that make similar method calls
and have similar parents
Matched Example
Structural Context
16Calls Best Fit Heuristic
Locate examples that dont make too many
extraneous method calls
Potential Example
Structural Context
17Evaluation
- We claim that our approach requires less effort
for developers to use - Example Repository
- Automatically populated
- Forming queries
- Automatically created from context of editor
- Query performance
- Queries take from 3 to 10 seconds
- Question addressed
- Can developers recognize and use examples?
18Case Study
- Evaluating the effectiveness of delivered
examples - Two subjects, both new to the Eclipse framework
- Each given the same four development tasks
- All tasks encountered during Strathcona
development - Each were provided with code fragment identified
from the documentation - Subjects were asked to use Strathcona to help
them complete the tasks within 3 hours
19Case Study
- Subject one completed all 4 tasks
- Subject two completed 3 of the 4 tasks
- Solutions were of high quality
- Included error cases they hadnt originally
considered - Subjects recognized examples that were not useful
- Subjects created new query fragments unexpected
by us
20Discussion
- Can developers create appropriate context to
query on? - Informal evaluation shows that they can create
fragments to form queries with - Are these really examples?
- Hand-crafted examples help developers understand
how and why to use an API - Our examples provide help in the usage of an API
21Conclusion
- Structural context can provide relevant examples
with less effort than previous approaches - Example repositories can be easily populated
- Automatically form query based on the code a
developer is writing - Developers can use examples to complete tasks
http//cs.ucalgary.ca/rtholmes/strathcona