Document d = DOMUtils.newDocument(); Element root = d.createElement("root"); DOMUtils.appendCDATAElement(root, "cdataElement", "content"); StringWriter sw = new StringWriter(); DOMElementWriter w = new DOMElementWriter(); w.write(root, sw, 0, " "); assertEquals("<root>" + StringUtils.LINE_SEP + " <cdataElement><![CDATA[content]]></cdataElement>" + StringUtils.LINE_SEP + "</root>" + StringUtils.LINE_SEP, sw.toString());
Document d = DOMUtils.newDocument(); Element root = d.createElement("root"); DOMUtils.createChildElement(root, "emptyElement"); StringWriter sw = new StringWriter(); DOMElementWriter w = new DOMElementWriter(); w.write(root, sw, 0, " "); assertEquals("<root>" + StringUtils.LINE_SEP // + " <emptyElement></emptyElement>" + " <emptyElement />" + StringUtils.LINE_SEP + "</root>" + StringUtils.LINE_SEP, sw.toString());
Clone fragments detected by clone detection tool
File path: /apache-ant-1.7.0/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java File path: /apache-ant-1.7.0/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java
Method name: void testNoAdditionalWhiteSpaceForCDATA() Method name: void testNoAdditionalWhiteSpaceForEmptyElement()
Number of AST nodes: 7 Number of AST nodes: 7
1
Document d = DOMUtils.newDocument();
1
Document d = DOMUtils.newDocument();
2
        Element root = d.createElement("root");
2
        Element root = d.createElement("root");
3
        DOMUtils.appendCDATAElement(root, "cdataElement", "content");
3
        DOMUtils.createChildElement(root, "emptyElement");
4
        StringWriter sw = new StringWriter();
4
        StringWriter sw = new StringWriter();
5
        DOMElementWriter w = new DOMElementWriter();
5
        DOMElementWriter w = new DOMElementWriter();
6
        w.write(root, sw, 0, "  ");
6
        w.write(root, sw, 0, "  ");
7
        assertEquals("<root>" + StringUtils.LINE_SEP
7
        assertEquals("<root>" + StringUtils.LINE_SEP
8
                     + "  <cdataElement><![CDATA[content]]></cdata
8
                     //                     + "  <emptyElement></emptyElement>"
9
Element>"
9
                     + "  <emptyElement />"
10
                     + StringUtils.LINE_SEP
10
                     + StringUtils.LINE_SEP
11
                     + "</root>" + StringUtils.LINE_SEP,
11
                     + "</root>" + StringUtils.LINE_SEP,
12
                     sw.toString());
12
                     sw.toString());
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones locationClones are declared in the same class
Number of node comparisons23
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements6
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)0.0
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    Document d = DOMUtils.newDocument();
    1
    Document d = DOMUtils.newDocument();
    2
    Element root = d.createElement("root");
    2
    Element root = d.createElement("root");
                                                                                                            
    3
    DOMUtils.createChildElement(root, "emptyElement");
    3
    DOMUtils.appendCDATAElement(root, "cdataElement", "content");
    3
    DOMUtils.appendCDATAElement(root, "cdataElement", "content");
    7
    assertEquals("<root>" + StringUtils.LINE_SEP + " <emptyElement />" + StringUtils.LINE_SEP + "</root>" + StringUtils.LINE_SEP, sw.toString());
    Differences
    Expression1Expression2Difference
    appendCDATAElementassertEqualsMETHOD_INVOCATION_NAME_MISMATCH
    DOMUtils.appendCDATAElement(root,"cdataElement","content")assertEquals("" + StringUtils.LINE_SEP + " "+ StringUtils.LINE_SEP+ ""+ StringUtils.LINE_SEP,sw.toString())ARGUMENT_NUMBER_MISMATCH
    DOMUtilsMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression DOMUtils.appendCDATAElement(root,"cdataElement","content") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals("<root>" + StringUtils.LINE_SEP + " <emptyElement />"+ StringUtils.LINE_SEP+ "</root>"+ StringUtils.LINE_SEP,sw.toString()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression DOMUtils.appendCDATAElement(root,"cdataElement","content") is a void method call, and thus it cannot be parameterized
    Expression assertEquals("<root>" + StringUtils.LINE_SEP + " <emptyElement />"+ StringUtils.LINE_SEP+ "</root>"+ StringUtils.LINE_SEP,sw.toString()) is a void method call, and thus it cannot be parameterized
    Expression DOMUtils.appendCDATAElement(root,"cdataElement","content") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression assertEquals("<root>" + StringUtils.LINE_SEP + " <emptyElement />"+ StringUtils.LINE_SEP+ "</root>"+ StringUtils.LINE_SEP,sw.toString()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression DOMUtils.appendCDATAElement(root,"cdataElement","content") is a void method call, and thus it cannot be parameterized
    Expression assertEquals("<root>" + StringUtils.LINE_SEP + " <emptyElement />"+ StringUtils.LINE_SEP+ "</root>"+ StringUtils.LINE_SEP,sw.toString()) is a void method call, and thus it cannot be parameterized
    7
    assertEquals("<root>" + StringUtils.LINE_SEP + "  <emptyElement />" + StringUtils.LINE_SEP + "</root>" + StringUtils.LINE_SEP, sw.toString());
    4
    StringWriter sw = new StringWriter();
    4
    StringWriter sw = new StringWriter();
    5
    DOMElementWriter w = new DOMElementWriter();
    5
    DOMElementWriter w = new DOMElementWriter();
    6
    w.write(root, sw, 0, "  ");
    6
    w.write(root, sw, 0, "  ");
    7
    assertEquals("<root>" + StringUtils.LINE_SEP + "  <cdataElement><![CDATA[content]]></cdataElement>" + StringUtils.LINE_SEP + "</root>" + StringUtils.LINE_SEP, sw.toString());
                                                                                                                                                                                                                                                                                                                                                              
    Precondition Violations (9)
    Row Violation
    1Expression DOMUtils.appendCDATAElement(root,"cdataElement","content") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression assertEquals("<root>" + StringUtils.LINE_SEP + " <emptyElement />"+ StringUtils.LINE_SEP+ "</root>"+ StringUtils.LINE_SEP,sw.toString()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression DOMUtils.appendCDATAElement(root,"cdataElement","content") is a void method call, and thus it cannot be parameterized
    4Expression assertEquals("<root>" + StringUtils.LINE_SEP + " <emptyElement />"+ StringUtils.LINE_SEP+ "</root>"+ StringUtils.LINE_SEP,sw.toString()) is a void method call, and thus it cannot be parameterized
    5Expression DOMUtils.appendCDATAElement(root,"cdataElement","content") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression assertEquals("<root>" + StringUtils.LINE_SEP + " <emptyElement />"+ StringUtils.LINE_SEP+ "</root>"+ StringUtils.LINE_SEP,sw.toString()) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression DOMUtils.appendCDATAElement(root,"cdataElement","content") is a void method call, and thus it cannot be parameterized
    8Expression assertEquals("<root>" + StringUtils.LINE_SEP + " <emptyElement />"+ StringUtils.LINE_SEP+ "</root>"+ StringUtils.LINE_SEP,sw.toString()) is a void method call, and thus it cannot be parameterized
    9Clone fragment #1 returns variable sw with type java.io.StringWriter , while Clone fragment #2 returns variable root with type org.w3c.dom.Element