private final void parseArguments() throws ParseException { if (STATE_REQUIRE_ARG == m_state) { if ('=' == m_ch || 0 == m_ch) { getChar(); } final Token token = nextToken(NULL_SEPARATORS); m_option.addArgument(token.getValue()); addOption(m_option); m_state = STATE_NORMAL; } else if (STATE_OPTIONAL_ARG == m_state) { if ('-' == m_ch || 0 == m_ch) { getChar(); // consume stray character addOption(m_option); m_state = STATE_NORMAL; return; } if (m_isLong && '=' != m_tokesep){ // Long optional arg must have = as separator addOption(m_option); m_state = STATE_NORMAL; return; } if ('=' == m_ch) { getChar(); } final Token token = nextToken(NULL_SEPARATORS); m_option.addArgument(token.getValue()); addOption(m_option); m_state = STATE_NORMAL; } else if (STATE_REQUIRE_2ARGS == m_state) { if (0 == m_option.getArgumentCount()) { /* * Fix bug: -D arg1=arg2 was causing parse error; however * --define arg1=arg2 is OK This seems to be because the parser * skips the terminator for the long options, but was not doing * so for the short options. */ if (!m_isLong) { if (0 == peekAtChar()) { getChar(); } } final Token token = nextToken(ARG_SEPARATORS); if (TOKEN_SEPARATOR == token.getType()) { final CLOptionDescriptor descriptor = getDescriptorFor(m_option.getDescriptor().getId()); final String message = "Unable to parse first argument for option " + getOptionDescription(descriptor); throw new ParseException(message, 0); } else { m_option.addArgument(token.getValue()); } // Are we about to start a new option? if (0 == m_ch && '-' == peekAtChar()) { // Yes, so the second argument is missing m_option.addArgument(""); m_options.addElement(m_option); m_state = STATE_NORMAL; } } else // 2nd argument { final StringBuilder sb = new StringBuilder(); m_ch = getChar(); while (!isSeparator(m_ch, NULL_SEPARATORS)) { sb.append(m_ch); m_ch = getChar(); } final String argument = sb.toString(); // System.out.println( "Arguement:" + argument ); m_option.addArgument(argument); addOption(m_option); m_option = null; m_state = STATE_NORMAL; } } }
private final Token nextToken(final char[] separators) { m_ch = getChar(); if (isSeparator(m_ch, separators)) { m_tokesep=m_ch; m_ch = getChar(); return new Token(TOKEN_SEPARATOR, null); } final StringBuilder sb = new StringBuilder(); do { sb.append(m_ch); m_ch = getChar(); } while (!isSeparator(m_ch, separators)); m_tokesep=m_ch; return new Token(TOKEN_STRING, sb.toString()); }
Clone fragments detected by clone detection tool
File path: /apache-jmeter-2.11/src/jorphan/org/apache/commons/cli/avalon/CLArgsParser.java File path: /apache-jmeter-2.11/src/jorphan/org/apache/commons/cli/avalon/CLArgsParser.java
Method name: void parseArguments() Method name: Token nextToken(char[])
Number of AST nodes: 3 Number of AST nodes: 3
1
private final void parseArguments() throws ParseException {
1
private final Token nextToken(final char[] separators) {
2
        if (STATE_REQUIRE_ARG == m_state) {
2
        m_ch = getChar();
3
            if ('=' == m_ch || 0 == m_ch) {
3
4
                getChar();
4
        if (isSeparator(m_ch, separators)) {
5
            }
5
            m_tokesep=m_ch;
6
6
            m_ch = getChar();
7
            final Token token = nextToken(NULL_SEPARATORS);
7
            return new Token(TOKEN_SEPARATOR, null);
8
            m_option.addArgument(token.getValue());
8
        }
9
9
10
            addOption(m_option);
10
        final StringBuilder sb = new StringBuilder();
11
            m_state = STATE_NORMAL;
11
12
        } else if (STATE_OPTIONAL_ARG == m_state) {
12
        do {
13
            if ('-' == m_ch || 0 == m_ch) {
13
            sb.append(m_ch);
14
                getChar(); // consume stray character
14
            m_ch = getChar();
15
                addOption(m_option);
15
        } while (!isSeparator(m_ch, separators));
16
                m_state = STATE_NORMAL;
16
17
                return;
17
        m_tokesep=m_ch;
18
            }
18
        return new Token(TOKEN_STRING, sb.toString());
19
19
    }
20
            if (m_isLong && '=' != m_tokesep){ // Long optional arg must have = as separator
21
                addOption(m_option);
22
                m_state = STATE_NORMAL;
23
                return;
24
            }
25
26
            if ('=' == m_ch) {
27
                getChar();
28
            }
29
30
            final Token token = nextToken(NULL_SEPARATORS);
31
            m_option.addArgument(token.getValue());
32
33
            addOption(m_option);
34
            m_state = STATE_NORMAL;
35
        } else if (STATE_REQUIRE_2ARGS == m_state) {
36
            if (0 == m_option.getArgumentCount()) {
37
                /*
38
                 * Fix bug: -D arg1=arg2 was causing parse error; however
39
                 * --define arg1=arg2 is OK This seems to be because the parser
40
                 * skips the terminator for the long options, but was not doing
41
                 * so for the short options.
42
                 */
43
                if (!m_isLong) {
44
                    if (0 == peekAtChar()) {
45
                        getChar();
46
                    }
47
                }
48
                final Token token = nextToken(ARG_SEPARATORS);
49
50
                if (TOKEN_SEPARATOR == token.getType()) {
51
                    final CLOptionDescriptor descriptor = getDescriptorFor(m_option.getDescriptor().getId());
52
                    final String message = "Unable to parse first argument for option "
53
                            + getOptionDescription(descriptor);
54
                    throw new ParseException(message, 0);
55
                } else {
56
                    m_option.addArgument(token.getValue());
57
                }
58
                // Are we about to start a new option?
59
                if (0 == m_ch && '-' == peekAtChar()) {
60
                    // Yes, so the second argument is missing
61
                    m_option.addArgument("");
62
                    m_options.addElement(m_option);
63
                    m_state = STATE_NORMAL;
64
                }
65
            } else // 2nd argument
66
            {
67
                final StringBuilder sb = new StringBuilder();
68
69
                m_ch = getChar();
70
                while (!isSeparator(m_ch, NULL_SEPARATORS)) {
71
                    sb.append(m_ch);
72
                    m_ch = getChar();
73
                }
74
75
                final String argument = sb.toString();
76
77
                // System.out.println( "Arguement:" + argument );
78
79
                m_option.addArgument(argument);
80
                addOption(m_option);
81
                m_option = null;
82
                m_state = STATE_NORMAL;
83
            }
84
        }
85
    }
  1. {Refactorable}
    Mapping Summary
    Number of mapped statements5
    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 Score1.000
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    41
    while (!isSeparator(m_ch, NULL_SEPARATORS))
    41
    while (!isSeparator(m_ch, NULL_SEPARATORS))
    9
    do while(!isSeparator(m_ch, separators))
    Differences
    Expression1Expression2Difference
    NULL_SEPARATORSseparatorsVARIABLE_NAME_MISMATCH
    9
    do while(!isSeparator(m_ch, separators))
    42
    sb.append(m_ch);
    7
    sb.append(m_ch);
    43
    m_ch = getChar();
    8
    m_ch = getChar();
    Precondition Violations (0)
    Row Violation