/** * Return the DirectoryScanner associated with this FileSet. * * @param p the project used to resolve dirs, etc. * * @return a dependency scanner. */ public DirectoryScanner getDirectoryScanner(Project p) { if (isReference()) { return getRef(p).getDirectoryScanner(p); } Vector allRootClasses = (Vector) rootClasses.clone(); for (Enumeration e = rootFileSets.elements(); e.hasMoreElements();) { FileSet additionalRootSet = (FileSet) e.nextElement(); DirectoryScanner additionalScanner = additionalRootSet.getDirectoryScanner(p); String[] files = additionalScanner.getIncludedFiles(); for (int i = 0; i < files.length; ++i) { if (files[i].endsWith(".class")) { String classFilePath = files[i].substring(0, files[i].length() - 6); String className = classFilePath.replace('/', '.').replace('\\', '.'); allRootClasses.addElement(className); } } } DirectoryScanner parentScanner = super.getDirectoryScanner(p); DependScanner scanner = new DependScanner(parentScanner); scanner.setBasedir(getDir(p)); scanner.setRootClasses(allRootClasses); scanner.scan(); return scanner; }
/** * Add all available classes, that depend on Remote, Home, Bean, PK * @param checkEntries files, that are extracted from the deployment descriptor * @throws BuildException if there is a problem. */ protected void checkAndAddDependants(Hashtable checkEntries) throws BuildException { if (dependencyAnalyzer == null) { return; } dependencyAnalyzer.reset(); Iterator i = checkEntries.keySet().iterator(); while (i.hasNext()) { String entryName = (String) i.next(); if (entryName.endsWith(".class")) { String className = entryName.substring(0, entryName.length() - ".class".length()); className = className.replace(File.separatorChar, '/'); className = className.replace('/', '.'); dependencyAnalyzer.addRootClass(className); } } Enumeration e = dependencyAnalyzer.getClassDependencies(); while (e.hasMoreElements()) { String classname = (String) e.nextElement(); String location = classname.replace('.', File.separatorChar) + ".class"; File classFile = new File(config.srcDir, location); if (classFile.exists()) { checkEntries.put(location, classFile); log("dependent class: " + classname + " - " + classFile, Project.MSG_VERBOSE); } } }
Clone fragments detected by clone detection tool
File path: /apache-ant-1.7.0/src/org/apache/tools/ant/types/optional/depend/ClassfileSet.java File path: /apache-ant-1.7.0/src/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java
Method name: DirectoryScanner getDirectoryScanner(Project) Method name: void checkAndAddDependants(Hashtable)
Number of AST nodes: 5 Number of AST nodes: 7
1
/**
1
/**
2
     * Return the DirectoryScanner associated with this FileSet.
2
     * Add all available classes, that depend on Remote, Home, Bean, PK
3
     *
3
     * @param checkEntries files, that are extracted from the deployment descriptor
4
     * @param p the project used to resolve dirs, etc.
4
     * @throws BuildException if there is a problem.
5
     *
5
     */
6
     * @return a dependency scanner.
6
    protected void checkAndAddDependants(Hashtable checkEntries)
7
     */
7
        throws BuildException {
8
    public DirectoryScanner getDirectoryScanner(Project p) {
8
9
        if (isReference()) {
9
        if (dependencyAnalyzer == null) {
10
            return getRef(p).getDirectoryScanner(p);
10
            return;
11
        }
11
        }
12
        Vector allRootClasses = (Vector) rootClasses.clone();
12
13
        for (Enumeration e = rootFileSets.elements(); e.hasMoreElements();) {
13
        dependencyAnalyzer.reset();
14
            FileSet additionalRootSet = (FileSet) e.nextElement();
14
15
            DirectoryScanner additionalScanner
15
        Iterator i = checkEntries.keySet().iterator();
16
                = additionalRootSet.getDirectoryScanner(p);
16
        while (i.hasNext()) {
17
            String[] files = additionalScanner.getIncludedFiles();
17
            String entryName = (String) i.next();
18
            for (int i = 0; i < files.length; ++i) {
18
            if (entryName.endsWith(".class")) {
19
                if (files[i].endsWith(".class")) {
19
                String className = entryName.substring(0,
20
                    String classFilePath
20
                    entryName.length() - ".class".length());
21
                        = files[i].substring(0, files[i].length() - 6);
21
                className = className.replace(File.separatorChar, '/');
22
                    String className
22
                className = className.replace('/', '.');
23
                        = classFilePath.replace('/', '.').replace('\\', '.');
23
24
                    allRootClasses.addElement(className);
24
                dependencyAnalyzer.addRootClass(className);
25
                }
25
            }
26
            }
26
        }
27
        }
27
28
        DirectoryScanner parentScanner = super.getDirectoryScanner(p);
28
        Enumeration e = dependencyAnalyzer.getClassDependencies();
29
        DependScanner scanner = new DependScanner(parentScanner);
29
30
        scanner.setBasedir(getDir(p));
30
        while (e.hasMoreElements()) {
31
        scanner.setRootClasses(allRootClasses);
31
            String classname = (String) e.nextElement();
32
        scanner.scan();
32
            String location
33
        return scanner;
33
                = classname.replace('.', File.separatorChar) + ".class";
34
    }
34
            File classFile = new File(config.srcDir, location);
35
            if (classFile.exists()) {
36
                checkEntries.put(location, classFile);
37
                log("dependent class: " + classname + " - " + classFile,
38
                    Project.MSG_VERBOSE);
39
            }
40
        }
41
    }
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements5
    Number of unmapped statements in the first code fragment2
    Number of unmapped statements in the second code fragment3
    Time elapsed for statement mapping (ms)0.0
    Similarity Score0.583
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    8
    for (int i = 0; i < files.length; ++i)
    8
    for (int i = 0; i < files.length; ++i)
    5
    while (i.hasNext())
    Differences
    Expression1Expression2Difference
    i < files.lengthi.hasNext()TYPE_COMPATIBLE_REPLACEMENT
    java.lang.String[]java.util.SetVARIABLE_TYPE_MISMATCH
    java.lang.String[]java.util.SetVARIABLE_TYPE_MISMATCH
    java.lang.String[]java.util.SetVARIABLE_TYPE_MISMATCH
    java.lang.String[]java.util.SetVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type java.lang.String[] of variable files does not match with type java.util.Set of variable checkEntries.keySet()
    • Make classes java.lang.String[] and java.util.Set extend a common superclass
    Type java.lang.String[] of variable files does not match with type java.util.Set of variable checkEntries.keySet()
    • Make classes java.lang.String[] and java.util.Set extend a common superclass
    Type java.lang.String[] of variable files does not match with type java.util.Set of variable checkEntries.keySet()
    • Make classes java.lang.String[] and java.util.Set extend a common superclass
    Type java.lang.String[] of variable files does not match with type java.util.Set of variable checkEntries.keySet()
    • Make classes java.lang.String[] and java.util.Set extend a common superclass
    5
    while (i.hasNext())
                                                                              
    6
    String entryName = (String)i.next();
    9
    if (files[i].endsWith(".class"))
    9
    if (files[i].endsWith(".class"))
    7
    if (entryName.endsWith(".class"))
    Differences
    Expression1Expression2Difference
    files[i]entryNameTYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression files[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7
    if (entryName.endsWith(".class"))
    10
    String classFilePath = files[i].substring(0, files[i].length() - 6);
    10
    String classFilePath = files[i].substring(0, files[i].length() - 6);
    8
    String className = entryName.substring(0, entryName.length() - ".class".length());
    Differences
    Expression1Expression2Difference
    classFilePathclassNameVARIABLE_NAME_MISMATCH
    files[i]entryNameTYPE_COMPATIBLE_REPLACEMENT
    6".class".length()TYPE_COMPATIBLE_REPLACEMENT
    files[i]entryNameTYPE_COMPATIBLE_REPLACEMENT
    Preondition Violations
    Expression files[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression files[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8
    String className = entryName.substring(0, entryName.length() - ".class".length());
                                                                                                                  
    9
    className = className.replace(File.separatorChar, '/');
                                                                                      
    10
    className = className.replace('/', '.');
                                                                                                  
    11
    dependencyAnalyzer.addRootClass(className);
    11
    String className = classFilePath.replace('/', '.').replace('\\', '.');
    11
    String className = classFilePath.replace('/', '.').replace('\\', '.');
    Preondition Violations
    Unmatched statement String className=classFilePath.replace('/','.').replace('\\','.'); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                
    12
    allRootClasses.addElement(className);
                                                                                      
    Precondition Violations (8)
    Row Violation
    1Type java.lang.String[] of variable files does not match with type java.util.Set of variable checkEntries.keySet()
    2Type java.lang.String[] of variable files does not match with type java.util.Set of variable checkEntries.keySet()
    3Type java.lang.String[] of variable files does not match with type java.util.Set of variable checkEntries.keySet()
    4Type java.lang.String[] of variable files does not match with type java.util.Set of variable checkEntries.keySet()
    5Expression files[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted
    6Expression files[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted
    7Expression files[i] cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Unmatched statement String className=classFilePath.replace('/','.').replace('\\','.'); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted