32
Automatically detecting and describing high level actions within methods Presented by: Gayani Samaraweera

Automatically detecting and describing high level actions within methods

  • Upload
    thea

  • View
    25

  • Download
    0

Embed Size (px)

DESCRIPTION

Automatically detecting and describing high level actions within methods. Presented by: Gayani Samaraweera. The problem. - PowerPoint PPT Presentation

Citation preview

Page 1: Automatically detecting  and describing high level actions  within methods

Automatically detecting and describing high level actions within methods

Presented by:Gayani Samaraweera

Page 2: Automatically detecting  and describing high level actions  within methods

The problem Given signature and the body of a method M,

automatically discover each code fragment that implements a high level action comprising the overall algorithm of M, and accurately express each high level action as a succinct natural language description

Page 3: Automatically detecting  and describing high level actions  within methods
Page 4: Automatically detecting  and describing high level actions  within methods

OutlineThe problemOutlineHigh level actionsMethodEvaluationConcernsOther usesConclusion

Page 5: Automatically detecting  and describing high level actions  within methods

High level actionsSequence fragment

A sequence of statements that when taken together represents a single high level action

Conditional fragment A conditional block that performs an

action with subtle variations based on the condition

Loop fragment Code patterns that are commonly

implemented using loop constructs that constitute a high level action

Page 6: Automatically detecting  and describing high level actions  within methods

Method

Page 7: Automatically detecting  and describing high level actions  within methods

Detecting high level actions Uses

AST (Abstract Syntax Tree) CFG (Control Flow Gragh) Information from naming

conventions and linguistic knowledge gained from observations of Java programs Textual clues from SWUM (Software

Word Usage Model)

Page 8: Automatically detecting  and describing high level actions  within methods

cont.. Word usage information from identifiers

Identifier splitting Camel case splitting: on capital letters, underscores,

numbers Eg: childXMLElement → child XML Element

Expand identifier abbreviations Eg: Button butSelectAll, MouseEvent evt

SWUM → action, theme, optional secondary arguments of a statement grouping Eg: list.add(Item i); → “add item to list”

themeaction secondary argument

Page 9: Automatically detecting  and describing high level actions  within methods

Sequence as single actionSequence fragmentsIdentifying sequences of

statements with similar actions◦Indicated by similar method calls

Page 10: Automatically detecting  and describing high level actions  within methods

cont.. Challenges

Integrate to successor statement based on similarity Different method names

Same method name different parameter types

Page 11: Automatically detecting  and describing high level actions  within methods

cont.. Identifying fragments

Statements with one or more method calls

Add ended panel to content panel

Add bid panel to content panel

Verb → add → equalsHead word of NP → panel → equalsPreposition → to content panel → equals

→ integratable

Page 12: Automatically detecting  and describing high level actions  within methods

cont.. Synthesizing descriptions

If equal head word → plural Else

Add okButton to content panel

Head word of NP → differentBut if fields of same class → “all attributes” “different attributes”

Page 13: Automatically detecting  and describing high level actions  within methods

Abstracting conditionals Challenges

Integrating similar statements in different branches

Integrating conditional statements guarding different branches

Integrating return statements with literals or similar method calls

Page 14: Automatically detecting  and describing high level actions  within methods

cont.. Identifying and describing

conditionals Integrate statements of each block,

compare each statement with statements of parent block For method calls

Singular

Page 15: Automatically detecting  and describing high level actions  within methods

cont.. For return statements

For assignment statements

Theme based on enclosing method

Update, create or get

Page 16: Automatically detecting  and describing high level actions  within methods

cont.. Describing conditional

expressions Compare phrases as 'subject

predicate object' Subject and predicate are equal →

based on what <subject> <predicate>Based on what os name starts with

If only head word of subject is equalBased on which <head word> <predicate> <object>

Based on which radio button is selected

Page 17: Automatically detecting  and describing high level actions  within methods

Finding traceable patterns in loops

Challenges Common algorithms as finding,

counting, copying Develop identification templates Develop heuristics to synthesize

phrases for each template

Page 18: Automatically detecting  and describing high level actions  within methods

cont.. Loop abstractions implemented

Count Contains Find Copy Max-min

Page 19: Automatically detecting  and describing high level actions  within methods

cont.. Identifying fragments and synthesize

templates

Page 20: Automatically detecting  and describing high level actions  within methods

cont.. Variations in synthesis templates

'find item (in collection) whose/which/such that <criteria>'in subject predicate object, If item is subject → which If an attribute of item is subject →

whose Default → such that

Page 21: Automatically detecting  and describing high level actions  within methods

Evaluation Executed on 1.2 million methods

across 1000 Java programs

Page 22: Automatically detecting  and describing high level actions  within methods

cont.. How prevalent are the implemented high

level methods? Sequence (methods with >= 10 statements

12.5%) 11%

Conditional 40% of if-else 24% of switch

Loop 51% of loops classified as iterating over all items in a

collection 15% of iterator loops detected by implemented

patterns

Page 23: Automatically detecting  and describing high level actions  within methods

cont.. Potential reduction in reading

detail Reduction in identified high level

actions Sequence → one phrase

22% of original size Conditional → two phrases

29% of original size Loop → varying # phrases

25% of original size

Page 24: Automatically detecting  and describing high level actions  within methods

cont.. Precision of identification and

description 15 human evaluators, each

evaluating 15 code fragments (5-sequence, 5-conditional, 5-loop)

75 code fragments from 15 projects evaluated by 3 evaluators

From methods with <= 20 statements25-conditional, 25-sequence, 25-loop

Loops: 5 fragments from each 5 patterns

Page 25: Automatically detecting  and describing high level actions  within methods

cont.. Evaluators wrote an abstraction of the

method Answered following based on

1 – strongly disagree to 5 – strongly agree

identification

description

Page 26: Automatically detecting  and describing high level actions  within methods

cont..

Majority agreed or strongly agreed on both P1 and P2

Page 27: Automatically detecting  and describing high level actions  within methods

Concerns.. May not generalize to other Java

programs Results may vary on larger programs Results might not hold with novices Reduction in reading measurement

may not hold with some developers

Page 28: Automatically detecting  and describing high level actions  within methods

Improving client tools Extract method refactoring

Create application based on whatos starts with

Set different attributes of SVGApplicationModel

Page 29: Automatically detecting  and describing high level actions  within methods

cont.. Internal comment generation

Instead of Extract Method refactoring, can add comments inline

Add empty lines between related code fragments

Suggesting more informative method names

Improving automatically generated summary comments for a method

Page 30: Automatically detecting  and describing high level actions  within methods

Conclusions First technique for identifying

code fragments of statement sequences, conditionals and loops, that is abstracted to a high level action

Automatically synthesizing natural language description

Page 31: Automatically detecting  and describing high level actions  within methods

References1. Giriprasad Sridhara, Lori Pollock, and K. Vijay-Shanker.

Automatically detecting and describing high level actions within methods. In Proceeding of the 33rd international conference on Software engineering (ICSE '11). ACM, New York, NY, USA, 101-110.

2. G. Sridhara, E. Hill, D. Muppaneni, L. Pollock, and K. Vijay-Shanker. Towards Automatically Generating Summary Comments for Java Methods. Intl. Conf on Automated Softw. Engg. (ASE’10), 2010.

3. Giriprasad Sridhara, Lori Pollock, K. Vijay-Shanker, "Generating Parameter Comments and Integrating with Method Summaries," International Conference on Program Comprehension, pp. 71-80, 2011 IEEE 19th International Conference on Program Comprehension, 2011

4. E. Hill. Integrating Natural Language and Program Structure Information to Improve Software Search and Exploration. PhD Dissertation, University of Delaware, 2010.

Page 32: Automatically detecting  and describing high level actions  within methods

Thank you for listening!