Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tatsuya Miyake Takashi Ishio Katsuro Inoue

Similar presentations


Presentation on theme: "Tatsuya Miyake Takashi Ishio Katsuro Inoue"— Presentation transcript:

1 Tatsuya Miyake Takashi Ishio Katsuro Inoue
Towards Maintenance Support for Idiom-based Code Using Sequential Pattern Mining Tatsuya Miyake Takashi Ishio Katsuro Inoue Thank you, chair. My name is Tatsuya Miyake from Osaka university in Japan. I am talking about Towards Maintenance Support for Idiom based Code Using Sequential Pattern Mining.

2 Code derived from an idiom
An idiom is a code fragment to implement a particular kind of concern. while (iter.hasNext()) { Item item = (Item)iter.next(); buf.append(item.toString()); } copy- and- paste reuse the idiom Data data = (Data)iter.next(); buf.append(process(data)); buf.append(data.toString()); code1 code2 code3 As a background, I talk about a code fragment derived from an idiom and a defect crosscutting modules. At first I talk about code derived from an idiom. An idiom is a code fragment to implement a particular kind of concern. For example, these three code fragments use the same iterator pattern. Code2 is a code clone of code1, a code fragment that has identical or similar code fragments to it in the source code. Code3 is a code modified after copy-and-pasted. AOASIA3 2018/11/27

3 A defect crosscutting modules
A company reuses many idioms in a software. An idiom often spread across several systems. When a defect is found in an idiom, developers have to inspect all instances of the idiom. A similar problem is well-known in code-clone research, but code clone does not cover idioms. while (iter.hasNext()) { Item item = (Item)iter.next(); buf.append(item.toString()); } copy- and- paste reuse the idiom Data data = (Data)iter.next(); buf.append(process(data)); buf.append(data.toString()); code1 code2 code3 Next, I talk about a defect crosscutting modules. A company reuses many idioms in a software. This often leads an idiom spread across several systems. When a defect is found in an idiom, developers have to inspect all instances of the idiom. A similar problem is well-known in code-clone research, but code clone does not cover idioms. For example, when the idiom of iterator has a defect in code1, code clone detection can detect code2, but cannot detect code3 derived from code1. AOASIA3 2018/11/27

4 crosscutting concern code
Our research goal To detect all instances of an idiom, we are planning to combine three approaches: Pattern Mining: sequential patterns Idiom-based Code Our research goal is to detect all instances of an idiom. We are planning to combine three approaches : Pattern mining, Code clone detection and aspect mining. These approaches are similar to one another because all of them detects code fragments that spread across the whole system. Now we are investigating sequential patterns. Aspect Mining: crosscutting concern code Code Clone Detection: copy-and-pasted code AOASIA3 2018/11/27

5 Sequential Pattern Mining
sequence database Sequential pattern mining extracts frequent subsequences from a sequence database. We apply prefixspan to a sequence database extracted from Java software. A B C D E A E B C A E D F B C A D B F C I explain about our detection technique used in the preliminary case study. Sequential pattern mining is a mining method which extracts frequent subsequences from a sequence database. For example, this sequence database includes four sequences. There are subsequences “ABC” in three sequences ,subsequences “EBC” in two sequences and subsequences “DFC” in two sequences. We applied sequential pattern mining to the sequence database extracted from java software. Sequential pattern A B C ×3 E B C ×2 D F C ×2 AOASIA3 2018/11/27

6 Sequence Database Extraction from Java Software
Sequence element of java source code Method call element IF/ELSE/END-IF element LOOP/END-LOOP element A sequence is extracted from a java method void sample () { hoge (); i = a.foo(); if( i == 0 ) { k = i; a.bar(); } Sequence Sample.hoge() A.foo() IF A.bar() END-IF Here, I explain how to extract sequence database from java software. Sequence elements of java source code are Method call, IF/ELSE/END-IF, LOOP and END-LOOP elements. A sequences is extracted from a java method. This figure is an example of extracting sequence from java source code. Element of Sequence AOASIA3 2018/11/27

7 Preliminary Case Study
We applied sequential pattern mining to Java source code to detect idiom-based code. The target software is JHotDraw We inspected whether the instances of a pattern contribute to a single concern or not. We applied sequential pattern mining to Java source code to detect idiom-based code as preliminary case study. The target software is JHotDraw. We inspected whether the instances of a pattern contribute to a single concern or not. AOASIA3 2018/11/27

8 Application Specific Patterns
org.jhotdraw.standard. DuplicateCommand public void execute() {   super.execute();   setUndoActivity(createUndoActivity());   FigureSelection selection = view().getFigureSele・・・   // create duplicate figure(s)   FigureEnumeration figures = (FigureEnumeration) ・・   getUndoActivity().setAffectedFigures(figures);   view().clearSelection();   ・・・・・・・・・・・・・・・・・・・・・・・・・・・・・ } setUndoActivity() createUndoActivity() getUndoActivityI() setAffectedFigures() Example of an idiom for undo Extracted from many classes, the pattern might be related to a crosscutting concern This is an example of application specific patterns. This pattern is related to undo concern of Jhotdraw. If a pattern is extracted from a number of classes, the pattern might be related to a crosscutting concern. org.jhotdraw. standard.ResizeHandle public void invokeStart(int x, int y, DrawingView view) {   setUndoActivity(createUndoActivity(view));   getUndoActivity().setAffectedFigures(new Sing ・・   ((ResizeHandle.UndoActivity)getUndoActivity()).se・・ } AOASIA3 2018/11/27

9 Patterns of Implementation Idioms
org.jhotdraw.standard.StandardDrawingView public void addAll(Collection figures) {   FigureEnumeration fe = new FigureEnumerato・・・   while (fe.hasNextFigure()) {    add(fe.nextFigure());   } }    Sequential Pattern ( Iteration ) FigureEnumeration.hasNextFigure() while FigureEnumeration.nextFigure() } org.jhotdraw.standard.CompositeFigure public FigureEnumeration figures(Rectangle ・・・   if (_theQuadTree != null) {    ・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・     while (fe.hasNextFigure()) {       Figure f = fe.nextFigure();       //int z = fFigures.indexOf(f);       l2.add(new OrderedFigureElement(f, ・・     }     ・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・ } This is an example of an implementation idioms. This pattern is related to iteration, but it is not an application specific pattern. In Aspect Mining Research, this kind of patterns are not interested, but useful for developers inspecting idioms. Not application specific pattern In aspect mining, this kind of pattern is not interested. Maybe useful for developers inspecting idiom AOASIA3 2018/11/27

10 The Difference from Code Clone Detection Tool
The patterns extracted by Sequential pattern mining tool org.jhotdraw.standard.CutCommand public void execute() {   super.execute();   setUndoActivity(createUndoActivity());   FigureEnumeration fe = view().selection();   List affected = CollectionsFactory.current().createL・・・   Figure f;   FigureEnumeration dfe;   while (fe.hasNextFigure()) {     f = fe.nextFigure();     affected.add(0, f);     dfe = f.getDependendFigures();     ・・・・・・・・・・・・・・・・・・・・・   }   fe = new FigureEnumerator(affected);   getUndoActivity().setAffectedFigures(fe);   UndoActivity ua = (UndoActivity) getUndoActivity();   ua.setSelectedFigures(view().selection());   copyFigures(ua.getSelectedFigures(), ua.getSele・・・・   deleteFigures(getUndoActivity().getAffectedFigures());   view().checkDamage(); } The code extracted by code clone detection tool org.jhotdraw.fiures.GroupCommand public void execute() {   super.execute();   setUndoActivity(createUndoActivity());   getUndoActivity().setAffectedFigures(view().selection());   ((GroupCommand.UndoActivity)getUndoActivity()).group・・・   view().checkDamage(); } Here, I show the difference between code clone detention and sequential pattern mining. These method use the same pattern highlighted by red color. Code clone detection tool can detect code clone in the right two source code . However, it cannot detect the left one. Our detection technique can detect all these source code. org.jhotdraw.standard.AlignCommand public void execute() {   super.execute();   setUndoActivity(createUndoActivity());   getUndoActivity().setAffectedFigures(view().selection());   ((AlignCommand.UndoActivity)getUndoActivity()).alignA・・・   view().checkDamage(); } AOASIA3 2018/11/27

11 Summary Sequential pattern mining found idiom-based code
Crosscutting concern Implementation Idiom Not application-specific patterns Useful information for software maintenance Combining with code clone detection is valuable The result of sequential pattern mining is different from the result of code clone detection We need further case studies on other software systems Preliminary case study shows sequential pattern mining found idiom-based code. Extracted idiom-based code includes crosscutting concerns and implementation idioms. The patterns related to an implementation idiom is also useful for software maintenance. Combining sequential pattern mining and code clone detection is valuable. Because The result of sequential pattern mining is different from the result of code clone detection. This result is limited on JhotDraw, we need further case studies on other software systems to generalize this result. AOASIA3 2018/11/27

12 Future Direction Combining this approach and code clone analysis
detecting all code fragments derived from an original idiom Support for inspecting idiom-based code crosscutting modules. Aspect mining based on sequential pattern mining Sequential pattern mining capture an idiom that is crosscutting modules and interleaving with other code fragments Distinguishing a crosscutting concern from implementation idioms As future direction we plan combining this approach and code clone analysis to detect all code fragments derived from an original idiom. This enables developers to inspect idiom-based code crosscutting modules. Another research direction is an aspect mining based on sequential pattern mining. Sequential pattern mining can capture an idiom that is crosscutting modules and interleaving with other code fragments. Distinguishing a crosscutting concern from implementation idioms is an interesting issue in this direction. That’s all. Thank you for your attention. AOASIA3 2018/11/27

13 AOASIA3 2018/11/27


Download ppt "Tatsuya Miyake Takashi Ishio Katsuro Inoue"

Similar presentations


Ads by Google