183-3-11

Rectangle shape = new Rectangle(-4, -4, 8, 8); PiePlot p1 = new PiePlot(); p1.setLegendItemShape(shape); PiePlot p2 = null; try { p2 = (PiePlot) p1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(p1 != p2); assertTrue(p1.getClass() == p2.getClass()); assertTrue(p1.equals(p2)); // change the shape and make sure it only affects p1 shape.setRect(1.0, 2.0, 3.0, 4.0); assertFalse(p1.equals(p2));
StandardXYSeriesLabelGenerator generator = new StandardXYSeriesLabelGenerator("Series {0}"); XYBarRenderer r1 = new XYBarRenderer(); r1.setLegendItemLabelGenerator(generator); XYBarRenderer r2 = null; try { r2 = (XYBarRenderer) r1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(r1 != r2); assertTrue(r1.getClass() == r2.getClass()); assertTrue(r1.equals(r2)); // check that the generator has been cloned assertTrue(r1.getLegendItemLabelGenerator() != r2.getLegendItemLabelGenerator());

Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/tests/org/jfree/chart/plot/junit/PiePlotTests.java |  | File path: /jfreechart-1.0.10/tests/org/jfree/chart/renderer/xy/junit/AbstractXYItemRendererTests.java
Method name: `void testCloning_LegendItemShape()` |  | Method name: `void testCloning_LegendItemLabelGenerator()`
Number of AST nodes: 11 |  | Number of AST nodes: 10

1

    Rectangle shape = new Rectangle(-4, -4, 8, 8);↵

2

            PiePlot p1 = new PiePlot↵

1

    StandardXYSeriesLabelGenerator generator ↵

2

                    = new StandardXYSeriesLabelGenerator("Series {0}");↵

3

    ();↵

3

            XYBarRenderer r1 = new XYBarRenderer();↵

4

            p1.setLegendItemShape(shape);↵

4

            r1.setLegendItem↵

5

            PiePlot p↵

5

    LabelGenerator(generator);↵

6

    2 = null;↵

6

            XYBarRenderer r2 = null;↵

7

            try {↵

7

            try {↵

8

                p2 = (PiePlot) p1.clone();↵

8

                r2 = (XYBarRenderer) r1.clone();↵

9

            }↵

9

            }↵

10

            catch (CloneNotSupportedException e) {↵

10

            catch (CloneNotSupportedException e) {↵

11

                e.printStackTrace();↵

11

                e.printStackTrace();↵

12

            }↵

12

            }↵

13

            assertTrue(p1 != p2);↵

13

            assertTrue(r1 != r2);↵

14

            assertTrue(p1.getClass() == p2.getClass());↵

14

            assertTrue(r1.getClass() == r2.getClass());↵

15

            assertTrue(p1.equals(p2));↵

15

            assertTrue(r1.equals(r2));↵

16

            ↵

16

            ↵

17

            // change the shape and make sure it only affects p1↵

17

            // check that the generator has been cloned↵

18

            shape.setRect(1.0, 2.0, 3.0, 4.0);↵

18

            ↵

19

            assertFalse(p1.equals(p2↵

19

    assertTrue(r1.getLegendItemLabelGenerator() ↵

20

    ));

20

                    != r2.getLegendItemLabelGenerator());

See real code fragment |  | See real code fragment

Summary
Number of common nesting structure subtrees | 1
Number of refactorable cases | 0
Number of non-refactorable cases | 1
Time elapsed for finding largest common nesting structure subtrees (ms) | 0.1
Clones location | Clones are in different classes having the same super class
Number of node comparisons | 76

1. {Non-refactorable}

   Mapping Summary
   Number of mapped statements | 5
   Number of unmapped statements in the first code fragment | 6
   Number of unmapped statements in the second code fragment | 5
   Time elapsed for statement mapping (ms) | 5.2
   Clone type | Type 3

   Mapped Statements
   ID | Statement |  | ID | Statement
   --- | --- | --- | --- | ---

   1

       StandardXYSeriesLabelGenerator generator = new StandardXYSeriesLabelGenerator("Series {0}");

   1

       Rectangle shape = new Rectangle(-4, -4, 8, 8);

   2

       XYBarRenderer r1 = new XYBarRenderer();

   2

       PiePlot p1 = new PiePlot();

   3

       r1.setLegendItemLabelGenerator(generator);

   3

       p1.setLegendItemShape(shape);

   4

       XYBarRenderer r2 = null;

   4

       PiePlot p2 = null;

   5

       try

   5

       try

   6 | r2 = (XYBarRenderer)r1.clone();

   Preondition Violations
   Unmatched statement r2=(XYBarRenderer)r1.clone(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted

   6

       r2 = (XYBarRenderer)r1.clone();

   6

       p2 = (PiePlot)p1.clone();

   6 | p2 = (PiePlot)p1.clone();

   Preondition Violations
   Unmatched statement p2=(PiePlot)p1.clone(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted

   7

       assertTrue(p1 != p2);

   8

       assertTrue(p1.getClass() == p2.getClass());

   8 | assertTrue(p1.getClass() == p2.getClass());
   9 | assertTrue(r1.equals(r2));

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   p1.getClass() == p2.getClass() | r1.equals(r2) | TYPE_COMPATIBLE_REPLACEMENT

   9

       assertTrue(r1.equals(r2));

   9

       assertTrue(p1.equals(p2));

   9 | assertTrue(p1.equals(p2));
   7 | assertTrue(r1 != r2);

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   p1.equals(p2) | r1 != r2 | TYPE_COMPATIBLE_REPLACEMENT

   7

       assertTrue(r1 != r2);

   10

       shape.setRect(1.0, 2.0, 3.0, 4.0);

   10 | shape.setRect(1.0, 2.0, 3.0, 4.0);
   10 | assertTrue(r1.getLegendItemLabelGenerator() != r2.getLegendItemLabelGenerator());

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   setRect | assertTrue | METHOD_INVOCATION_NAME_MISMATCH
   shape.setRect(1.0,2.0,3.0,4.0) | assertTrue(r1.getLegendItemLabelGenerator() != r2.getLegendItemLabelGenerator()) | ARGUMENT_NUMBER_MISMATCH
   shape |  | MISSING_METHOD_INVOCATION_EXPRESSION

   Preondition Violations
   Expression shape.setRect(1.0,2.0,3.0,4.0) is a void method call, and thus it cannot be parameterized
   Expression assertTrue(r1.getLegendItemLabelGenerator() != r2.getLegendItemLabelGenerator()) is a void method call, and thus it cannot be parameterized
   Expression shape.setRect(1.0,2.0,3.0,4.0) is a void method call, and thus it cannot be parameterized
   Expression assertTrue(r1.getLegendItemLabelGenerator() != r2.getLegendItemLabelGenerator()) is a void method call, and thus it cannot be parameterized

   10

       assertTrue(r1.getLegendItemLabelGenerator() != r2.getLegendItemLabelGenerator());

   11

       assertFalse(p1.equals(p2));

   11 | assertFalse(p1.equals(p2));
   8 | assertTrue(r1.getClass() == r2.getClass());

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   assertFalse | assertTrue | METHOD_INVOCATION_NAME_MISMATCH
   p1.equals(p2) | r1.getClass() == r2.getClass() | TYPE_COMPATIBLE_REPLACEMENT

   Preondition Violations
   Expression assertFalse(p1.equals(p2)) is a void method call, and thus it cannot be parameterized
   Expression assertTrue(r1.getClass() == r2.getClass()) is a void method call, and thus it cannot be parameterized

   8

       assertTrue(r1.getClass() == r2.getClass());

   Precondition Violations (8)
   Row | Violation
   --- | ---
   1 | Unmatched statement r2=(XYBarRenderer)r1.clone(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
   2 | Unmatched statement p2=(PiePlot)p1.clone(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
   3 | Expression shape.setRect(1.0,2.0,3.0,4.0) is a void method call, and thus it cannot be parameterized
   4 | Expression assertTrue(r1.getLegendItemLabelGenerator() != r2.getLegendItemLabelGenerator()) is a void method call, and thus it cannot be parameterized
   5 | Expression shape.setRect(1.0,2.0,3.0,4.0) is a void method call, and thus it cannot be parameterized
   6 | Expression assertTrue(r1.getLegendItemLabelGenerator() != r2.getLegendItemLabelGenerator()) is a void method call, and thus it cannot be parameterized
   7 | Expression assertFalse(p1.equals(p2)) is a void method call, and thus it cannot be parameterized
   8 | Expression assertTrue(r1.getClass() == r2.getClass()) is a void method call, and thus it cannot be parameterized