1 / 13

Towards Maintenance Support for Idiom-based Code Using Sequential Pattern Mining

Towards Maintenance Support for Idiom-based Code Using Sequential Pattern Mining. Tatsuya Miyake Takashi Ishio Katsuro Inoue. copy- and- paste. while (iter.hasNext()) { Item item = (Item)iter.next(); buf.append(item.toString()); }. while (iter.hasNext()) {

Download Presentation

Towards Maintenance Support for Idiom-based Code Using Sequential Pattern Mining

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Towards Maintenance Support for Idiom-based Code Using Sequential Pattern Mining Tatsuya Miyake Takashi Ishio Katsuro Inoue

  2. copy- and- paste while (iter.hasNext()) { Item item = (Item)iter.next(); buf.append(item.toString()); } while (iter.hasNext()) { Item item = (Item)iter.next(); buf.append(item.toString()); } code2 code1 reuse the idiom while (iter.hasNext()) { Datadata = (Data)iter.next(); buf.append(process(data)); buf.append(data.toString()); } code3 Code derived from an idiom • An idiom is a code fragment to implement a particular kind of concern. AOASIA3

  3. copy- and- paste while (iter.hasNext()) { Item item = (Item)iter.next(); buf.append(item.toString()); } while (iter.hasNext()) { Item item = (Item)iter.next(); buf.append(item.toString()); } code2 code1 reuse the idiom while (iter.hasNext()) { Datadata = (Data)iter.next(); buf.append(process(data)); buf.append(data.toString()); } code3 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. AOASIA3

  4. Our research goal • To detect all instances of an idiom, we are planning to combine three approaches: Pattern Mining: sequential patterns Idiom-based Code Aspect Mining: crosscutting concern code Code Clone Detection: copy-and-pasted code AOASIA3

  5. A B C ×3 E B C ×2 D F C ×2 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 Sequential pattern AOASIA3

  6. Sample.hoge() A.foo() IF A.bar() END-IF 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 Element of Sequence AOASIA3

  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. AOASIA3

  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();   ・・・・・・・・・・・・・・・・・・・・・・・・・・・・・ } • Example of an idiom for undo • Extracted from many classes, the pattern might be related to a crosscutting concern setUndoActivity() createUndoActivity() getUndoActivityI() setAffectedFigures() 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

  9. Patterns of Implementation Idioms org.jhotdraw.standard.StandardDrawingView public void addAll(Collection figures) { FigureEnumeration fe = new FigureEnumerato・・・ while (fe.hasNextFigure()) { add(fe.nextFigure()); } } • Not application specific pattern • In aspect mining, this kind of pattern is not interested. • Maybe useful for developers inspecting idiom 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, ・・ } ・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・ } AOASIA3

  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(); } org.jhotdraw.standard.AlignCommand public void execute() { super.execute(); setUndoActivity(createUndoActivity()); getUndoActivity().setAffectedFigures(view().selection()); ((AlignCommand.UndoActivity)getUndoActivity()).alignA・・・ view().checkDamage(); } AOASIA3

  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 AOASIA3

  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 AOASIA3

  13. AOASIA3

More Related