int index = text.indexOf("&"); if ((index != -1) && ((index + 1) < text.length())) { // mnemonic found // ...and not at the end of the string (which doesn't make sence) char mnemonic = text.charAt(index + 1); StringBuffer buf = new StringBuffer(); // if mnemonic is first character of this string if (index == 0) { buf.append(text.substring(1)); } else { buf.append(text.substring(0, index)); buf.append(text.substring(index + 1)); } // set display text component.setText(buf.toString()); // set mnemonic component.setMnemonic(mnemonic); component.setDisplayedMnemonicIndex(index); } else { // no mnemonic found - just set the text on the menu item component.setText(text); }
int index = text.indexOf("&"); if ((index != -1) && ((index + 1) < text.length())) { // mnemonic found // ...and not at the end of the string (which doesn't make sence) char mnemonic = text.charAt(index + 1); StringBuffer buf = new StringBuffer(); // if mnemonic is first character of this string if (index == 0) { buf.append(text.substring(1)); } else { buf.append(text.substring(0, index)); buf.append(text.substring(index + 1)); } // set display text label.setText(buf.toString()); // set mnemonic label.setDisplayedMnemonic(mnemonic); label.setDisplayedMnemonicIndex(index); } else { // no mnemonic found - just set the text on the menu item label.setText(text); }
Clone fragments detected by clone detection tool
File path: /columba-1.4-src/core/src/main/java/org/columba/core/gui/base/MnemonicSetter.java File path: /columba-1.4-src/core/src/main/java/org/columba/core/gui/base/MnemonicSetter.java
Method name: void setTextWithMnemonic(AbstractButton, String) Method name: void setTextWithMnemonic(JLabel, String)
Number of AST nodes: 12 Number of AST nodes: 12
1
int index = text.indexOf("&");
1
int index = text.indexOf("&");
2
		if ((index != -1) && ((index + 1) < text.length())) {
2
		if ((index != -1) && ((index + 1) < text.length())) {
3
			// mnemonic found
3
			// mnemonic found
4
			// ...and not at the end of the string (which doesn't make sence)
4
			// ...and not at the end of the string (which doesn't make sence)
5
			char mnemonic = text.charAt(index + 1);
5
			char mnemonic = text.charAt(index + 1);
6
			StringBuffer buf = new StringBuffer();
6
			StringBuffer buf = new StringBuffer();
7
			// if mnemonic is first character of this string
7
			// if mnemonic is first character of this string
8
			if (index == 0) {
8
			if (index == 0) {
9
				buf.append(text.substring(1));
9
				buf.append(text.substring(1));
10
			} else {
10
			} else {
11
				buf.append(text.substring(0, index));
11
				buf.append(text.substring(0, index));
12
				buf.append(text.substring(index + 1));
12
				buf.append(text.substring(index + 1));
13
			}
13
			}
14
			// set display text
14
			// set display text
15
			component.setText(buf.toString());
15
			label.setText(buf.toString());
16
			// set mnemonic
16
			// set mnemonic
17
			component.setMnemonic(mnemonic);
17
			label.setDisplayedMnemonic(mnemonic);
18
			component.setDisplayedMnemonicIndex(index);
18
			label.setDisplayedMnemonicIndex(index);
19
		} else {
19
		} else {
20
			// no mnemonic found - just set the text on the menu item
20
			// no mnemonic found - just set the text on the menu item
21
			component.setText(text);
21
			label.setText(text);
22
		}
22
		}
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.5
Clones locationClones are declared in the same class
Number of node comparisons66
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements12
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)29.1
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    int index = text.indexOf("&");
    1
    int index = text.indexOf("&");
    2
    if ((index != -1) && ((index + 1) < text.length()))
    2
    if ((index != -1) && ((index + 1) < text.length()))
    3
    char mnemonic = text.charAt(index + 1);
    3
    char mnemonic = text.charAt(index + 1);
    4
    StringBuffer buf = new StringBuffer();
    4
    StringBuffer buf = new StringBuffer();
    5
    if (index == 0)
    5
    if (index == 0)
    6
    buf.append(text.substring(1));
    6
    buf.append(text.substring(1));
    else
    else
    7
    buf.append(text.substring(0, index));
    7
    buf.append(text.substring(0, index));
    8
    buf.append(text.substring(index + 1));
    8
    buf.append(text.substring(index + 1));
    9
    component.setText(buf.toString());
    9
    component.setText(buf.toString());
    9
    label.setText(buf.toString());
    Differences
    Expression1Expression2Difference
    componentlabelVARIABLE_NAME_MISMATCH
    javax.swing.AbstractButtonjavax.swing.JLabelSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression component cannot be unified with expression label , because common superclass javax.swing.JComponent does not declare member(s) public void setText(java.lang.String)
    9
    label.setText(buf.toString());
    10
    component.setMnemonic(mnemonic);
    10
    component.setMnemonic(mnemonic);
    10
    label.setDisplayedMnemonic(mnemonic);
    Differences
    Expression1Expression2Difference
    setMnemonicsetDisplayedMnemonicMETHOD_INVOCATION_NAME_MISMATCH
    componentlabelVARIABLE_NAME_MISMATCH
    javax.swing.AbstractButtonjavax.swing.JLabelSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression component.setMnemonic(mnemonic) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression label.setDisplayedMnemonic(mnemonic) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression component.setMnemonic(mnemonic) is a void method call, and thus it cannot be parameterized
    Expression label.setDisplayedMnemonic(mnemonic) is a void method call, and thus it cannot be parameterized
    10
    label.setDisplayedMnemonic(mnemonic);
    11
    component.setDisplayedMnemonicIndex(index);
    11
    component.setDisplayedMnemonicIndex(index);
    11
    label.setDisplayedMnemonicIndex(index);
    Differences
    Expression1Expression2Difference
    componentlabelVARIABLE_NAME_MISMATCH
    javax.swing.AbstractButtonjavax.swing.JLabelSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression component cannot be unified with expression label , because common superclass javax.swing.JComponent does not declare member(s) public void setDisplayedMnemonicIndex(int) throws java.lang.IllegalArgumentException
    11
    label.setDisplayedMnemonicIndex(index);
    else
    else
    12
    component.setText(text);
    12
    component.setText(text);
    12
    label.setText(text);
    Differences
    Expression1Expression2Difference
    componentlabelVARIABLE_NAME_MISMATCH
    javax.swing.AbstractButtonjavax.swing.JLabelSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression component cannot be unified with expression label , because common superclass javax.swing.JComponent does not declare member(s) public void setText(java.lang.String)
    12
    label.setText(text);
    Precondition Violations (7)
    Row Violation
    1Expression component cannot be unified with expression label , because common superclass javax.swing.JComponent does not declare member(s) public void setText(java.lang.String)
    2Expression component.setMnemonic(mnemonic) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Expression label.setDisplayedMnemonic(mnemonic) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Expression component.setMnemonic(mnemonic) is a void method call, and thus it cannot be parameterized
    5Expression label.setDisplayedMnemonic(mnemonic) is a void method call, and thus it cannot be parameterized
    6Expression component cannot be unified with expression label , because common superclass javax.swing.JComponent does not declare member(s) public void setDisplayedMnemonicIndex(int) throws java.lang.IllegalArgumentException
    7Expression component cannot be unified with expression label , because common superclass javax.swing.JComponent does not declare member(s) public void setText(java.lang.String)