String[] toCopy = null; if (forceOverwrite) { Vector v = new Vector(); for (int i = 0; i < names.length; i++) { if (mapper.mapFileName(names[i]) != null) { v.addElement(names[i]); } } toCopy = new String[v.size()]; v.copyInto(toCopy); } else { SourceFileScanner ds = new SourceFileScanner(this); toCopy = ds.restrict(names, fromDir, toDir, mapper, granularity); } for (int i = 0; i < toCopy.length; i++) { File src = new File(fromDir, toCopy[i]); String[] mappedFiles = mapper.mapFileName(toCopy[i]); if (!enableMultipleMappings) { map.put(src.getAbsolutePath(), new String[] {new File(toDir, mappedFiles[0]).getAbsolutePath()}); } else { // reuse the array created by the mapper for (int k = 0; k < mappedFiles.length; k++) { mappedFiles[k] = new File(toDir, mappedFiles[k]).getAbsolutePath(); } map.put(src.getAbsolutePath(), mappedFiles); } }
HashMap map = new HashMap(); Resource[] toCopy = null; if (forceOverwrite) { Vector v = new Vector(); for (int i = 0; i < fromResources.length; i++) { if (mapper.mapFileName(fromResources[i].getName()) != null) { v.addElement(fromResources[i]); } } toCopy = new Resource[v.size()]; v.copyInto(toCopy); } else { toCopy = ResourceUtils.selectOutOfDateSources(this, fromResources, mapper, new ResourceFactory() { public Resource getResource(String name) { return new FileResource(toDir, name); } }, granularity); } for (int i = 0; i < toCopy.length; i++) { String[] mappedFiles = mapper.mapFileName(toCopy[i].getName()); if (!enableMultipleMappings) { map.put(toCopy[i], new String[] {new File(toDir, mappedFiles[0]).getAbsolutePath()}); } else { // reuse the array created by the mapper for (int k = 0; k < mappedFiles.length; k++) { mappedFiles[k] = new File(toDir, mappedFiles[k]).getAbsolutePath(); } map.put(toCopy[i], mappedFiles); } } return map;
Clone fragments detected by clone detection tool
File path: /apache-ant-1.7.0/src/org/apache/tools/ant/taskdefs/Copy.java File path: /apache-ant-1.7.0/src/org/apache/tools/ant/taskdefs/Copy.java
Method name: void buildMap(File, File, String[], FileNameMapper, Hashtable) Method name: Map buildMap(Resource[], File, FileNameMapper)
Number of AST nodes: 18 Number of AST nodes: 18
1
String
1
HashMap map = new HashMap();
2
[] toCopy = null;
2
        Resource[] toCopy = null;
3
        if (forceOverwrite) {
3
        if (forceOverwrite) {
4
            Vector v = new Vector();
4
            Vector v = new Vector();
5
            for (int i = 0; i < names.length; i++) {
5
            for (int i = 0; i < fromResources.length; i++) {
6
                if (mapper.mapFileName(names[i]) != null) {
6
                if (mapper.mapFileName(fromResources[i].getName()) != null) {
7
                    v.addElement(names[i]);
7
                    v.addElement(fromResources[i]);
8
                }
8
                }
9
            }
9
            }
10
            toCopy = new String[v.size()];
10
            toCopy = new Resource[v.size()];
11
            v.copyInto(toCopy);
11
            v.copyInto(toCopy);
12
        } else {
12
        } else {
13
            SourceFileScanner ds =
13
            toCopy =
14
                ResourceUtils.selectOutOfDateSources(this, fromResources,
15
                                                     mapper,
14
 new SourceFileScanner(this);
16
                                                     new ResourceF
15
            toCopy = ds.restrict(names, fromDir, toDir, mapper,
17
actory() {
18
                           public Resource getResource(String name) {
19
                               return new FileResource(toDir, name);
20
                           }
21
                                                     },
16
 granularity);
22
                                                     granularity);
17
        }
23
        }
18
        for (int i = 0; i < toCopy.length; i++) {
24
        for (int i = 0; i < toCopy.length; i++) {
19
            File src = new File(fromDir, toCopy[i]);
20
            String[] mappedFiles = mapper.mapFileName(toCopy[i]);
25
            String[] mappedFiles = mapper.mapFileName(toCopy[i].getName());
21
            if (!enableMultipleMappings) {
26
            if (!enableMultipleMappings) {
22
                map.put(src.getAbsolutePath(),
27
                map.put(toCopy[i],
23
                        new String[] {new File(toDir, mappedFiles[0]).getAbsolutePath()});
28
                        new String[] {new File(toDir, mappedFiles[0]).getAbsolutePath()});
24
            } else {
29
            } else {
25
                // reuse the array created by the mapper
30
                // reuse the array created by the mapper
26
                for (int k = 0; k < mappedFiles.length; k++) {
31
                for (int k = 0; k < mappedFiles.length; k++) {
27
                    mappedFiles[k] = new File(toDir, mappedFiles[k]).getAbsolutePath();
32
                    mappedFiles[k] = new File(toDir, mappedFiles[k]).getAbsolutePath();
28
                }
33
                }
29
                map.put(src.getAbsolutePath(), mappedFiles);
34
                map.put(toCopy[i], mappedFiles);
30
            }
35
            }
31
        }
36
        }
37
        return map;
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)1.7
Clones locationClones are declared in the same class
Number of node comparisons66
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements11
    Number of unmapped statements in the first code fragment7
    Number of unmapped statements in the second code fragment7
    Time elapsed for statement mapping (ms)13.7
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
                                                              
    1
    HashMap map = new HashMap();
    1
    String[] toCopy = null;
                                                    
                                                        
    2
    Resource[] toCopy = null;
    2
    if (forceOverwrite)
    3
    if (forceOverwrite)
    3
    Vector v = new Vector();
    4
    Vector v = new Vector();
    4
    for (int i = 0; i < names.length; i++)
    4
    for (int i = 0; i < names.length; i++)
    5
    for (int i = 0; i < fromResources.length; i++)
    Differences
    Expression1Expression2Difference
    namesfromResourcesVARIABLE_NAME_MISMATCH
    java.lang.String[]org.apache.tools.ant.types.Resource[]VARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.lang.String[] of variable names does not match with type org.apache.tools.ant.types.Resource[] of variable fromResources
    • Make classes java.lang.String[] and org.apache.tools.ant.types.Resource[] extend a common superclass
    5
    for (int i = 0; i < fromResources.length; i++)
    5
    if (mapper.mapFileName(names[i]) != null)
    5
    if (mapper.mapFileName(names[i]) != null)
    6
    if (mapper.mapFileName(fromResources[i].getName()) != null)
    Differences
    Expression1Expression2Difference
    names[i]fromResources[i].getName()TYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression names[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression fromResources[i].getName() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6
    if (mapper.mapFileName(fromResources[i].getName()) != null)
    6
    v.addElement(names[i]);
    6
    v.addElement(names[i]);
    7
    v.addElement(fromResources[i]);
    Differences
    Expression1Expression2Difference
    namesfromResourcesVARIABLE_NAME_MISMATCH
    java.lang.String[]org.apache.tools.ant.types.Resource[]VARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.lang.String[] of variable names does not match with type org.apache.tools.ant.types.Resource[] of variable fromResources
    • Make classes java.lang.String[] and org.apache.tools.ant.types.Resource[] extend a common superclass
    7
    v.addElement(fromResources[i]);
    7
    toCopy = new String[v.size()];
    7
    toCopy = new String[v.size()];
    Preondition Violations
    Unmatched statement toCopy=new String[v.size()]; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                  
                                                                      
    8
    toCopy = new Resource[v.size()];
    Preondition Violations
    Unmatched statement toCopy=new Resource[v.size()]; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8
    toCopy = new Resource[v.size()];
    8
    v.copyInto(toCopy);
    8
    v.copyInto(toCopy);
    9
    v.copyInto(toCopy);
    Differences
    Expression1Expression2Difference
    java.lang.String[]org.apache.tools.ant.types.Resource[]VARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.lang.String[] of variable toCopy does not match with type org.apache.tools.ant.types.Resource[] of variable toCopy
    • Make classes java.lang.String[] and org.apache.tools.ant.types.Resource[] extend a common superclass
    9
    v.copyInto(toCopy);
    else
            
    9
    SourceFileScanner ds = new SourceFileScanner(this);
                                                                                                            
                                                                                                                                                                                                                                                                                                                                                                                                                            
    10
    toCopy = ResourceUtils.selectOutOfDateSources(this, fromResources, mapper, new ResourceFactory() {...}, granularity);
    10
    toCopy = ds.restrict(names, fromDir, toDir, mapper, granularity);
                                                                                                                                  
    11
    for (int i = 0; i < toCopy.length; i++)
    11
    for (int i = 0; i < toCopy.length; i++)
    11
    for (int i = 0; i < toCopy.length; i++)
    Differences
    Expression1Expression2Difference
    java.lang.String[]org.apache.tools.ant.types.Resource[]VARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.lang.String[] of variable toCopy does not match with type org.apache.tools.ant.types.Resource[] of variable toCopy
    • Make classes java.lang.String[] and org.apache.tools.ant.types.Resource[] extend a common superclass
    11
    for (int i = 0; i < toCopy.length; i++)
    12
    File src = new File(fromDir, toCopy[i]);
    12
    File src = new File(fromDir, toCopy[i]);
    Preondition Violations
    Unmatched statement File src=new File(fromDir,toCopy[i]); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                      
    13
    String[] mappedFiles = mapper.mapFileName(toCopy[i]);
    13
    String[] mappedFiles = mapper.mapFileName(toCopy[i]);
    12
    String[] mappedFiles = mapper.mapFileName(toCopy[i].getName());
    Differences
    Expression1Expression2Difference
    toCopy[i]toCopy[i].getName()TYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression toCopy[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression toCopy[i].getName() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12
    String[] mappedFiles = mapper.mapFileName(toCopy[i].getName());
    14
    if (!enableMultipleMappings)
    13
    if (!enableMultipleMappings)
                                                                                                                                                                                
    14
    map.put(toCopy[i], new String[] {new File(toDir, mappedFiles[0]).getAbsolutePath()});
    Preondition Violations
    Unmatched statement map.put(toCopy[i],new String[]{new File(toDir,mappedFiles[0]).getAbsolutePath()}); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    14
    map.put(toCopy[i], new String[] {new File(toDir, mappedFiles[0]).getAbsolutePath()});
    15
    map.put(src.getAbsolutePath(), new String[] {new File(toDir, mappedFiles[0]).getAbsolutePath()});
    15
    map.put(src.getAbsolutePath(), new String[] {new File(toDir, mappedFiles[0]).getAbsolutePath()});
    Preondition Violations
    Unmatched statement map.put(src.getAbsolutePath(),new String[]{new File(toDir,mappedFiles[0]).getAbsolutePath()}); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                                                                        
    else
    else
    16
    for (int k = 0; k < mappedFiles.length; k++)
    15
    for (int k = 0; k < mappedFiles.length; k++)
    17
    mappedFiles[k] = new File(toDir, mappedFiles[k]).getAbsolutePath();
    16
    mappedFiles[k] = new File(toDir, mappedFiles[k]).getAbsolutePath();
                                                                          
    17
    map.put(toCopy[i], mappedFiles);
    Preondition Violations
    Unmatched statement map.put(toCopy[i],mappedFiles); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    17
    map.put(toCopy[i], mappedFiles);
    18
    map.put(src.getAbsolutePath(), mappedFiles);
    18
    map.put(src.getAbsolutePath(), mappedFiles);
    Preondition Violations
    Unmatched statement map.put(src.getAbsolutePath(),mappedFiles); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                  
                                  
    18
    return map;
    Preondition Violations
    Unmatched return map;
    18
    return map;
    Precondition Violations (17)
    Row Violation
    1Type java.lang.String[] of variable names does not match with type org.apache.tools.ant.types.Resource[] of variable fromResources
    2Expression names[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression fromResources[i].getName() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Type java.lang.String[] of variable names does not match with type org.apache.tools.ant.types.Resource[] of variable fromResources
    5Unmatched statement toCopy=new String[v.size()]; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched statement toCopy=new Resource[v.size()]; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7Type java.lang.String[] of variable toCopy does not match with type org.apache.tools.ant.types.Resource[] of variable toCopy
    8Type java.lang.String[] of variable toCopy does not match with type org.apache.tools.ant.types.Resource[] of variable toCopy
    9Unmatched statement File src=new File(fromDir,toCopy[i]); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    10Expression toCopy[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted
    11Expression toCopy[i].getName() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    12Unmatched statement map.put(toCopy[i],new String[]{new File(toDir,mappedFiles[0]).getAbsolutePath()}); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    13Unmatched statement map.put(src.getAbsolutePath(),new String[]{new File(toDir,mappedFiles[0]).getAbsolutePath()}); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    14Unmatched statement map.put(toCopy[i],mappedFiles); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    15Unmatched statement map.put(src.getAbsolutePath(),mappedFiles); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    16Unmatched return map;
    17Clone fragment #1 returns variables v, i, mappedFiles , while Clone fragment #2 returns variables v, i, mappedFiles