private String createOutputFileName(File destFile, String optionalOutputFile, boolean plain) { String suffix = DEFAULT_SUFFIX_HTML; String javaccFile = destFile.getAbsolutePath().replace('\\', '/'); if (plain) { suffix = DEFAULT_SUFFIX_TEXT; } if ((optionalOutputFile == null) || optionalOutputFile.equals("")) { int filePos = javaccFile.lastIndexOf("/"); if (filePos >= 0) { javaccFile = javaccFile.substring(filePos + 1); } int suffixPos = javaccFile.lastIndexOf('.'); if (suffixPos == -1) { optionalOutputFile = javaccFile + suffix; } else { String currentSuffix = javaccFile.substring(suffixPos); if (currentSuffix.equals(suffix)) { optionalOutputFile = javaccFile + suffix; } else { optionalOutputFile = javaccFile.substring(0, suffixPos) + suffix; } } } else { optionalOutputFile = optionalOutputFile.replace('\\', '/'); } return (getProject().getBaseDir() + "/" + optionalOutputFile) .replace('\\', '/'); }
/** * Dissect the specified absolute path. * @param path the path to dissect. * @return String[] {root, remaining path}. * @throws java.lang.NullPointerException if path is null. * @since Ant 1.7 */ public String[] dissect(String path) { char sep = File.separatorChar; path = path.replace('/', sep).replace('\\', sep); // make sure we are dealing with an absolute path if (!isAbsolutePath(path)) { throw new BuildException(path + " is not an absolute path"); } String root = null; int colon = path.indexOf(':'); if (colon > 0 && (onDos || onNetWare)) { int next = colon + 1; root = path.substring(0, next); char[] ca = path.toCharArray(); root += sep; //remove the initial separator; the root has it. next = (ca[next] == sep) ? next + 1 : next; StringBuffer sbPath = new StringBuffer(); // Eliminate consecutive slashes after the drive spec: for (int i = next; i < ca.length; i++) { if (ca[i] != sep || ca[i - 1] != sep) { sbPath.append(ca[i]); } } path = sbPath.toString(); } else if (path.length() > 1 && path.charAt(1) == sep) { // UNC drive int nextsep = path.indexOf(sep, 2); nextsep = path.indexOf(sep, nextsep + 1); root = (nextsep > 2) ? path.substring(0, nextsep + 1) : path; path = path.substring(root.length()); } else { root = File.separator; path = path.substring(1); } return new String[] {root, path}; }
Clone fragments detected by clone detection tool
File path: /apache-ant-1.7.0/src/org/apache/tools/ant/taskdefs/optional/javacc/JJDoc.java File path: /apache-ant-1.7.0/src/org/apache/tools/ant/util/FileUtils.java
Method name: String createOutputFileName(File, String, boolean) Method name: String[] dissect(String)
Number of AST nodes: 3 Number of AST nodes: 1
1
private String createOutputFileName(File destFile, String optionalOutputFile,
1
/**
2
                                        boolean plain) {
2
     * Dissect the specified absolute path.
3
        String suffix = DEFAULT_SUFFIX_HTML;
3
     * @param path the path to dissect.
4
        String javaccFile = destFile.getAbsolutePath().replace('\\', '/');
4
     * @return String[] {root, remaining path}.
5
5
     * @throws java.lang.NullPointerException if path is null.
6
        if (plain) {
6
     * @since Ant 1.7
7
            suffix = DEFAULT_SUFFIX_TEXT;
7
     */
8
        }
8
    public String[] dissect(String path) {
9
9
        char sep = File.separatorChar;
10
        if ((optionalOutputFile == null) || optionalOutputFile.equals("")) {
10
        path = path.replace('/', sep).replace('\\', sep);
11
            int filePos = javaccFile.lastIndexOf("/");
11
12
12
        // make sure we are dealing with an absolute path
13
            if (filePos >= 0) {
13
        if (!isAbsolutePath(path)) {
14
                javaccFile = javaccFile.substring(filePos + 1);
14
            throw new BuildException(path + " is not an absolute path");
15
            }
15
        }
16
16
        String root = null;
17
            int suffixPos = javaccFile.lastIndexOf('.');
17
        int colon = path.indexOf(':');
18
18
        if (colon > 0 && (onDos || onNetWare)) {
19
            if (suffixPos == -1) {
19
20
                optionalOutputFile = javaccFile + suffix;
20
            int next = colon + 1;
21
            } else {
21
            root = path.substring(0, next);
22
                String currentSuffix = javaccFile.substring(suffixPos);
22
            char[] ca = path.toCharArray();
23
23
            root += sep;
24
                if (currentSuffix.equals(suffix)) {
24
            //remove the initial separator; the root has it.
25
                    optionalOutputFile = javaccFile + suffix;
25
            next = (ca[next] == sep) ? next + 1 : next;
26
                } else {
26
27
                    optionalOutputFile = javaccFile.substring(0, suffixPos)
27
            StringBuffer sbPath = new StringBuffer();
28
                        + suffix;
28
            // Eliminate consecutive slashes after the drive spec:
29
                }
29
            for (int i = next; i < ca.length; i++) {
30
            }
30
                if (ca[i] != sep || ca[i - 1] != sep) {
31
        } else {
31
                    sbPath.append(ca[i]);
32
            optionalOutputFile = optionalOutputFile.replace('\\', '/');
32
                }
33
        }
33
            }
34
34
            path = sbPath.toString();
35
        return (getProject().getBaseDir() + "/" + optionalOutputFile)
35
        } else if (path.length() > 1 && path.charAt(1) == sep) {
36
            .replace('\\', '/');
36
            // UNC drive
37
    }
37
            int nextsep = path.indexOf(sep, 2);
38
            nextsep = path.indexOf(sep, nextsep + 1);
39
            root = (nextsep > 2) ? path.substring(0, nextsep + 1) : path;
40
            path = path.substring(root.length());
41
        } else {
42
            root = File.separator;
43
            path = path.substring(1);
44
        }
45
        return new String[] {root, path};
46
    }
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements3
    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.750
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    13
    if (currentSuffix.equals(suffix))
    13
    if (currentSuffix.equals(suffix))
    21
    root = (nextsep > 2) ? path.substring(0, nextsep + 1) : path;
    Differences
    Expression1Expression2Difference
    currentSuffix.equals(suffix)(nextsep > 2)TYPE_COMPATIBLE_REPLACEMENT
    optionalOutputFilerootVARIABLE_NAME_MISMATCH
    optionalOutputFilerootVARIABLE_NAME_MISMATCH
    javaccFile + suffixpath.substring(0,nextsep + 1)TYPE_COMPATIBLE_REPLACEMENT
    javaccFile.substring(0,suffixPos) + suffixpathTYPE_COMPATIBLE_REPLACEMENT
    21
    root = (nextsep > 2) ? path.substring(0, nextsep + 1) : path;
    14
    optionalOutputFile = javaccFile + suffix;
    14
    optionalOutputFile = javaccFile + suffix;
    Differences
    Expression1Expression2Difference
    optionalOutputFilerootVARIABLE_NAME_MISMATCH
    javaccFile + suffixpath.substring(0,nextsep + 1)TYPE_COMPATIBLE_REPLACEMENT
                                                                                          
    else
            
    15
    optionalOutputFile = javaccFile.substring(0, suffixPos) + suffix;
    15
    optionalOutputFile = javaccFile.substring(0, suffixPos) + suffix;
    Differences
    Expression1Expression2Difference
    optionalOutputFilerootVARIABLE_NAME_MISMATCH
    javaccFile.substring(0,suffixPos) + suffixpathTYPE_COMPATIBLE_REPLACEMENT
                                                                                                                                        
    Precondition Violations (0)
    Row Violation