String classname = (String) e.nextElement(); dependencies.put(classname, classname); try { File container = getClassContainer(classname); if (container == null) { continue; } containers.put(container, container); ZipFile zipFile = null; InputStream inStream = null; try { if (container.getName().endsWith(".class")) { inStream = new FileInputStream(container.getPath()); } else { zipFile = new ZipFile(container.getPath()); String entryName = classname.replace('.', '/') + ".class"; ZipEntry entry = new ZipEntry(entryName); inStream = zipFile.getInputStream(entry); } ClassFile classFile = new ClassFile(); classFile.read(inStream); Vector dependencyList = classFile.getClassRefs(); Enumeration depEnum = dependencyList.elements(); while (depEnum.hasMoreElements()) { String dependency = (String) depEnum.nextElement(); analyzedDeps.put(dependency, dependency); } } finally { if (inStream != null) { inStream.close(); } if (zipFile != null) { zipFile.close(); } } } catch (IOException ioe) { // ignore }
while (toAnalyze.size() != 0 && count++ < maxCount) { DependencyVisitor dependencyVisitor = new DependencyVisitor(); for (Enumeration e = toAnalyze.keys(); e.hasMoreElements();) { String classname = (String) e.nextElement(); dependencies.put(classname, classname); try { File container = getClassContainer(classname); if (container == null) { continue; } containers.put(container, container); ClassParser parser = null; if (container.getName().endsWith(".class")) { parser = new ClassParser(container.getPath()); } else { parser = new ClassParser(container.getPath(), classname.replace('.', '/') + ".class"); } JavaClass javaClass = parser.parse(); DescendingVisitor traverser = new DescendingVisitor(javaClass, dependencyVisitor); traverser.visit(); } catch (IOException ioe) { // ignore } } toAnalyze.clear(); // now recover all the dependencies collected and add to the list. Enumeration depsEnum = dependencyVisitor.getDependencies(); while (depsEnum.hasMoreElements()) { String className = (String) depsEnum.nextElement(); if (!dependencies.containsKey(className)) { toAnalyze.put(className, className); } } }
Clone fragments detected by clone detection tool
File path: /apache-ant-1.7.0/src/org/apache/tools/ant/taskdefs/optional/depend/AntAnalyzer.java File path: /apache-ant-1.7.0/src/org/apache/tools/ant/util/depend/bcel/FullAnalyzer.java
Method name: void determineDependencies(Vector, Vector) Method name: void determineDependencies(Vector, Vector)
Number of AST nodes: 23 Number of AST nodes: 23
1
while (toAnalyze.size() != 0 && count++ < maxCount) {
2
            DependencyVisitor dependencyVisitor = new DependencyVisitor();
3
            for (Enumeration e = toAnalyze.keys(); e.hasMoreElements();) {
1
String classname = (String) e.nextElement();
4
                String classname = (String) e.nextElement();
2
                dependencies.put(classname, classname);
5
                dependencies.put(classname, classname);
3
                try {
6
                try {
4
                    File container = getClassContainer(classname);
7
                    File container = getClassContainer(classname);
5
                    if (container == null) {
8
                    if (container == null) {
6
                        continue;
9
                        continue;
7
                    }
10
                    }
8
                    containers.put(container, container);
11
                    containers.put(container, container);
9
                    ZipFile zipFile = null;
12
                    
10
                    InputStream inStream = null;
11
                    try {
12
    
13
ClassParser parser = null;
13
                    if (container.getName().endsWith(".class")) {
14
                    if (container.getName().endsWith(".class")) {
14
                            inStream = new FileInputStream(container.getPath());
15
                        parser = new ClassParser(container.getPath());
15
                        } else {
16
                    } else {
16
                            zipFile = new ZipFile(container.getPath());
17
                        
17
                            String entryName
18
  
18
parser = new ClassParser(container.getPath(),
19
                              = classname.replace('.', '/') + ".class";
19
                            classname.replace('.', '/') + ".class");
20
                  
20
                    }
21
          ZipEntry entry = new ZipEntry(entryName);
21
          
22
                            inStream
23
                                = zipFile.getInputStream(entry);
24
                 
22
          JavaClass javaClass = parser.parse();
23
                    DescendingVisitor traverser
24
                         = new DescendingVisitor(javaClass, dependencyVisitor);
25
                    traverser.visit();
26
                } catch (IOException ioe) {
25
       }
27
       
26
                        ClassFile classFile = new ClassFile();
28
             // ignore
29
                }
27
            
30
            }
28
            classFile.read(inStream);
31
            toAnalyze.clear();
29
                        Vector dependencyList = classFile.getClassRefs();
32
            // now recover all the dependenc
30
      
33
ies collected and add to the list.
31
                  Enumeration depEnum = dependencyList.elements();
34
            Enumeration depsEnum = dependencyVis
32
     
35
itor.getDependencies();
33
                   while (depEnum.hasMoreElements()) {
36
            while (depsEnum.hasMoreElements()) {
34
                            String dependency = (String) depEnum.nextElement();
37
                String className = (String) depsEnum.nextElement();
35
                            analyzedDeps.put(dependency, dependency);
38
                
36
                        }
37
                    } finally {
38
                        if (inStream != null) {
39
                            inStream.close();
40
                        }
41
                        if (zipFile != null) {
42
                            zipFile.close();
43
                        }
44
                    }
45
                } catch (IOException ioe) {
46
                    // ignore
47
        
39
if (!dependencies.containsKey(className)) {
40
                    toAnalyze.put(className, className);
41
                }
42
            }
48
        }
43
        }
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.5
Clones locationClones are in different classes having the same super class
Number of node comparisons25
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements1
    Number of unmapped statements in the first code fragment5
    Number of unmapped statements in the second code fragment7
    Time elapsed for statement mapping (ms)2.3
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
                              
    17
    continue;
    Preondition Violations
    Unmatched continue;
    17
    continue;
    23
    if (container.getName().endsWith(".class"))
    20
    if (container.getName().endsWith(".class"))
                                                                                                    
    21
    parser = new ClassParser(container.getPath());
    Preondition Violations
    Unmatched statement parser=new ClassParser(container.getPath()); cannot be moved, because it updates a variable modified in other unmapped statements
    21
    parser = new ClassParser(container.getPath());
    24
    inStream = new FileInputStream(container.getPath());
    24
    inStream = new FileInputStream(container.getPath());
    Preondition Violations
    Unmatched statement inStream=new FileInputStream(container.getPath()); cannot be moved, because it updates a variable modified in other unmapped statements
                                                                                                                
    else
            
                                                                                                                                                                                
    22
    parser = new ClassParser(container.getPath(), classname.replace('.', '/') + ".class");
    Preondition Violations
    Unmatched statement parser=new ClassParser(container.getPath(),classname.replace('.','/') + ".class"); cannot be moved, because it updates a variable modified in other unmapped statements
    22
    parser = new ClassParser(container.getPath(), classname.replace('.', '/') + ".class");
    25
    zipFile = new ZipFile(container.getPath());
                                                                                              
    26
    String entryName = classname.replace('.', '/') + ".class";
                                                                                                                          
    27
    ZipEntry entry = new ZipEntry(entryName);
                                                                                          
    28
    inStream = zipFile.getInputStream(entry);
    28
    inStream = zipFile.getInputStream(entry);
    Preondition Violations
    Unmatched statement inStream=zipFile.getInputStream(entry); cannot be moved, because it updates a variable modified in other unmapped statements
                                                                                          
    Precondition Violations (5)
    Row Violation
    1Unmatched continue;
    2Unmatched statement inStream=new FileInputStream(container.getPath()); cannot be moved, because it updates a variable modified in other unmapped statements
    3Unmatched statement inStream=zipFile.getInputStream(entry); cannot be moved, because it updates a variable modified in other unmapped statements
    4Unmatched statement parser=new ClassParser(container.getPath()); cannot be moved, because it updates a variable modified in other unmapped statements
    5Unmatched statement parser=new ClassParser(container.getPath(),classname.replace('.','/') + ".class"); cannot be moved, because it updates a variable modified in other unmapped statements