/** * Determine the dependencies of the configured root classes. * * @param files a vector to be populated with the files which contain * the dependency classes * @param classes a vector to be populated with the names of the * dependency classes. */ protected void determineDependencies(Vector files, Vector classes) { // we get the root classes and build up a set of // classes upon which they depend Hashtable dependencies = new Hashtable(); Hashtable containers = new Hashtable(); Hashtable toAnalyze = new Hashtable(); for (Enumeration e = getRootClasses(); e.hasMoreElements();) { String classname = (String) e.nextElement(); toAnalyze.put(classname, classname); } int count = 0; int maxCount = isClosureRequired() ? MAX_LOOPS : 1; Hashtable analyzedDeps = null; while (toAnalyze.size() != 0 && count++ < maxCount) { analyzedDeps = new Hashtable(); 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); 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 } } toAnalyze.clear(); // now recover all the dependencies collected and add to the list. Enumeration depsEnum = analyzedDeps.elements(); while (depsEnum.hasMoreElements()) { String className = (String) depsEnum.nextElement(); if (!dependencies.containsKey(className)) { toAnalyze.put(className, className); } } } // pick up the last round of dependencies that were determined Enumeration depsEnum = analyzedDeps.elements(); while (depsEnum.hasMoreElements()) { String className = (String) depsEnum.nextElement(); dependencies.put(className, className); } files.removeAllElements(); for (Enumeration e = containers.keys(); e.hasMoreElements();) { files.addElement((File) e.nextElement()); } classes.removeAllElements(); for (Enumeration e = dependencies.keys(); e.hasMoreElements();) { classes.addElement((String) e.nextElement()); } }
/** * Determine the dependencies of the configured root classes. * * @param files a vector to be populated with the files which contain * the dependency classes * @param classes a vector to be populated with the names of the * depencency classes. */ protected void determineDependencies(Vector files, Vector classes) { // we get the root classes and build up a set of // classes upon which they depend Hashtable dependencies = new Hashtable(); Hashtable containers = new Hashtable(); Hashtable toAnalyze = new Hashtable(); Hashtable nextAnalyze = new Hashtable(); for (Enumeration e = getRootClasses(); e.hasMoreElements();) { String classname = (String) e.nextElement(); toAnalyze.put(classname, classname); } int count = 0; int maxCount = isClosureRequired() ? MAX_LOOPS : 2; while (toAnalyze.size() != 0 && count++ < maxCount) { nextAnalyze.clear(); 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(); String[] interfaces = javaClass.getInterfaceNames(); for (int i = 0; i < interfaces.length; ++i) { String interfaceName = interfaces[i]; if (!dependencies.containsKey(interfaceName)) { nextAnalyze.put(interfaceName, interfaceName); } } if (javaClass.isClass()) { String superClass = javaClass.getSuperclassName(); if (!dependencies.containsKey(superClass)) { nextAnalyze.put(superClass, superClass); } } } catch (IOException ioe) { // ignore } } Hashtable temp = toAnalyze; toAnalyze = nextAnalyze; nextAnalyze = temp; } files.removeAllElements(); for (Enumeration e = containers.keys(); e.hasMoreElements();) { files.addElement((File) e.nextElement()); } classes.removeAllElements(); for (Enumeration e = dependencies.keys(); e.hasMoreElements();) { classes.addElement((String) e.nextElement()); } }
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/AncestorAnalyzer.java
Method name: void determineDependencies(Vector, Vector) Method name: void determineDependencies(Vector, Vector)
Number of AST nodes: 4 Number of AST nodes: 4
1
/**
1
/**
2
     * Determine the dependencies of the configured root classes.
2
     * Determine the dependencies of the configured root classes.
3
     *
3
     *
4
     * @param files a vector to be populated with the files which contain
4
     * @param files a vector to be populated with the files which contain
5
     *      the dependency classes
5
     *      the dependency classes
6
     * @param classes a vector to be populated with the names of the
6
     * @param classes a vector to be populated with the names of the
7
     *      dependency classes.
7
     *      depencency classes.
8
     */
8
     */
9
    protected void determineDependencies(Vector files, Vector classes) {
9
    protected void determineDependencies(Vector files, Vector classes) {
10
        // we get the root classes and build up a set of
10
        // we get the root classes and build up a set of
11
        // classes upon which they depend
11
        // classes upon which they depend
12
        Hashtable dependencies = new Hashtable();
12
        Hashtable dependencies = new Hashtable();
13
        Hashtable containers = new Hashtable();
13
        Hashtable containers = new Hashtable();
14
        Hashtable toAnalyze = new Hashtable();
14
        Hashtable toAnalyze = new Hashtable();
15
        for (Enumeration e = getRootClasses(); e.hasMoreElements();) {
15
        Hashtable nextAnalyze = new Hashtable();
16
            String classname = (String) e.nextElement();
16
        for (Enumeration e = getRootClasses(); e.hasMoreElements();) {
17
            toAnalyze.put(classname, classname);
17
            String classname = (String) e.nextElement();
18
        }
18
            toAnalyze.put(classname, classname);
19
19
        }
20
        int count = 0;
20
21
        int maxCount = isClosureRequired() ? MAX_LOOPS : 1;
21
        int count = 0;
22
        Hashtable analyzedDeps = null;
22
        int maxCount = isClosureRequired() ? MAX_LOOPS : 2;
23
        while (toAnalyze.size() != 0 && count++ < maxCount) {
23
        while (toAnalyze.size() != 0 && count++ < maxCount) {
24
            analyzedDeps = new Hashtable();
24
            nextAnalyze.clear();
25
            for (Enumeration e = toAnalyze.keys(); e.hasMoreElements();) {
25
            for (Enumeration e = toAnalyze.keys(); e.hasMoreElements();) {
26
                String classname = (String) e.nextElement();
26
                String classname = (String) e.nextElement();
27
                dependencies.put(classname, classname);
27
                dependencies.put(classname, classname);
28
                try {
28
                try {
29
                    File container = getClassContainer(classname);
29
                    File container = getClassContainer(classname);
30
                    if (container == null) {
30
                    if (container == null) {
31
                        continue;
31
                        continue;
32
                    }
32
                    }
33
                    containers.put(container, container);
33
                    containers.put(container, container);
34
34
35
                    ZipFile zipFile = null;
35
                    ClassParser parser = null;
36
                    InputStream inStream = null;
36
                    if (container.getName().endsWith(".class")) {
37
                    try {
37
                        parser = new ClassParser(container.getPath());
38
                        if (container.getName().endsWith(".class")) {
38
                    } else {
39
                            inStream = new FileInputStream(container.getPath());
39
                        parser = new ClassParser(container.getPath(),
40
                        } else {
40
                            classname.replace('.', '/') + ".class");
41
                            zipFile = new ZipFile(container.getPath());
41
                    }
42
                            String entryName
42
43
                                = classname.replace('.', '/') + ".class";
43
                    JavaClass javaClass = parser.parse();
44
                            ZipEntry entry = new ZipEntry(entryName);
44
                    String[] interfaces = javaClass.getInterfaceNames();
45
                            inStream
45
                    for (int i = 0; i < interfaces.length; ++i) {
46
                                = zipFile.getInputStream(entry);
46
                        String interfaceName = interfaces[i];
47
                        }
47
                        if (!dependencies.containsKey(interfaceName)) {
48
                        ClassFile classFile = new ClassFile();
48
                            nextAnalyze.put(interfaceName, interfaceName);
49
                        classFile.read(inStream);
49
                        }
50
                        Vector dependencyList = classFile.getClassRefs();
50
                    }
51
                        Enumeration depEnum = dependencyList.elements();
51
52
                        while (depEnum.hasMoreElements()) {
52
                    if (javaClass.isClass()) {
53
                            String dependency = (String) depEnum.nextElement();
53
                        String superClass = javaClass.getSuperclassName();
54
                            analyzedDeps.put(dependency, dependency);
54
                        if (!dependencies.containsKey(superClass)) {
55
                        }
55
                            nextAnalyze.put(superClass, superClass);
56
                    } finally {
56
                        }
57
                        if (inStream != null) {
57
                    }
58
                            inStream.close();
58
                } catch (IOException ioe) {
59
                        }
59
                    // ignore
60
                        if (zipFile != null) {
60
                }
61
                            zipFile.close();
61
            }
62
                        }
62
63
                    }
63
            Hashtable temp = toAnalyze;
64
                } catch (IOException ioe) {
64
            toAnalyze = nextAnalyze;
65
                    // ignore
65
            nextAnalyze = temp;
66
                }
66
        }
67
            }
67
68
68
        files.removeAllElements();
69
            toAnalyze.clear();
69
        for (Enumeration e = containers.keys(); e.hasMoreElements();) {
70
70
            files.addElement((File) e.nextElement());
71
            // now recover all the dependencies collected and add to the list.
71
        }
72
            Enumeration depsEnum = analyzedDeps.elements();
72
73
            while (depsEnum.hasMoreElements()) {
73
        classes.removeAllElements();
74
                String className = (String) depsEnum.nextElement();
74
        for (Enumeration e = dependencies.keys(); e.hasMoreElements();) {
75
                if (!dependencies.containsKey(className)) {
75
            classes.addElement((String) e.nextElement());
76
                    toAnalyze.put(className, className);
76
        }
77
                }
77
    }
78
            }
79
        }
80
81
        // pick up the last round of dependencies that were determined
82
        Enumeration depsEnum = analyzedDeps.elements();
83
        while (depsEnum.hasMoreElements()) {
84
            String className = (String) depsEnum.nextElement();
85
            dependencies.put(className, className);
86
        }
87
88
        files.removeAllElements();
89
        for (Enumeration e = containers.keys(); e.hasMoreElements();) {
90
            files.addElement((File) e.nextElement());
91
        }
92
93
        classes.removeAllElements();
94
        for (Enumeration e = dependencies.keys(); e.hasMoreElements();) {
95
            classes.addElement((String) e.nextElement());
96
        }
97
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements7
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)0.0
    Similarity Score0.800
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    38
    while (depsEnum.hasMoreElements())
    38
    while (depsEnum.hasMoreElements())
    26
    for (int i = 0; i < interfaces.length; ++i)
    Differences
    Expression1Expression2Difference
    depsEnum.hasMoreElements()i < interfaces.lengthTYPE_COMPATIBLE_REPLACEMENT
    java.util.Hashtablejava.lang.String[]VARIABLE_TYPE_MISMATCH
    java.util.Hashtablejava.lang.String[]VARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.util.Hashtable of variable analyzedDeps does not match with type java.lang.String[] of variable interfaces
    • Make classes java.util.Hashtable and java.lang.String[] extend a common superclass
    Type java.util.Hashtable of variable analyzedDeps does not match with type java.lang.String[] of variable interfaces
    • Make classes java.util.Hashtable and java.lang.String[] extend a common superclass
    26
    for (int i = 0; i < interfaces.length; ++i)
    39
    String className = (String)depsEnum.nextElement();
    39
    String className = (String)depsEnum.nextElement();
    27
    String interfaceName = interfaces[i];
    Differences
    Expression1Expression2Difference
    classNameinterfaceNameVARIABLE_NAME_MISMATCH
    (String)depsEnum.nextElement()interfaces[i]TYPE_COMPATIBLE_REPLACEMENT
    27
    String interfaceName = interfaces[i];
    40
    if (!dependencies.containsKey(className))
    40
    if (!dependencies.containsKey(className))
    28
    if (!dependencies.containsKey(interfaceName))
    Differences
    Expression1Expression2Difference
    classNameinterfaceNameVARIABLE_NAME_MISMATCH
    28
    if (!dependencies.containsKey(interfaceName))
    41
    toAnalyze.put(className, className);
    41
    toAnalyze.put(className, className);
    29
    nextAnalyze.put(interfaceName, interfaceName);
    Differences
    Expression1Expression2Difference
    classNameinterfaceNameVARIABLE_NAME_MISMATCH
    classNameinterfaceNameVARIABLE_NAME_MISMATCH
    toAnalyzenextAnalyzeVARIABLE_NAME_MISMATCH
    29
    nextAnalyze.put(interfaceName, interfaceName);
    Precondition Violations (2)
    Row Violation
    1Type java.util.Hashtable of variable analyzedDeps does not match with type java.lang.String[] of variable interfaces
    2Type java.util.Hashtable of variable analyzedDeps does not match with type java.lang.String[] of variable interfaces