StringBuffer subst = new StringBuffer(); for (int i = 0; i < argument.length(); i++) { char c = argument.charAt(i); if (c == '$') { subst.append('\\'); subst.append('$'); } else if (c == '\\') { if (++i < argument.length()) { c = argument.charAt(i); int value = Character.digit(c, 10); if (value > -1) { subst.append("$").append(value); } else { subst.append(c); } } else { // XXX - should throw an exception instead? subst.append('\\'); } } else { subst.append(c); } } // Do the substitution Substitution s = new Perl5Substitution(subst.toString(), Perl5Substitution.INTERPOLATE_ALL); return Util.substitute(matcher, getCompiledPattern(options), s, input, getSubsOptions(options));
for (int i = 0; i < argument.length(); i++) { char c = argument.charAt(i); if (c == '$') { subst.append('\\'); subst.append('$'); } else if (c == '\\') { if (++i < argument.length()) { c = argument.charAt(i); int value = Character.digit(c, 10); if (value > -1) { subst.append("$").append(value); } else { subst.append(c); } } else { // XXX - should throw an exception instead? subst.append('\\'); } } else { subst.append(c); } }
Clone fragments detected by clone detection tool
File path: /apache-ant-1.7.0/src/org/apache/tools/ant/util/regexp/JakartaOroRegexp.java File path: /apache-ant-1.7.0/src/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexp.java
Method name: String substitute(String, String, int) Method name: String substitute(String, String, int)
Number of AST nodes: 17 Number of AST nodes: 14
1
StringBuffer subst = new StringBuffer();
2
        for (int i = 0; i < argument.length(); i++) {
1
for (int i = 0; i < argument.length(); i++) {
3
            char c = argument.charAt(i);
2
            char c = argument.charAt(i);
4
            if (c == '$') {
3
            if (c == '$') {
5
                subst.append('\\');
4
                subst.append('\\');
6
                subst.append('$');
5
                subst.append('$');
7
            } else if (c == '\\') {
6
            } else if (c == '\\') {
8
                if (++i < argument.length()) {
7
                if (++i < argument.length()) {
9
                    c = argument.charAt(i);
8
                    c = argument.charAt(i);
10
                    int value = Character.digit(c, 10);
9
                    int value = Character.digit(c, 10);
11
                    if (value > -1) {
10
                    if (value > -1) {
12
                        subst.append("$").append(value);
11
                        subst.append("$").append(value);
13
                    } else {
12
                    } else {
14
                        subst.append(c);
13
                        subst.append(c);
15
                    }
14
                    }
16
                } else {
15
                } else {
17
                    // XXX - should throw an exception instead?
16
                    // XXX - should throw an exception instead?
18
                    subst.append('\\');
17
                    subst.append('\\');
19
                }
18
                }
20
            } else {
19
            } else {
21
                subst.append(c);
20
                subst.append(c);
22
            }
21
            }
23
        }
22
        }
24
        // Do the substitution
25
        Substitution s =
26
            new Perl5Substitution(subst.toString(),
27
                                  Perl5Substitution.INTERPOLATE_ALL);
28
        return Util.substitute(matcher,
29
                               getCompiledPattern(options),
30
                               s,
31
                               input,
32
                               getSubsOptions(options));
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.7
Clones locationClones are in different classes
Number of node comparisons42
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements14
    Number of unmapped statements in the first code fragment3
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)8.1
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    1
    StringBuffer subst = new StringBuffer();
                                                                                      
    2
    for (int i = 0; i < argument.length(); i++)
    2
    for (int i = 0; i < argument.length(); i++)
    3
    char c = argument.charAt(i);
    3
    char c = argument.charAt(i);
    4
    if (c == '$')
    4
    if (c == '$')
    5
    subst.append('\\');
    5
    subst.append('\\');
    6
    subst.append('$');
    6
    subst.append('$');
    7
    else if (c == '\\')
    7
    else if (c == '\\')
    8
    if (++i < argument.length())
    8
    if (++i < argument.length())
    9
    c = argument.charAt(i);
    9
    c = argument.charAt(i);
    10
    int value = Character.digit(c, 10);
    10
    int value = Character.digit(c, 10);
    11
    if (value > -1)
    11
    if (value > -1)
    12
    subst.append("$").append(value);
    12
    subst.append("$").append(value);
    else
    else
    13
    subst.append(c);
    13
    subst.append(c);
    else
    else
    14
    subst.append('\\');
    14
    subst.append('\\');
    else
    else
    15
    subst.append(c);
    15
    subst.append(c);
    16
    Substitution s = new Perl5Substitution(subst.toString(), Perl5Substitution.INTERPOLATE_ALL);
    16
    Substitution s = new Perl5Substitution(subst.toString(), Perl5Substitution.INTERPOLATE_ALL);
    Preondition Violations
    Unmatched statement Substitution s=new Perl5Substitution(subst.toString(),Perl5Substitution.INTERPOLATE_ALL); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                                                                                                              
    17
    return Util.substitute(matcher, getCompiledPattern(options), s, input, getSubsOptions(options));
    17
    return Util.substitute(matcher, getCompiledPattern(options), s, input, getSubsOptions(options));
    Preondition Violations
    Unmatched return Util.substitute(matcher,getCompiledPattern(options),s,input,getSubsOptions(options));
                                                                                                                                                                                                    
    Precondition Violations (2)
    Row Violation
    1Unmatched statement Substitution s=new Perl5Substitution(subst.toString(),Perl5Substitution.INTERPOLATE_ALL); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched return Util.substitute(matcher,getCompiledPattern(options),s,input,getSubsOptions(options));