| MARBLE Mining for Boilerplate Code to Identify API Usability - - PowerPoint PPT Presentation

marble
SMART_READER_LITE
LIVE PREVIEW

| MARBLE Mining for Boilerplate Code to Identify API Usability - - PowerPoint PPT Presentation

| MARBLE Mining for Boilerplate Code to Identify API Usability Problems Daye Nam Amber Horvath Andrew Macvean Brad Myers Bogdan Vesilescu Code to write an XML document to a speci fi ed output stream? 2 Code to write an XML document to a


slide-1
SLIDE 1

MARBLE

Daye Nam Amber Horvath Andrew Macvean Brad Myers Bogdan Vesilescu

Mining for Boilerplate Code to Identify API Usability Problems

|

slide-2
SLIDE 2

Code to write an XML document to a specified output stream?

2

slide-3
SLIDE 3

writeXMLDoc(Document doc, OutputStream out);

Code to write an XML document to a specified output stream?

Expectation

3

slide-4
SLIDE 4

static final void writeDoc(Document doc, OutputStream out) throws IOException { try { Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doc.getDoctype().getSystemId()); t.transform(new DOMSource(doc), new StreamResult(out)); } catch(TransformerException e) { throw new AssertionError(e); //Can’t happen! } } writeXMLDoc(Document doc, OutputStream out);

Code to write an XML document to a specified output stream?

Expectation Reality

4

slide-5
SLIDE 5

static final void writeDoc(Document doc, OutputStream out) throws IOException { try { Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doc.getDoctype().getSystemId()); t.transform(new DOMSource(doc), new StreamResult(out)); } catch(TransformerException e) { throw new AssertionError(e); //Can’t happen! } }

Boilerplate Code

5

slide-6
SLIDE 6

static final void writeDoc(Document doc, OutputStream out) throws IOException { try { Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doc.getDoctype().getSystemId()); t.transform(new DOMSource(doc), new StreamResult(out)); } catch(TransformerException e) { throw new AssertionError(e); //Can’t happen! } }

Boilerplate Code

Hard to understand

Error-Prone

6

Verbose

slide-7
SLIDE 7

API Design Guidelines suggest 
 to reduce the need for boilerplate code.

7

[Mosqueira-Rey et al. 2018, Reddy 2011]

slide-8
SLIDE 8

8

The existence of boilerplate client code may serve as an indicator of poor API design.

slide-9
SLIDE 9

static final void writeDoc(Document doc, OutputStream out) throws IOException { try { Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doc.getDoctype().getSystemId()); t.transform(new DOMSource(doc), new StreamResult(out)); } catch(TransformerException e) { throw new AssertionError(e); //Can’t happen! } } static final void writeDoc(Document doc, OutputStream out) throws IOException { try { Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doc.getDoctype().getSystemId()); t.transform(new DOMSource(doc), new StreamResult(out)); } catch(TransformerException e) { throw new AssertionError(e); //Can’t happen! } }

9

API Designer

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions( this, new String[]{ Manifest.permission.ACCESS_FINE_LOCATION }, LOCATION_PERMISSION_REQUEST); return; }

I thought users will need the flexibility, 
 but most users do not…

slide-10
SLIDE 10

10

static final void writeDoc(Document doc, OutputStream out) throws IOException { try { Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doc.getDoctype().getSystemId()); t.transform(new DOMSource(doc), new StreamResult(out)); } catch(TransformerException e) { throw new AssertionError(e); //Can’t happen! } } static final void writeDoc(Document doc, OutputStream out) throws IOException { try { Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doc.getDoctype().getSystemId()); t.transform(new DOMSource(doc), new StreamResult(out)); } catch(TransformerException e) { throw new AssertionError(e); //Can’t happen! } }

API Designer

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions( this, new String[]{ Manifest.permission.ACCESS_FINE_LOCATION }, LOCATION_PERMISSION_REQUEST); return; }

My API does not directly provide 
 the methods that programmers need…

slide-11
SLIDE 11

static final void writeDoc(Document doc, OutputStream out) throws IOException { try { Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doc.getDoctype().getSystemId()); t.transform(new DOMSource(doc), new StreamResult(out)); } catch(TransformerException e) { throw new AssertionError(e); //Can’t happen! } } static final void writeDoc(Document doc, OutputStream out) throws IOException { try { Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doc.getDoctype().getSystemId()); t.transform(new DOMSource(doc), new StreamResult(out)); } catch(TransformerException e) { throw new AssertionError(e); //Can’t happen! } }

11

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions( this, new String[]{ Manifest.permission.ACCESS_FINE_LOCATION }, LOCATION_PERMISSION_REQUEST); return; }

My API does not directly provide 
 the methods that programmers need…

MARBLE: API Boilerplate Code Miner

slide-12
SLIDE 12

static final void writeDoc(Document doc, OutputStream out) throws IOException { try { Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doc.getDoctype().getSystemId()); t.transform(new DOMSource(doc), new StreamResult(out)); } catch(TransformerException e) { throw new AssertionError(e); //Can’t happen! } } static final void writeDoc(Document doc, OutputStream out) throws IOException { try { Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doc.getDoctype().getSystemId()); t.transform(new DOMSource(doc), new StreamResult(out)); } catch(TransformerException e) { throw new AssertionError(e); //Can’t happen! } }

12

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions( this, new String[]{ Manifest.permission.ACCESS_FINE_LOCATION }, LOCATION_PERMISSION_REQUEST); return; }

MARBLE-found

My API does not directly provide 
 the methods that programmers need…

MARBLE: API Boilerplate Code Miner

slide-13
SLIDE 13

Define Boilerplate Code

slide-14
SLIDE 14

14

Study on Boilerplate Code

Sources Google Scholar
 GitHub Commits
 the Web — Blog Posts, Stack Overflow/Quora Q&AA
 Survey on Twitter

slide-15
SLIDE 15

15

Study on Boilerplate Code

Sources Google Scholar
 GitHub Commits
 the Web — Blog Posts, Stack Overflow/Quora Q&AA
 Survey on Twitter Data Definitions of boilerplate code Examples that are explicitly annotated as boilerplate code The rationale for the boilerplate designation

slide-16
SLIDE 16

16

Sources Google Scholar
 GitHub Commits
 the Web — Blog Posts, Stack Overflow/Quora Q&AA
 Survey on Twitter

Study on Boilerplate Code

Data Definitions of boilerplate code Examples that are explicitly annotated as boilerplate code The rationale for the boilerplate designation

4 Common Properties

slide-17
SLIDE 17

17

Common Properties of Boilerplate

P1

Annoying!!!

slide-18
SLIDE 18

18

Common Properties of Boilerplate

P1

Annoying!!! Frequently Occurs in Client Code

P2

slide-19
SLIDE 19

19

Common Properties of Boilerplate

P1

Occurs Within a Relatively Condensed Area Annoying!!! Frequently Occurs in Client Code

P2 P3

slide-20
SLIDE 20

20

Common Properties of Boilerplate

P1

Occurs Within a Relatively Condensed Area Annoying!!! Frequently Occurs in Client Code Used in Similar Forms Without Significant Variations

P2 P3 P4

slide-21
SLIDE 21

21

Common Properties of Boilerplate

P1

Occurs Within a Relatively Condensed Area Annoying!!! Frequently Occurs in Client Code Used in Similar Forms Without Significant Variations

P2 P3 P4 Subjective Automatable

slide-22
SLIDE 22

Mining Boilerplate Code

slide-23
SLIDE 23

Identifying patterns used 
 in similar forms among the client code Identifying patterns occurring within condensed area Identifying patterns occurring 
 frequently among the client code

Overview of Mining Process

23

.JAVA

Target API & Client Code Files

High Frequency Similar Structure Condensed Area

javax.xml.transform

Annoying

Viewer
 Generator

API Designer

slide-24
SLIDE 24

Overview of Mining Process

24

.JAVA

Target API & Client Code Files Ranked API Files Containing
 Usage Patterns & Each Pattern

API Usage Miner 
 (PAM)

High Frequency Similar Structure Condensed Area

.JAVA
  • 1. API Pattern &
  • 2. API Pattern &
.JAVA

javax.xml.transform

[Fowkes and Sutton, 2016]

Annoying

Viewer
 Generator

API Designer

Identifying patterns used 
 in similar forms among the client code Identifying patterns occurring within condensed area

slide-25
SLIDE 25

25

API Usage Mining

.JAVA

TargetAPI&ClientCodeFiles RankedAPIFilesContaining
 UsagePatterns&EachPattern

APIUsageMiner
 (PAM)

.JAVA

1.APIPattern& 2.APIPattern&

.JAVA

javax.xml.transform

[FowkesandSutton,2016]

High Frequency

slide-26
SLIDE 26

26

API Usage Mining

.JAVA

TargetAPI&ClientCodeFiles RankedAPIFilesContaining
 UsagePatterns&EachPattern

APIUsageMiner
 (PAM)

.JAVA

1.APIPattern& 2.APIPattern&

.JAVA

javax.xml.transform

[FowkesandSutton,2016]

High Frequency

newTransformer transform DOMSource.<init> newInstance setOutputProperty StreamResult.<init> , , , , ,

slide-27
SLIDE 27

27

API Usage Mining

.JAVA

TargetAPI&ClientCodeFiles RankedAPIFilesContaining
 UsagePatterns&EachPattern

APIUsageMiner
 (PAM)

.JAVA

1.APIPattern& 2.APIPattern&

.JAVA

javax.xml.transform

[FowkesandSutton,2016]

High Frequency

newTransformer

static final void writeDoc(Document doc, OutputStream out) throws IOException { try { Transformer t = TransformerFactory.newInstance().newTransformer(); t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, doc.getDoctype().getSystemId()); t.transform(new DOMSource(doc), new StreamResult(out)); } catch(TransformerException e) { throw new AssertionError(e); //Can’t happen! }

transform DOMSource.<init> newInstance setOutputProperty StreamResult.<init>

slide-28
SLIDE 28

Overview of Mining Process

28

.JAVA

Target API & Client Code Files Ranked API Files Containing
 Usage Patterns & Each Pattern

API Usage Miner 
 (PAM)

High Frequency Similar Structure Condensed Area

.JAVA
  • 1. API Pattern &
  • 2. API Pattern &
.JAVA

javax.xml.transform

[Fowkes and Sutton, 2016]

Annoying

Viewer
 Generator

API Designer

Identifying patterns used 
 in similar forms among the client code Identifying patterns occurring within condensed area

slide-29
SLIDE 29

Overview of Mining Process

29

.JAVA

Target API & Client Code Files Ranked API Files Containing
 Usage Patterns & Each Pattern

API Usage Miner 
 (PAM)

High Frequency Similar Structure Condensed Area

.JAVA
  • 1. API Pattern &
  • 2. API Pattern &
.JAVA

javax.xml.transform

AST Building Subtree
 Extraction

API Pattern &

API 
 Usage Pattern & Subtrees

[Fowkes and Sutton, 2016]

Annoying

Viewer
 Generator

API Designer

Identifying patterns used 
 in similar forms among the client code

slide-30
SLIDE 30

Subtree Extraction

30

.JAVA

API Pattern &

AST Building Subtree
 Extraction

API Pattern &

API Files Containing
 Usage Pattern & the Pattern API AST
 Usage Pattern & Subtrees

Condensed Area

slide-31
SLIDE 31

Subtree Extraction

31

try {
 TransformerFactory transFactory = TransformerFactory.newInstance();
 Transformer transformer = transFactory.newTransformer();
 DOMSource domSource = new DOMSource(node); 
 …

alibaba/fastjson/MiscCodec.java

Condensed Area

.JAVA

API Pattern &

AST Building Subtree
 Extraction

API Pattern &

API Files Containing
 Usage Pattern & the Pattern API AST
 Usage Pattern & Subtrees

[newInstance,newTransformer,setOutputProperty,DOMSource.<Init>,StreamResult.<Init>,Transform]

slide-32
SLIDE 32

Subtree Extraction

32

transform DOMSource StreamResult

… …

Condensed Area

.JAVA

API Pattern &

AST Building

API Pattern &

API Files Containing
 Usage Pattern & the Pattern API AST
 Usage Pattern & Subtrees

Subtree
 Extraction

newInstance newTransformer

[newInstance,newTransformer,setOutputProperty,DOMSource.<Init>,StreamResult.<Init>,Transform]

setOutputProperty

slide-33
SLIDE 33

Subtree Extraction

33

Condensed Area

.JAVA

API Pattern &

Subtree
 Extraction

API Pattern &

API Files Containing
 Usage Pattern & the Pattern API AST
 Usage Pattern & Subtrees

AST Building

[newInstance,newTransformer,setOutputProperty,DOMSource.<Init>,StreamResult.<Init>,Transform]

transform DOMSource StreamResult newInstance newTransformer setOutputProperty

slide-34
SLIDE 34

More Likely To Contain Boilerplate

34

Condensed Area

.JAVA

API Pattern &

Subtree
 Extraction

API Pattern &

API Files Containing
 Usage Pattern & the Pattern API AST
 Usage Pattern & Subtrees

AST Building

[newInstance,newTransformer,setOutputProperty,DOMSource.<Init>,StreamResult.<Init>,Transform]

transform DOMSource StreamResult newInstance newTransformer setOutputProperty

slide-35
SLIDE 35

Less Likely To Contain Boilerplate

35

newInstance … … setOutputProperty

Condensed Area

.JAVA

API Pattern &

Subtree
 Extraction

API Pattern &

API Files Containing
 Usage Pattern & the Pattern API AST
 Usage Pattern & Subtrees

AST Building

newTransformer …

slide-36
SLIDE 36

Overview of Mining Process

36

.JAVA

Target API & Client Code Files Ranked API Files Containing
 Usage Patterns & Each Pattern

API Usage Miner 
 (PAM)

High Frequency Similar Structure Condensed Area

.JAVA
  • 1. API Pattern &
  • 2. API Pattern &
.JAVA

javax.xml.transform

AST Building Subtree
 Extraction

API Pattern &

API 
 Usage Pattern & Subtrees

[Fowkes and Sutton, 2016]

Annoying

Viewer
 Generator

API Designer

Identifying patterns used 
 in similar forms among the client code

slide-37
SLIDE 37

Overview of Mining Process

37

.JAVA

Target API & Client Code Files Ranked API Files Containing
 Usage Patterns & Each Pattern

API Usage Miner 
 (PAM)

High Frequency Similar Structure Condensed Area

.JAVA
  • 1. API Pattern &
  • 2. API Pattern &
.JAVA

javax.xml.transform

AST Building Subtree
 Extraction

API Pattern &

API 
 Usage Pattern & Subtrees

Similarity
 Computation Graph
 Partitioning

[Fowkes and Sutton, 2016]

Annoying

Boilerplate Candidates

Viewer
 Generator

API Designer

slide-38
SLIDE 38

Similarity Computation

Similar Structure

38

API Pattern &

API AST
 Usage Pattern & Subtrees

Similarity
 Computation Graph
 Partitioning

Boilerplate Candidates

slide-39
SLIDE 39

Similarity Computation

39

alibaba/fastjson/ MiscCodec.java apache/jmeter/ XPathUtil.java … … … …

Similar Structure

API Pattern &

API AST
 Usage Pattern & Subtrees

Similarity
 Computation Graph
 Partitioning

Boilerplate Candidates

slide-40
SLIDE 40

Similarity Computation

40

Similar Structure

Similarity(s1,s2)

0.8 0.9 0.9 0.9 0.8 0.9

API Pattern &

API AST
 Usage Pattern & Subtrees

Similarity
 Computation Graph
 Partitioning

Boilerplate Candidates

alibaba/fastjson/ MiscCodec.java apache/jmeter/ XPathUtil.java … … … …

slide-41
SLIDE 41

Similarity Computation

41

Similar Structure

Similarity(s1,s2)

0.8 0.9 0.9 0.9 0.8 0.9

API Pattern &

API AST
 Usage Pattern & Subtrees

Boilerplate Candidates

alibaba/fastjson/ MiscCodec.java apache/jmeter/ XPathUtil.java … … … …

Graph
 Partitioning Similarity
 Computation

slide-42
SLIDE 42

Graph Partitioning

42

LesslikelyBoilerplate MorelikelyBoilerplate

#ofClusters≤Threshold #ofClusters>Threshold

Similar Structure

slide-43
SLIDE 43

Overview of Mining Process

43

.JAVA

Target API & Client Code Files Ranked API Files Containing
 Usage Patterns & Each Pattern

API Usage Miner 
 (PAM)

High Frequency Similar Structure Condensed Area

.JAVA
  • 1. API Pattern &
  • 2. API Pattern &
.JAVA

javax.xml.transform

AST Building Subtree
 Extraction

API Pattern &

API 
 Usage Pattern & Subtrees

Similarity
 Computation Graph
 Partitioning

[Fowkes and Sutton, 2016]

Annoying

Boilerplate Candidates

Viewer
 Generator

API Designer

slide-44
SLIDE 44

Candidate Viewer

44

Annoying Representative Boilerplate Client Code API Usage Pattern

slide-45
SLIDE 45

Evaluation

slide-46
SLIDE 46

13 Java APIs Client code from 10,000 Github Java repositories

46

Evaluation Dataset

1 android.app.ProgressDialog 2 android.database.sqlite

3 android.support.v4.app.ActivityCompat

4 android.view.View 5 com.squareup.picasso 6 java.beans.ProperrtyChangeSupport 7 java.beans.PropertyChangeEvent 8 java.io.BufferedReader 9 java.sql.DriverManager 10 java.swing.JFrame 11 Javax.swing.SwingUtilities 12 java.xml.parsers 13 java.xml.transform

slide-47
SLIDE 47

47

1 android.app.ProgressDialog

12

2 android.database.sqlite

7

3 android.support.v4.app.ActivityCompat

5

4 android.view.View

11

5 com.squareup.picasso 6 java.beans.ProperrtyChangeSupport

8

7 java.beans.PropertyChangeEvent

5

8 java.io.BufferedReader

3

9 java.sql.DriverManager 10 java.swing.JFrame 11 Javax.swing.SwingUtilities

2

12 java.xml.parsers

3

13 java.xml.transform

3

MARBLE returned 59 boilerplate candidates

Evaluation Dataset

slide-48
SLIDE 48

48

Precision

1 android.app.ProgressDialog

12

2 android.database.sqlite

7

3 android.support.v4.app.ActivityCompat

5

4 android.view.View

11

5 com.squareup.picasso 6 java.beans.ProperrtyChangeSupport

8

7 java.beans.PropertyChangeEvent

5

8 java.io.BufferedReader

3

9 java.sql.DriverManager 10 java.swing.JFrame 11 Javax.swing.SwingUtilities

2

12 java.xml.parsers

3

13 java.xml.transform

3

56%

Out of 59 boilerplate candidates, 33 judged to be boilerplate More than 1 out of 2 MARBLE results 
 are worth looking

slide-49
SLIDE 49

9 out of 13

49

Validation

1 android.app.ProgressDialog

12

2 android.database.sqlite

7

3 android.support.v4.app.ActivityCompat

5

4 android.view.View

11

5 com.squareup.picasso 6 java.beans.ProperrtyChangeSupport

8

7 java.beans.PropertyChangeEvent

5

8 java.io.BufferedReader

3

9 java.sql.DriverManager 10 java.swing.JFrame 11 Javax.swing.SwingUtilities

2

12 java.xml.parsers

3

13 java.xml.transform

3

Out of 13 known Boilerplate Instances 
 (one for each API) MARBLE identified 9

slide-50
SLIDE 50

Practicality

50

Annoying

Viewer
 Generator

API Designer

slide-51
SLIDE 51

Practicality

51

.JAVA

Target API & Client Code Files Ranked API Files Containing
 Usage Patterns & Each Pattern

API Usage Miner 
 (PAM)

High Frequency Similar Structure Condensed Area

.JAVA
  • 1. API Pattern &
  • 2. API Pattern &
.JAVA

AST Building Subtree
 Extraction

API Pattern &

API 
 Usage Pattern & Subtrees

Similarity
 Computation Graph
 Partitioning

[Fowkes and Sutton, 2016]

Annoying

Boilerplate Candidates

Viewer
 Generator

API Designer

slide-52
SLIDE 52

Practicality

52

.JAVA

Target API & Client Code Files Ranked API Files Containing
 Usage Patterns & Each Pattern

API Usage Miner 
 (PAM)

High Frequency Similar Structure Condensed Area

.JAVA
  • 1. API Pattern &
  • 2. API Pattern &
.JAVA

13 APIs

AST Building Subtree
 Extraction

API Pattern &

API 
 Usage Pattern & Subtrees

Similarity
 Computation Graph
 Partitioning

[Fowkes and Sutton, 2016]

Annoying

Boilerplate Candidates

Viewer
 Generator

API Designer

slide-53
SLIDE 53

Practicality

53

.JAVA

Target API & Client Code Files Ranked API Files Containing
 Usage Patterns & Each Pattern

API Usage Miner 
 (PAM)

High Frequency Similar Structure Condensed Area

.JAVA
  • 1. API Pattern &
  • 2. API Pattern &
.JAVA

13 APIs

AST Building Subtree
 Extraction

API Pattern &

API 
 Usage Pattern & Subtrees

Similarity
 Computation Graph
 Partitioning

[Fowkes and Sutton, 2016]

Annoying

Boilerplate Candidates

Viewer
 Generator

API Designer

200 Patterns

slide-54
SLIDE 54

Practicality

54

.JAVA

Target API & Client Code Files Ranked API Files Containing
 Usage Patterns & Each Pattern

API Usage Miner 
 (PAM)

High Frequency Similar Structure Condensed Area

.JAVA
  • 1. API Pattern &
  • 2. API Pattern &
.JAVA

13 APIs

AST Building Subtree
 Extraction

API Pattern &

API 
 Usage Pattern & Subtrees

Similarity
 Computation Graph
 Partitioning

[Fowkes and Sutton, 2016]

Annoying

Boilerplate Candidates

Viewer
 Generator

API Designer

200 Patterns 4.5 Candidates

slide-55
SLIDE 55

Practicality

55

.JAVA

Target API & Client Code Files Ranked API Files Containing
 Usage Patterns & Each Pattern

API Usage Miner 
 (PAM)

High Frequency Similar Structure Condensed Area

.JAVA
  • 1. API Pattern &
  • 2. API Pattern &
.JAVA

13 APIs

AST Building Subtree
 Extraction

API Pattern &

API 
 Usage Pattern & Subtrees

Similarity
 Computation Graph
 Partitioning

[Fowkes and Sutton, 2016]

Annoying

Boilerplate Candidates

Viewer
 Generator

API Designer

200 Patterns 4.5 Candidates

2.25 %

slide-56
SLIDE 56

56

Pattern API

android.database.sqlite

Boilerplate Review Example

[execSQL, onCreate]

slide-57
SLIDE 57

57

Client Code Pattern

@Override public void onUpgrade( SQLiteDatabase db, int oldVersion, int currentVersion) { Log.w(TAG, ”Upgrading test database from version ” + oldVersion + ” to ” + currentVersion + ”, which will destroy all old data”); db.execSQL(”DROP TABLE IF EXISTS data”);

  • nCreate(db);

}

API

[execSQL, onCreate] android.database.sqlite

Boilerplate Review Example

slide-58
SLIDE 58

58

Potential Improvement

To make the common usage as the default functionality of

  • nUpgrade.

Client Code Pattern

@Override public void onUpgrade( SQLiteDatabase db, int oldVersion, int currentVersion) { Log.w(TAG, ”Upgrading test database from version ” + oldVersion + ” to ” + currentVersion + ”, which will destroy all old data”); db.execSQL(”DROP TABLE IF EXISTS data”);

  • nCreate(db);

}

API

android.database.sqlite

Boilerplate Review Example

[execSQL, onCreate]

slide-59
SLIDE 59

59

Next Steps

Mining Algorithm Apply other techniques for each step
 (e.g., code clone detection, program slicing techniques). Qualitative Study More extensive evaluation by surveying

  • pen source API designers with mined

boilerplate instances of their APIs. Definition The definition and properties of boilerplate could also be refined.

slide-60
SLIDE 60

Daye Nam: dayen@andrew.cmu.edu

MARBLE and the result are available at https://dayenam.com/MARBLE

Target API & Client Code Files API Usage Miner 
 (PAM) AST Building Subtree
 Extraction Similarity
 Computation Graph
 Partitioning

Boilerplate
 Viewer

Condensed Area Similar Structure High Frequency

MARBLE: Mining for Boilerplate Code to Identify API Usability Problems

Annoying

  • The existence of boilerplate code

may serve as an indicator of poor API usability.

  • MARBLE can identify known and

new boilerplate instances, and returns reasonable number of results for the manual review of API design.