183-3-7

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));
CustomPieURLGenerator generator = new CustomPieURLGenerator(); PiePlot p1 = new PiePlot(); p1.setURLGenerator(generator); 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)); // check that the URL generator has been cloned assertTrue(p1.getURLGenerator() != p2.getURLGenerator());

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/plot/junit/PiePlotTests.java
Method name: `void testCloning_LegendItemShape()` |  | Method name: `void testCloning_URLGenerator()`
Number of AST nodes: 11 |  | Number of AST nodes: 10

1

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

1

    CustomPieURLGenerator generator = new CustomPieURLGenerator();↵

2

            PiePlot p1 = new PiePlot();↵

2

            PiePlot p1 = new PiePlot();↵

3

            p1.setLegendItemShape(shape);↵

3

            p1.setURLGenerator(generator);↵

4

            PiePlot p2 = null;↵

4

            PiePlot p2 = null;↵

5

            try {↵

5

            try {↵

6

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

6

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

7

            }↵

7

            }↵

8

            catch (CloneNotSupportedException e) {↵

8

            catch (CloneNotSupportedException e) {↵

9

                e.printStackTrace();↵

9

                e.printStackTrace();↵

10

            }↵

10

            }↵

11

            assertTrue(p1 != p2);↵

11

            assertTrue(p1 != p2);↵

12

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

12

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

13

            assertTrue(p1.equals(p2));↵

13

            assertTrue(p1.equals(p2));↵

14

            ↵

14

            ↵

15

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

15

            // ch↵

16

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

16

    eck that the URL generator has been cloned↵

17

            assertFalse(p1.equals(p2));

17

            assertTrue(p1.getURLGenerator() != p2.getURLGenerator());

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 declared in the same class
Number of node comparisons | 65

1. {Non-refactorable}

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

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

   1

       CustomPieURLGenerator generator = new CustomPieURLGenerator();

   1

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

   2

       PiePlot p1 = new PiePlot();

   2

       PiePlot p1 = new PiePlot();

   3 | p1.setURLGenerator(generator);

   Preondition Violations
   Unmatched statement p1.setURLGenerator(generator); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted

   3

       p1.setURLGenerator(generator);

   3

       p1.setLegendItemShape(shape);

   3 | p1.setLegendItemShape(shape);

   Preondition Violations
   Unmatched statement p1.setLegendItemShape(shape); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted

   4

       PiePlot p2 = null;

   4

       PiePlot p2 = null;

   5

       try

   5

       try

   6

       p2 = (PiePlot)p1.clone();

   6

       p2 = (PiePlot)p1.clone();

   7

       assertTrue(p1 != p2);

   7

       assertTrue(p1 != p2);

   8

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

   8

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

   9

       assertTrue(p1.equals(p2));

   9

       assertTrue(p1.equals(p2));

   10

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

   11

       assertFalse(p1.equals(p2));

   11 | assertFalse(p1.equals(p2));
   10 | assertTrue(p1.getURLGenerator() != p2.getURLGenerator());

   Differences
   Expression1 | Expression2 | Difference
   --- | --- | ---
   assertFalse | assertTrue | METHOD_INVOCATION_NAME_MISMATCH
   p1.equals(p2) | p1.getURLGenerator() != p2.getURLGenerator() | TYPE_COMPATIBLE_REPLACEMENT

   Preondition Violations
   Expression assertFalse(p1.equals(p2)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
   Expression assertTrue(p1.getURLGenerator() != p2.getURLGenerator()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
   Expression assertFalse(p1.equals(p2)) is a void method call, and thus it cannot be parameterized
   Expression assertTrue(p1.getURLGenerator() != p2.getURLGenerator()) is a void method call, and thus it cannot be parameterized
   Expression p1.equals(p2) cannot be parameterized, because it has dependencies to/from statements that will be extracted
   Expression p1.getURLGenerator() != p2.getURLGenerator() cannot be parameterized, because it has dependencies to/from statements that will be extracted

   10

       assertTrue(p1.getURLGenerator() != p2.getURLGenerator());

   Precondition Violations (8)
   Row | Violation
   --- | ---
   1 | Unmatched statement p1.setURLGenerator(generator); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
   2 | Unmatched statement p1.setLegendItemShape(shape); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
   3 | Expression assertFalse(p1.equals(p2)) cannot be parameterized, because it has dependencies to/from statements that will be extracted
   4 | Expression assertTrue(p1.getURLGenerator() != p2.getURLGenerator()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
   5 | Expression assertFalse(p1.equals(p2)) is a void method call, and thus it cannot be parameterized
   6 | Expression assertTrue(p1.getURLGenerator() != p2.getURLGenerator()) is a void method call, and thus it cannot be parameterized
   7 | Expression p1.equals(p2) cannot be parameterized, because it has dependencies to/from statements that will be extracted
   8 | Expression p1.getURLGenerator() != p2.getURLGenerator() cannot be parameterized, because it has dependencies to/from statements that will be extracted