SlideShare a Scribd company logo
Defaultification Refactoring: A Tool for
Automatically Converting Java Methods to
Default
Raffi Khatchadourian1,2
Hidehiko Masuhara3
International Conference on Automated Software Engineering, 2017
1
Computer Science, Hunter College, City University of New York, USA
2
Computer Science, The Graduate Center, City University of New York, USA
3
Mathematical and Computing Science, Tokyo Institute of Technology, Japan
Motivation
Interfaces Are Traditionally Lists of Method Declarations
• Traditionally, an interface is a Java type that lists method
declarations.
interface Collection<E> {
int size();
void add(E elem);
boolean isEmpty();
int capacity();
abstract boolean atCapacity();} 1
Interfaces Are Traditionally Lists of Method Declarations
• Traditionally, an interface is a Java type that lists method
declarations.
• Clients are guaranteed that concrete interface implementers
provide implementations for all listed methods.
interface Collection<E> {
int size();
void add(E elem);
boolean isEmpty();
int capacity();
abstract boolean atCapacity();} 1
Some Interface Methods Are Optional
• Interface methods can be listed as optional operations.
interface Collection<E> {
// ...
void add(E elem); /* optional */ }}
2
Some Interface Methods Are Optional
• Interface methods can be listed as optional operations.
• Implementers may choose to support them or not.
interface Collection<E> {
// ...
void add(E elem); /* optional */ }}
class ImmutableList<E> implements Collection<E> {
// ...
}
2
Some Interface Methods Are Optional
• Interface methods can be listed as optional operations.
• Implementers may choose to support them or not.
• If operations are unsupported, they conventionally throw an
UnsupportedOperationException.
interface Collection<E> {
// ...
void add(E elem); /* optional */ }}
class ImmutableList<E> implements Collection<E> {
// ...
@Override public void add(E elem) {
throw new UnsupportedOperationException();}}
2
Skeletal Implementation Classes Help Implement Interfaces
• The skeletal implementation design pattern [Bloch, 2008] is
used to make implementing interfaces easier.
3
Skeletal Implementation Classes Help Implement Interfaces
• The skeletal implementation design pattern [Bloch, 2008] is
used to make implementing interfaces easier.
• Abstract skeletal implementation class provides partial
implementations.
abstract class AbstractImmutableList<E> implements
Collection<E> {
@Override public void add(E elem) {
throw new UnsupportedOperationException();}}
3
Skeletal Implementation Classes Help Implement Interfaces
• The skeletal implementation design pattern [Bloch, 2008] is
used to make implementing interfaces easier.
• Abstract skeletal implementation class provides partial
implementations.
• Implementers extend the skeletal implementation class rather
than directly implementing the interface.
abstract class AbstractImmutableList<E> implements
Collection<E> {
@Override public void add(E elem) {
throw new UnsupportedOperationException();}}
class ImmutableList<E> extends AbstractImmutableList<E>{
// ...
@Override public void add(E elem) {
throw new UnsupportedOperationException();}}}
3
The Skeletal Implementation Pattern Has Several Drawbacks
The skeletal implementation pattern has several drawbacks.
4
The Skeletal Implementation Pattern Has Several Drawbacks
The skeletal implementation pattern has several drawbacks.
Example
ImmutableList cannot:
4
The Skeletal Implementation Pattern Has Several Drawbacks
The skeletal implementation pattern has several drawbacks.
Example
ImmutableList cannot:
• Subclass another class.
4
The Skeletal Implementation Pattern Has Several Drawbacks
The skeletal implementation pattern has several drawbacks.
Example
ImmutableList cannot:
• Subclass another class.
• Inherit skeletal implementations split over multiple
classes [Horstmann, 2014].
4
The Skeletal Implementation Pattern Has Several Drawbacks
The skeletal implementation pattern has several drawbacks.
Example
ImmutableList cannot:
• Subclass another class.
• Inherit skeletal implementations split over multiple
classes [Horstmann, 2014].
• Inherit skeletal implementations for multiple interfaces.
4
Java 8 Default Methods Can Replace Skeletal Implementations
• Java 8 enhanced interfaces allow both method declarations and
definitions.
interface Collection<E> {
default void add(E elem) { // optional.
throw new UnsupportedOperationException();}}
5
Java 8 Default Methods Can Replace Skeletal Implementations
• Java 8 enhanced interfaces allow both method declarations and
definitions.
• Implementers inherit the (default) implementation if none
provided.
interface Collection<E> {
default void add(E elem) { // optional.
throw new UnsupportedOperationException();}}
class ImmutableList<E> implements Collection<E> {}
5
Java 8 Default Methods Can Replace Skeletal Implementations
• Java 8 enhanced interfaces allow both method declarations and
definitions.
• Implementers inherit the (default) implementation if none
provided.
• Original motivation to facilitate interface evolution.
interface Collection<E> {
default void add(E elem) { // optional.
throw new UnsupportedOperationException();}}
class ImmutableList<E> implements Collection<E> {}
5
Java 8 Default Methods Can Replace Skeletal Implementations
• Java 8 enhanced interfaces allow both method declarations and
definitions.
• Implementers inherit the (default) implementation if none
provided.
• Original motivation to facilitate interface evolution.
• Can also be used as a replacement of the skeletal
implementation pattern [Goetz, 2011].
interface Collection<E> {
default void add(E elem) { // optional.
throw new UnsupportedOperationException();}}
class ImmutableList<E> implements Collection<E> {}
abstract class AbstractImmutableList<E> implements
Collection<E> {
@Override public void add(E elem) {
throw new UnsupportedOperationException();}}
5
Implementation
• Implemented as an open source plug-in for the Eclipse IDE
(available at http://cuny.is/interefact).
6
• Implemented as an open source plug-in for the Eclipse IDE
(available at http://cuny.is/interefact).
• Built on existing refactoring support in Eclipse.
6
• Implemented as an open source plug-in for the Eclipse IDE
(available at http://cuny.is/interefact).
• Built on existing refactoring support in Eclipse.
• Conceptual approach based on type-constraints [Palsberg and
Schwartzbach, 1994; Tip et al., 2011].
6
• Implemented as an open source plug-in for the Eclipse IDE
(available at http://cuny.is/interefact).
• Built on existing refactoring support in Eclipse.
• Conceptual approach based on type-constraints [Palsberg and
Schwartzbach, 1994; Tip et al., 2011].
• See ICSE 2017 paper [Khatchadourian and Masuhara, 2017] for
approach details.
6
• Implemented as an open source plug-in for the Eclipse IDE
(available at http://cuny.is/interefact).
• Built on existing refactoring support in Eclipse.
• Conceptual approach based on type-constraints [Palsberg and
Schwartzbach, 1994; Tip et al., 2011].
• See ICSE 2017 paper [Khatchadourian and Masuhara, 2017] for
approach details.
• Implementation is in procedural-style, similar to Pull Up
Method refactoring. 6
High-level System Workflow
7
High-level System Workflow
2. Options control refactoring “invasiveness.”
7
High-level System Workflow
2. Options control refactoring “invasiveness.”
• Remove or deprecate empty classes.
7
High-level System Workflow
2. Options control refactoring “invasiveness.”
• Remove or deprecate empty classes.
• Consider non-standard annotation differences.
7
High-level System Workflow
2. Options control refactoring “invasiveness.”
• Remove or deprecate empty classes.
• Consider non-standard annotation differences.
3. Simple initial checks, e.g., file writability.
7
High-level System Workflow
2. Options control refactoring “invasiveness.”
• Remove or deprecate empty classes.
• Consider non-standard annotation differences.
3. Simple initial checks, e.g., file writability.
4. Bulk of processing in final check. 7
Architecture and Plug-In Dependencies
• Four plugins: two internal and two with UIs.
8
Architecture and Plug-In Dependencies
• Four plugins: two internal and two with UIs.
• Internal plug-ins include core and test plug-ins.
8
Architecture and Plug-In Dependencies
• Four plugins: two internal and two with UIs.
• Internal plug-ins include core and test plug-ins.
• 259 automated refactoring tests.
8
Architecture and Plug-In Dependencies
• Four plugins: two internal and two with UIs.
• Internal plug-ins include core and test plug-ins.
• 259 automated refactoring tests.
• UI plug-ins include both end-user tool and evaluator.
8
Architecture and Plug-In Dependencies
• Four plugins: two internal and two with UIs.
• Internal plug-ins include core and test plug-ins.
• 259 automated refactoring tests.
• UI plug-ins include both end-user tool and evaluator.
• Depends on Eclipse refactoring support. 8
Evaluation
Useful?
• Successfully converted ∼20%
of methods possibly
participating in the pattern to
default methods in
corresponding interfaces
(see [Khatchadourian and
Masuhara, 2017] for details).
9
Useful?
• Successfully converted ∼20%
of methods possibly
participating in the pattern to
default methods in
corresponding interfaces
(see [Khatchadourian and
Masuhara, 2017] for details).
• Many failures related to:
9
Useful?
• Successfully converted ∼20%
of methods possibly
participating in the pattern to
default methods in
corresponding interfaces
(see [Khatchadourian and
Masuhara, 2017] for details).
• Many failures related to:
• Inaccessibility of members
between skeletal
implementers and
interfaces.
9
Useful?
• Successfully converted ∼20%
of methods possibly
participating in the pattern to
default methods in
corresponding interfaces
(see [Khatchadourian and
Masuhara, 2017] for details).
• Many failures related to:
• Inaccessibility of members
between skeletal
implementers and
interfaces.
• Access to instance fields.
9
Correct?
• Ensured that no compilation
errors existed before and
after refactoring.
10
Correct?
• Ensured that no compilation
errors existed before and
after refactoring.
• Verified unit tests results
identical before and after the
refactoring.
10
Correct?
• Ensured that no compilation
errors existed before and
after refactoring.
• Verified unit tests results
identical before and after the
refactoring.
• Preliminary pull request
study ensures that the
automated results matched
what experienced developers
may have written.
10
Correct?
• Ensured that no compilation
errors existed before and
after refactoring.
• Verified unit tests results
identical before and after the
refactoring.
• Preliminary pull request
study ensures that the
automated results matched
what experienced developers
may have written.
• Four projects accepted our
pull requests so far.
10
Summary
Summary & Future Work
• A refactoring tool that migrates the skeletal implementation
pattern to instead use Java 8 default methods based on
type-constraints.
11
Summary & Future Work
• A refactoring tool that migrates the skeletal implementation
pattern to instead use Java 8 default methods based on
type-constraints.
• Implemented as an Eclipse IDE plug-in (available at
http://cuny.is/interefact).
11
Summary & Future Work
• A refactoring tool that migrates the skeletal implementation
pattern to instead use Java 8 default methods based on
type-constraints.
• Implemented as an Eclipse IDE plug-in (available at
http://cuny.is/interefact).
• Evaluated using several techniques.
11
Summary & Future Work
• A refactoring tool that migrates the skeletal implementation
pattern to instead use Java 8 default methods based on
type-constraints.
• Implemented as an Eclipse IDE plug-in (available at
http://cuny.is/interefact).
• Evaluated using several techniques.
• In the future, composite refactorings (field encapsulation, etc.).
11
For Further Reading
Joshua Bloch. Effective Java. Addison Wesley, 2 edition, 2008. ISBN 0321356683.
Brian Goetz. Interface evolution via virtual extensions methods. Technical report,
Oracle Corporation, June 2011. URL http://cr.openjdk.java.net/
~briangoetz/lambda/Defender%20Methods%20v4.pdf.
Cay S. Horstmann. Java SE 8 for the Really Impatient. Addison-Wesley Professional,
2014.
Raffi Khatchadourian and Hidehiko Masuhara. Automated refactoring of legacy Java
software to default methods. In International Conference on Software Engineering,
2017.
Jens Palsberg and Michael I. Schwartzbach. Object-oriented type systems. John Wiley
and Sons Ltd., 1994. ISBN 0-471-94128-X.
Frank Tip, Robert M. Fuhrer, Adam Kieżun, Michael D. Ernst, Ittai Balaban, and Bjorn
De Sutter. Refactoring using type constraints. ACM Transactions on Programming
Languages and Systems, 2011. doi: 10.1145/1961204.1961205.
12

More Related Content

PDF
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
PDF
Automatic Migration of Legacy Java Method Implementations to Interfaces
PPTX
Java SE 8 - New Features
PPTX
java 8 new features
PDF
Java8 features
PPTX
Java 8 Features
PPTX
Java 8 - Features Overview
Defaultification Refactoring: A Tool for Automatically Converting Java Method...
Automatic Migration of Legacy Java Method Implementations to Interfaces
Java SE 8 - New Features
java 8 new features
Java8 features
Java 8 Features
Java 8 - Features Overview

What's hot (20)

PPTX
Type Annotations in Java 8
PDF
Java Annotation Processing: A Beginner Walkthrough
PDF
CS5393-Korat_Mittal_Akshay_ProjReport
PPTX
Java Annotations
PDF
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
PPT
Annotations
PDF
Exception handling
PDF
Applicative Logic Meta-Programming as the foundation for Template-based Progr...
PPTX
PDF
Data access
PDF
Java lab1 manual
PPTX
Certification preparation - Error Handling and Troubleshooting recap.pptx
PDF
.Net Classes and Objects | UiPath Community
PPTX
Certification preparation - Net classses and functions.pptx
PPT
Java Annotation
PDF
Java SE 8
PPT
Major Java 8 features
PPS
Packages and inbuilt classes of java
ODP
EJB 3.0 Walkthrough (2006)
PDF
Java concurrency
Type Annotations in Java 8
Java Annotation Processing: A Beginner Walkthrough
CS5393-Korat_Mittal_Akshay_ProjReport
Java Annotations
Lambdas and Streams in Java SE 8: Making Bulk Operations simple - Simon Ritter
Annotations
Exception handling
Applicative Logic Meta-Programming as the foundation for Template-based Progr...
Data access
Java lab1 manual
Certification preparation - Error Handling and Troubleshooting recap.pptx
.Net Classes and Objects | UiPath Community
Certification preparation - Net classses and functions.pptx
Java Annotation
Java SE 8
Major Java 8 features
Packages and inbuilt classes of java
EJB 3.0 Walkthrough (2006)
Java concurrency
Ad

Similar to Defaultification Refactoring: A Tool for Automatically Converting Java Methods to Default (20)

PDF
Automated Refactoring of Legacy Java Software to Default Methods Talk at ICSE...
PDF
Automated Refactoring of Legacy Java Software to Default Methods Talk at GMU
PDF
Stream Api.pdf
PPTX
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
PDF
Advanced Java Testing
PDF
Learn about Eclipse e4 from Lars Vogel at SF-JUG
PDF
Eclipse 40 - Eclipse Summit Europe 2010
PDF
‏‏‏‏‏‏oop lecture 6_١٢٥٩٤٧taiz univercity.pdf
PDF
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
PPT
Eclipse 2011 Hot Topics
PPTX
Pptchdtdtfygugyxthgihhihigugufydtdfzrzrzrtdyfyfy
PPTX
Design Patterns - Part 1 of 2
PPTX
The Road to Lambda - Mike Duigou
PPTX
Writing Well Abstracted Automation on Foundations of Jello
PDF
C# 8 in Libraries and Applications - BASTA! Frankfurt 2020
PPTX
Java For beginners and CSIT and IT students
PPT
What is Java Technology (An introduction with comparision of .net coding)
PDF
Test Driven Development with JavaFX
PDF
Testing Angular
PDF
Design Patterns
Automated Refactoring of Legacy Java Software to Default Methods Talk at ICSE...
Automated Refactoring of Legacy Java Software to Default Methods Talk at GMU
Stream Api.pdf
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
Advanced Java Testing
Learn about Eclipse e4 from Lars Vogel at SF-JUG
Eclipse 40 - Eclipse Summit Europe 2010
‏‏‏‏‏‏oop lecture 6_١٢٥٩٤٧taiz univercity.pdf
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Eclipse 2011 Hot Topics
Pptchdtdtfygugyxthgihhihigugufydtdfzrzrzrtdyfyfy
Design Patterns - Part 1 of 2
The Road to Lambda - Mike Duigou
Writing Well Abstracted Automation on Foundations of Jello
C# 8 in Libraries and Applications - BASTA! Frankfurt 2020
Java For beginners and CSIT and IT students
What is Java Technology (An introduction with comparision of .net coding)
Test Driven Development with JavaFX
Testing Angular
Design Patterns
Ad

More from Raffi Khatchadourian (20)

PDF
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
PDF
Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...
PDF
Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...
PDF
Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...
PDF
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
PDF
A Tool for Rejuvenating Feature Logging Levels via Git Histories and Degree o...
PDF
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
PPTX
Actor Concurrency Bugs: A Comprehensive Study on Symptoms, Root Causes, API U...
PDF
An Empirical Study of Refactorings and Technical Debt in Machine Learning Sys...
PDF
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
PDF
An Empirical Study on the Use and Misuse of Java 8 Streams
PDF
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams
PDF
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams
PDF
A Brief Introduction to Type Constraints
PDF
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams ...
PDF
A Tool for Optimizing Java 8 Stream Software via Automated Refactoring
PDF
Porting the NetBeans Java 8 Enhanced For Loop Lambda Expression Refactoring t...
PDF
Towards Safe Refactoring for Intelligent Parallelization of Java 8 Streams
PDF
Proactive Empirical Assessment of New Language Feature Adoption via Automated...
PDF
Poster on Automated Refactoring of Legacy Java Software to Default Methods
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...
Hybridize Functions: A Tool for Automatically Refactoring Imperative Deep Lea...
Towards Safe Automated Refactoring of Imperative Deep Learning Programs to Gr...
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
A Tool for Rejuvenating Feature Logging Levels via Git Histories and Degree o...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Actor Concurrency Bugs: A Comprehensive Study on Symptoms, Root Causes, API U...
An Empirical Study of Refactorings and Technical Debt in Machine Learning Sys...
Automated Evolution of Feature Logging Statement Levels Using Git Histories a...
An Empirical Study on the Use and Misuse of Java 8 Streams
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams
A Brief Introduction to Type Constraints
Safe Automated Refactoring for Intelligent Parallelization of Java 8 Streams ...
A Tool for Optimizing Java 8 Stream Software via Automated Refactoring
Porting the NetBeans Java 8 Enhanced For Loop Lambda Expression Refactoring t...
Towards Safe Refactoring for Intelligent Parallelization of Java 8 Streams
Proactive Empirical Assessment of New Language Feature Adoption via Automated...
Poster on Automated Refactoring of Legacy Java Software to Default Methods

Recently uploaded (20)

PDF
System and Network Administration Chapter 2
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
AI in Product Development-omnex systems
PPTX
Transform Your Business with a Software ERP System
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
top salesforce developer skills in 2025.pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
medical staffing services at VALiNTRY
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
System and Network Administration Chapter 2
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
AI in Product Development-omnex systems
Transform Your Business with a Software ERP System
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Design an Analysis of Algorithms I-SECS-1021-03
top salesforce developer skills in 2025.pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Operating system designcfffgfgggggggvggggggggg
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
How to Migrate SBCGlobal Email to Yahoo Easily
Navsoft: AI-Powered Business Solutions & Custom Software Development
PTS Company Brochure 2025 (1).pdf.......
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Wondershare Filmora 15 Crack With Activation Key [2025
How to Choose the Right IT Partner for Your Business in Malaysia
medical staffing services at VALiNTRY
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus

Defaultification Refactoring: A Tool for Automatically Converting Java Methods to Default

  • 1. Defaultification Refactoring: A Tool for Automatically Converting Java Methods to Default Raffi Khatchadourian1,2 Hidehiko Masuhara3 International Conference on Automated Software Engineering, 2017 1 Computer Science, Hunter College, City University of New York, USA 2 Computer Science, The Graduate Center, City University of New York, USA 3 Mathematical and Computing Science, Tokyo Institute of Technology, Japan
  • 3. Interfaces Are Traditionally Lists of Method Declarations • Traditionally, an interface is a Java type that lists method declarations. interface Collection<E> { int size(); void add(E elem); boolean isEmpty(); int capacity(); abstract boolean atCapacity();} 1
  • 4. Interfaces Are Traditionally Lists of Method Declarations • Traditionally, an interface is a Java type that lists method declarations. • Clients are guaranteed that concrete interface implementers provide implementations for all listed methods. interface Collection<E> { int size(); void add(E elem); boolean isEmpty(); int capacity(); abstract boolean atCapacity();} 1
  • 5. Some Interface Methods Are Optional • Interface methods can be listed as optional operations. interface Collection<E> { // ... void add(E elem); /* optional */ }} 2
  • 6. Some Interface Methods Are Optional • Interface methods can be listed as optional operations. • Implementers may choose to support them or not. interface Collection<E> { // ... void add(E elem); /* optional */ }} class ImmutableList<E> implements Collection<E> { // ... } 2
  • 7. Some Interface Methods Are Optional • Interface methods can be listed as optional operations. • Implementers may choose to support them or not. • If operations are unsupported, they conventionally throw an UnsupportedOperationException. interface Collection<E> { // ... void add(E elem); /* optional */ }} class ImmutableList<E> implements Collection<E> { // ... @Override public void add(E elem) { throw new UnsupportedOperationException();}} 2
  • 8. Skeletal Implementation Classes Help Implement Interfaces • The skeletal implementation design pattern [Bloch, 2008] is used to make implementing interfaces easier. 3
  • 9. Skeletal Implementation Classes Help Implement Interfaces • The skeletal implementation design pattern [Bloch, 2008] is used to make implementing interfaces easier. • Abstract skeletal implementation class provides partial implementations. abstract class AbstractImmutableList<E> implements Collection<E> { @Override public void add(E elem) { throw new UnsupportedOperationException();}} 3
  • 10. Skeletal Implementation Classes Help Implement Interfaces • The skeletal implementation design pattern [Bloch, 2008] is used to make implementing interfaces easier. • Abstract skeletal implementation class provides partial implementations. • Implementers extend the skeletal implementation class rather than directly implementing the interface. abstract class AbstractImmutableList<E> implements Collection<E> { @Override public void add(E elem) { throw new UnsupportedOperationException();}} class ImmutableList<E> extends AbstractImmutableList<E>{ // ... @Override public void add(E elem) { throw new UnsupportedOperationException();}}} 3
  • 11. The Skeletal Implementation Pattern Has Several Drawbacks The skeletal implementation pattern has several drawbacks. 4
  • 12. The Skeletal Implementation Pattern Has Several Drawbacks The skeletal implementation pattern has several drawbacks. Example ImmutableList cannot: 4
  • 13. The Skeletal Implementation Pattern Has Several Drawbacks The skeletal implementation pattern has several drawbacks. Example ImmutableList cannot: • Subclass another class. 4
  • 14. The Skeletal Implementation Pattern Has Several Drawbacks The skeletal implementation pattern has several drawbacks. Example ImmutableList cannot: • Subclass another class. • Inherit skeletal implementations split over multiple classes [Horstmann, 2014]. 4
  • 15. The Skeletal Implementation Pattern Has Several Drawbacks The skeletal implementation pattern has several drawbacks. Example ImmutableList cannot: • Subclass another class. • Inherit skeletal implementations split over multiple classes [Horstmann, 2014]. • Inherit skeletal implementations for multiple interfaces. 4
  • 16. Java 8 Default Methods Can Replace Skeletal Implementations • Java 8 enhanced interfaces allow both method declarations and definitions. interface Collection<E> { default void add(E elem) { // optional. throw new UnsupportedOperationException();}} 5
  • 17. Java 8 Default Methods Can Replace Skeletal Implementations • Java 8 enhanced interfaces allow both method declarations and definitions. • Implementers inherit the (default) implementation if none provided. interface Collection<E> { default void add(E elem) { // optional. throw new UnsupportedOperationException();}} class ImmutableList<E> implements Collection<E> {} 5
  • 18. Java 8 Default Methods Can Replace Skeletal Implementations • Java 8 enhanced interfaces allow both method declarations and definitions. • Implementers inherit the (default) implementation if none provided. • Original motivation to facilitate interface evolution. interface Collection<E> { default void add(E elem) { // optional. throw new UnsupportedOperationException();}} class ImmutableList<E> implements Collection<E> {} 5
  • 19. Java 8 Default Methods Can Replace Skeletal Implementations • Java 8 enhanced interfaces allow both method declarations and definitions. • Implementers inherit the (default) implementation if none provided. • Original motivation to facilitate interface evolution. • Can also be used as a replacement of the skeletal implementation pattern [Goetz, 2011]. interface Collection<E> { default void add(E elem) { // optional. throw new UnsupportedOperationException();}} class ImmutableList<E> implements Collection<E> {} abstract class AbstractImmutableList<E> implements Collection<E> { @Override public void add(E elem) { throw new UnsupportedOperationException();}} 5
  • 21. • Implemented as an open source plug-in for the Eclipse IDE (available at http://cuny.is/interefact). 6
  • 22. • Implemented as an open source plug-in for the Eclipse IDE (available at http://cuny.is/interefact). • Built on existing refactoring support in Eclipse. 6
  • 23. • Implemented as an open source plug-in for the Eclipse IDE (available at http://cuny.is/interefact). • Built on existing refactoring support in Eclipse. • Conceptual approach based on type-constraints [Palsberg and Schwartzbach, 1994; Tip et al., 2011]. 6
  • 24. • Implemented as an open source plug-in for the Eclipse IDE (available at http://cuny.is/interefact). • Built on existing refactoring support in Eclipse. • Conceptual approach based on type-constraints [Palsberg and Schwartzbach, 1994; Tip et al., 2011]. • See ICSE 2017 paper [Khatchadourian and Masuhara, 2017] for approach details. 6
  • 25. • Implemented as an open source plug-in for the Eclipse IDE (available at http://cuny.is/interefact). • Built on existing refactoring support in Eclipse. • Conceptual approach based on type-constraints [Palsberg and Schwartzbach, 1994; Tip et al., 2011]. • See ICSE 2017 paper [Khatchadourian and Masuhara, 2017] for approach details. • Implementation is in procedural-style, similar to Pull Up Method refactoring. 6
  • 27. High-level System Workflow 2. Options control refactoring “invasiveness.” 7
  • 28. High-level System Workflow 2. Options control refactoring “invasiveness.” • Remove or deprecate empty classes. 7
  • 29. High-level System Workflow 2. Options control refactoring “invasiveness.” • Remove or deprecate empty classes. • Consider non-standard annotation differences. 7
  • 30. High-level System Workflow 2. Options control refactoring “invasiveness.” • Remove or deprecate empty classes. • Consider non-standard annotation differences. 3. Simple initial checks, e.g., file writability. 7
  • 31. High-level System Workflow 2. Options control refactoring “invasiveness.” • Remove or deprecate empty classes. • Consider non-standard annotation differences. 3. Simple initial checks, e.g., file writability. 4. Bulk of processing in final check. 7
  • 32. Architecture and Plug-In Dependencies • Four plugins: two internal and two with UIs. 8
  • 33. Architecture and Plug-In Dependencies • Four plugins: two internal and two with UIs. • Internal plug-ins include core and test plug-ins. 8
  • 34. Architecture and Plug-In Dependencies • Four plugins: two internal and two with UIs. • Internal plug-ins include core and test plug-ins. • 259 automated refactoring tests. 8
  • 35. Architecture and Plug-In Dependencies • Four plugins: two internal and two with UIs. • Internal plug-ins include core and test plug-ins. • 259 automated refactoring tests. • UI plug-ins include both end-user tool and evaluator. 8
  • 36. Architecture and Plug-In Dependencies • Four plugins: two internal and two with UIs. • Internal plug-ins include core and test plug-ins. • 259 automated refactoring tests. • UI plug-ins include both end-user tool and evaluator. • Depends on Eclipse refactoring support. 8
  • 38. Useful? • Successfully converted ∼20% of methods possibly participating in the pattern to default methods in corresponding interfaces (see [Khatchadourian and Masuhara, 2017] for details). 9
  • 39. Useful? • Successfully converted ∼20% of methods possibly participating in the pattern to default methods in corresponding interfaces (see [Khatchadourian and Masuhara, 2017] for details). • Many failures related to: 9
  • 40. Useful? • Successfully converted ∼20% of methods possibly participating in the pattern to default methods in corresponding interfaces (see [Khatchadourian and Masuhara, 2017] for details). • Many failures related to: • Inaccessibility of members between skeletal implementers and interfaces. 9
  • 41. Useful? • Successfully converted ∼20% of methods possibly participating in the pattern to default methods in corresponding interfaces (see [Khatchadourian and Masuhara, 2017] for details). • Many failures related to: • Inaccessibility of members between skeletal implementers and interfaces. • Access to instance fields. 9
  • 42. Correct? • Ensured that no compilation errors existed before and after refactoring. 10
  • 43. Correct? • Ensured that no compilation errors existed before and after refactoring. • Verified unit tests results identical before and after the refactoring. 10
  • 44. Correct? • Ensured that no compilation errors existed before and after refactoring. • Verified unit tests results identical before and after the refactoring. • Preliminary pull request study ensures that the automated results matched what experienced developers may have written. 10
  • 45. Correct? • Ensured that no compilation errors existed before and after refactoring. • Verified unit tests results identical before and after the refactoring. • Preliminary pull request study ensures that the automated results matched what experienced developers may have written. • Four projects accepted our pull requests so far. 10
  • 47. Summary & Future Work • A refactoring tool that migrates the skeletal implementation pattern to instead use Java 8 default methods based on type-constraints. 11
  • 48. Summary & Future Work • A refactoring tool that migrates the skeletal implementation pattern to instead use Java 8 default methods based on type-constraints. • Implemented as an Eclipse IDE plug-in (available at http://cuny.is/interefact). 11
  • 49. Summary & Future Work • A refactoring tool that migrates the skeletal implementation pattern to instead use Java 8 default methods based on type-constraints. • Implemented as an Eclipse IDE plug-in (available at http://cuny.is/interefact). • Evaluated using several techniques. 11
  • 50. Summary & Future Work • A refactoring tool that migrates the skeletal implementation pattern to instead use Java 8 default methods based on type-constraints. • Implemented as an Eclipse IDE plug-in (available at http://cuny.is/interefact). • Evaluated using several techniques. • In the future, composite refactorings (field encapsulation, etc.). 11
  • 51. For Further Reading Joshua Bloch. Effective Java. Addison Wesley, 2 edition, 2008. ISBN 0321356683. Brian Goetz. Interface evolution via virtual extensions methods. Technical report, Oracle Corporation, June 2011. URL http://cr.openjdk.java.net/ ~briangoetz/lambda/Defender%20Methods%20v4.pdf. Cay S. Horstmann. Java SE 8 for the Really Impatient. Addison-Wesley Professional, 2014. Raffi Khatchadourian and Hidehiko Masuhara. Automated refactoring of legacy Java software to default methods. In International Conference on Software Engineering, 2017. Jens Palsberg and Michael I. Schwartzbach. Object-oriented type systems. John Wiley and Sons Ltd., 1994. ISBN 0-471-94128-X. Frank Tip, Robert M. Fuhrer, Adam Kieżun, Michael D. Ernst, Ittai Balaban, and Bjorn De Sutter. Refactoring using type constraints. ACM Transactions on Programming Languages and Systems, 2011. doi: 10.1145/1961204.1961205. 12