public static class ReplaceRegex extends ChainableReaderFilter { private String from; private String to; private RegularExpression regularExpression; private Substitution substitution; private boolean initialized = false; private String flags = ""; private int options; private Regexp regexp; /** * the from attribute * @param from the regex string */ public void setPattern(String from) { this.from = from; } /** * the to attribute * @param to the replacement string */ public void setReplace(String to) { this.to = to; } /** * @param flags the regex flags */ public void setFlags(String flags) { this.flags = flags; } private void initialize() { if (initialized) { return; } options = convertRegexOptions(flags); if (from == null) { throw new BuildException("Missing pattern in replaceregex"); } regularExpression = new RegularExpression(); regularExpression.setPattern(from); regexp = regularExpression.getRegexp(getProject()); if (to == null) { to = ""; } substitution = new Substitution(); substitution.setExpression(to); } /** * @param line the string to modify * @return the modified string */ public String filter(String line) { initialize(); if (!regexp.matches(line, options)) { return line; } return regexp.substitute( line, substitution.getExpression(getProject()), options);
public static class ContainsRegex extends ChainableReaderFilter { private String from; private String to; private RegularExpression regularExpression; private Substitution substitution; private boolean initialized = false; private String flags = ""; private int options; private Regexp regexp; /** * @param from the regex pattern */ public void setPattern(String from) { this.from = from; } /** * @param to the replacement string */ public void setReplace(String to) { this.to = to; } /** * @param flags the regex flags */ public void setFlags(String flags) { this.flags = flags; } private void initialize() { if (initialized) { return; } options = convertRegexOptions(flags); if (from == null) { throw new BuildException("Missing from in containsregex"); } regularExpression = new RegularExpression(); regularExpression.setPattern(from); regexp = regularExpression.getRegexp(getProject()); if (to == null) { return; } substitution = new Substitution(); substitution.setExpression(to); } /** * apply regex and substitution on a string * @param string the string to apply filter on * @return the filtered string */ public String filter(String string) { initialize(); if (!regexp.matches(string, options)) { return null; } if (substitution == null) { return string; } return regexp.substitute( string, substitution.getExpression(getProject()), options);
Clone fragments detected by clone detection tool
File path: /apache-ant-1.7.0/src/org/apache/tools/ant/filters/TokenFilter.java File path: /apache-ant-1.7.0/src/org/apache/tools/ant/filters/TokenFilter.java
Method name: Method name:
Number of AST nodes: 0 Number of AST nodes: 0
1
public static class ReplaceRegex extends ChainableReaderFilter {
1
public static class ContainsRegex extends ChainableReaderFilter {
2
        private String             from;
2
        private String             from;
3
        private String             to;
3
        private String             to;
4
        private RegularExpression  regularExpression;
4
        private RegularExpression  regularExpression;
5
        private Substitution       substitution;
5
        private Substitution       substitution;
6
        private boolean            initialized = false;
6
        private boolean            initialized = false;
7
        private String             flags = "";
7
        private String             flags = "";
8
        private int                options;
8
        private int                options;
9
        private Regexp             regexp;
9
        private Regexp             regexp;
10
        /**
10
        /**
11
         * the from attribute
12
         * @param from the regex string
11
         * @param from the regex pattern
13
         */
12
         */
14
        public void setPattern(String from) {
13
        public void setPattern(String from) {
15
            this.from = from;
14
            this.from = from;
16
        }
15
        }
17
        /**
16
        /**
18
         * the to attribute
19
         * @param to the replacement string
17
         * @param to the replacement string
20
         */
18
         */
21
        public void setReplace(String to) {
19
        public void setReplace(String to) {
22
            this.to = to;
20
            this.to = to;
23
        }
21
        }
24
        /**
22
        /**
25
         * @param flags the regex flags
23
         * @param flags the regex flags
26
         */
24
         */
27
        public void setFlags(String flags) {
25
        public void setFlags(String flags) {
28
            this.flags = flags;
26
            this.flags = flags;
29
        }
27
        }
30
        private void initialize() {
28
        private void initialize() {
31
            if (initialized) {
29
            if (initialized) {
32
                return;
30
                return;
33
            }
31
            }
34
            options = convertRegexOptions(flags);
32
            options = convertRegexOptions(flags);
35
            if (from == null) {
33
            if (from == null) {
36
                throw new BuildException("Missing pattern in replaceregex");
34
                throw new BuildException("Missing from in containsregex");
37
            }
35
            }
38
            regularExpression = new RegularExpression();
36
            regularExpression = new RegularExpression();
39
            regularExpression.setPattern(from);
37
            regularExpression.setPattern(from);
40
            regexp = regularExpression.getRegexp(getProject());
38
            regexp = regularExpression.getRegexp(getProject());
41
            if (to == null) {
39
            if (to == null) {
42
                to = "";
40
                return;
43
            }
41
            }
44
            substitution = new Substitution();
42
            substitution = new Substitution();
45
            substitution.setExpression(to);
43
            substitution.setExpression(to);
46
        }
44
        }
47
        /**
45
        /**
46
         * apply regex and substitution on a string
48
         * @param line the string to modify
47
         * @param string the string to apply filter on
49
         * @return the modified string
48
         * @return the filtered string
50
         */
49
         */
51
        public String filter(String line) {
50
        public String filter(String string) {
52
            initialize();
51
            initialize();
53
            if (!regexp.matches(line, options)) {
52
            if (!regexp.matches(string, options)) {
54
                return line
53
                return null;
54
            }
55
            if (substitution == null) {
55
;
56
                return string;
56
            }
57
            }
57
            return regexp.substitute(
58
            return regexp.substitute(
58
                line, substitution.getExpression(getProject()), options);
59
                string, substitution.getExpression(getProject()), options);
59
        
60
        
Summary
Number of common nesting structure subtrees0
Number of refactorable cases0
Number of non-refactorable cases0
Time elapsed for finding largest common nesting structure subtrees (ms)0.0
Clones location
Number of node comparisons0