private String createOutputFileName(File destFile, String optionalOutputFile, String outputDir) { optionalOutputFile = validateOutputFile(optionalOutputFile, outputDir); String jjtreeFile = destFile.getAbsolutePath().replace('\\', '/'); if ((optionalOutputFile == null) || optionalOutputFile.equals("")) { int filePos = jjtreeFile.lastIndexOf("/"); if (filePos >= 0) { jjtreeFile = jjtreeFile.substring(filePos + 1); } int suffixPos = jjtreeFile.lastIndexOf('.'); if (suffixPos == -1) { optionalOutputFile = jjtreeFile + DEFAULT_SUFFIX; } else { String currentSuffix = jjtreeFile.substring(suffixPos); if (currentSuffix.equals(DEFAULT_SUFFIX)) { optionalOutputFile = jjtreeFile + DEFAULT_SUFFIX; } else { optionalOutputFile = jjtreeFile.substring(0, suffixPos) + DEFAULT_SUFFIX; } } } if ((outputDir == null) || outputDir.equals("")) { outputDir = getDefaultOutputDirectory(); } return (outputDir + "/" + 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/JJTree.java File path: /apache-ant-1.7.0/src/org/apache/tools/ant/util/FileUtils.java
Method name: String createOutputFileName(File, String, String) 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
                                        String outputDir) {
2
     * Dissect the specified absolute path.
3
        optionalOutputFile = validateOutputFile(optionalOutputFile,
3
     * @param path the path to dissect.
4
                                                outputDir);
4
     * @return String[] {root, remaining path}.
5
        String jjtreeFile = destFile.getAbsolutePath().replace('\\', '/');
5
     * @throws java.lang.NullPointerException if path is null.
6
6
     * @since Ant 1.7
7
        if ((optionalOutputFile == null) || optionalOutputFile.equals("")) {
7
     */
8
            int filePos = jjtreeFile.lastIndexOf("/");
8
    public String[] dissect(String path) {
9
9
        char sep = File.separatorChar;
10
            if (filePos >= 0) {
10
        path = path.replace('/', sep).replace('\\', sep);
11
                jjtreeFile = jjtreeFile.substring(filePos + 1);
11
12
            }
12
        // make sure we are dealing with an absolute path
13
13
        if (!isAbsolutePath(path)) {
14
            int suffixPos = jjtreeFile.lastIndexOf('.');
14
            throw new BuildException(path + " is not an absolute path");
15
15
        }
16
            if (suffixPos == -1) {
16
        String root = null;
17
                optionalOutputFile = jjtreeFile + DEFAULT_SUFFIX;
17
        int colon = path.indexOf(':');
18
            } else {
18
        if (colon > 0 && (onDos || onNetWare)) {
19
                String currentSuffix = jjtreeFile.substring(suffixPos);
19
20
20
            int next = colon + 1;
21
                if (currentSuffix.equals(DEFAULT_SUFFIX)) {
21
            root = path.substring(0, next);
22
                    optionalOutputFile = jjtreeFile + DEFAULT_SUFFIX;
22
            char[] ca = path.toCharArray();
23
                } else {
23
            root += sep;
24
                    optionalOutputFile = jjtreeFile.substring(0, suffixPos)
24
            //remove the initial separator; the root has it.
25
                        + DEFAULT_SUFFIX;
25
            next = (ca[next] == sep) ? next + 1 : next;
26
                }
26
27
            }
27
            StringBuffer sbPath = new StringBuffer();
28
        }
28
            // Eliminate consecutive slashes after the drive spec:
29
29
            for (int i = next; i < ca.length; i++) {
30
        if ((outputDir == null) || outputDir.equals("")) {
30
                if (ca[i] != sep || ca[i - 1] != sep) {
31
            outputDir = getDefaultOutputDirectory();
31
                    sbPath.append(ca[i]);
32
        }
32
                }
33
33
            }
34
        return (outputDir + "/" + optionalOutputFile).replace('\\', '/');
34
            path = sbPath.toString();
35
    }
35
        } else if (path.length() > 1 && path.charAt(1) == sep) {
36
            // UNC drive
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
    11
    if (currentSuffix.equals(DEFAULT_SUFFIX))
    11
    if (currentSuffix.equals(DEFAULT_SUFFIX))
    21
    root = (nextsep > 2) ? path.substring(0, nextsep + 1) : path;
    Differences
    Expression1Expression2Difference
    currentSuffix.equals(DEFAULT_SUFFIX)(nextsep > 2)TYPE_COMPATIBLE_REPLACEMENT
    optionalOutputFilerootVARIABLE_NAME_MISMATCH
    optionalOutputFilerootVARIABLE_NAME_MISMATCH
    jjtreeFile + DEFAULT_SUFFIXpath.substring(0,nextsep + 1)TYPE_COMPATIBLE_REPLACEMENT
    jjtreeFile.substring(0,suffixPos) + DEFAULT_SUFFIXpathTYPE_COMPATIBLE_REPLACEMENT
    21
    root = (nextsep > 2) ? path.substring(0, nextsep + 1) : path;
    12
    optionalOutputFile = jjtreeFile + DEFAULT_SUFFIX;
    12
    optionalOutputFile = jjtreeFile + DEFAULT_SUFFIX;
    Differences
    Expression1Expression2Difference
    optionalOutputFilerootVARIABLE_NAME_MISMATCH
    jjtreeFile + DEFAULT_SUFFIXpath.substring(0,nextsep + 1)TYPE_COMPATIBLE_REPLACEMENT
                                                                                                          
    else
            
    13
    optionalOutputFile = jjtreeFile.substring(0, suffixPos) + DEFAULT_SUFFIX;
    13
    optionalOutputFile = jjtreeFile.substring(0, suffixPos) + DEFAULT_SUFFIX;
    Differences
    Expression1Expression2Difference
    optionalOutputFilerootVARIABLE_NAME_MISMATCH
    jjtreeFile.substring(0,suffixPos) + DEFAULT_SUFFIXpathTYPE_COMPATIBLE_REPLACEMENT
                                                                                                                                                        
    Precondition Violations (0)
    Row Violation