char c = e.getKeyChar(); // as a coding convenience, create a reference to the text component // that is typecast to JTextComponent. this is not essential, as we // could typecast every reference, but this makes the code cleaner JTextComponent _theComponent = (JTextComponent)DataTypeLong.this._textComponent; String text = _theComponent.getText(); // look for illegal chars if ( ! DataTypeLong.this._isSigned && c == '-') { // cannot use '-' when unsigned _beepHelper.beep(_theComponent); e.consume(); } // tabs and newlines get put into the text before this check, // so remove them // This only applies to Popup editing since these chars are // not passed to this level by the in-cell editor. if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) { // remove all instances of the offending char int index = text.indexOf(c); if (index != -1) { if (index == text.length() -1) { text = text.substring(0, text.length()-1); // truncate string } else { text = text.substring(0, index) + text.substring(index+1); } ((IRestorableTextComponent)_theComponent).updateText( text); _beepHelper.beep(_theComponent); } e.consume(); } if ( ! ( Character.isDigit(c) || (c == '-') || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE) ) ) { _beepHelper.beep(_theComponent); e.consume(); } // check for max size reached (only works when DB provides non-zero scale info if (DataTypeLong.this._scale > 0 && text.length() == DataTypeLong.this._scale && c != KeyEvent.VK_BACK_SPACE && c != KeyEvent.VK_DELETE) { // max size reached e.consume(); _beepHelper.beep(_theComponent); } // handle cases of null // The processing is different when nulls are allowed and when they are not. // if ( DataTypeLong.this._isNullable) { // user enters something when field is null if (text.equals("<null>")) { if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) { // delete when null => original value DataTypeLong.this._textComponent.restoreText(); e.consume(); } else { // non-delete when null => clear field and add text DataTypeLong.this._textComponent.updateText(""); // fall through to normal processing of this key stroke } } else { // check for user deletes last thing in field if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) { if (text.length() <= 1 ) { // about to delete last thing in field, so replace with null DataTypeLong.this._textComponent.updateText("<null>"); e.consume(); } } } } else { // field is not nullable // handleNotNullableField(text, c, e, _textComponent); }
char c = e.getKeyChar(); // as a coding convenience, create a reference to the text component // that is typecast to JTextComponent. this is not essential, as we // could typecast every reference, but this makes the code cleaner JTextComponent _theComponent = (JTextComponent)DataTypeShort.this._textComponent; String text = _theComponent.getText(); // look for illegal chars if ( ! DataTypeShort.this._isSigned && c == '-') { // cannot use '-' when unsigned _beepHelper.beep(_theComponent); e.consume(); } // tabs and newlines get put into the text before this check, // so remove them // This only applies to Popup editing since these chars are // not passed to this level by the in-cell editor. if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) { // remove all instances of the offending char int index = text.indexOf(c); if (index != -1) { if (index == text.length() -1) { text = text.substring(0, text.length()-1); // truncate string } else { text = text.substring(0, index) + text.substring(index+1); } ((IRestorableTextComponent)_theComponent).updateText( text); _beepHelper.beep(_theComponent); } e.consume(); } if ( ! ( Character.isDigit(c) || (c == '-') || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE) ) ) { _beepHelper.beep(_theComponent); e.consume(); } // check for max size reached (only works when DB provides non-zero scale info if (DataTypeShort.this._scale > 0 && text.length() == DataTypeShort.this._scale && c != KeyEvent.VK_BACK_SPACE && c != KeyEvent.VK_DELETE) { // max size reached e.consume(); _beepHelper.beep(_theComponent); } // handle cases of null // The processing is different when nulls are allowed and when they are not. // if ( DataTypeShort.this._isNullable) { // user enters something when field is null if (text.equals("<null>")) { if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) { // delete when null => original value DataTypeShort.this._textComponent.restoreText(); e.consume(); } else { // non-delete when null => clear field and add text DataTypeShort.this._textComponent.updateText(""); // fall through to normal processing of this key stroke } } else { // check for user deletes last thing in field if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) { if (text.length() <= 1 ) { // about to delete last thing in field, so replace with null DataTypeShort.this._textComponent.updateText("<null>"); e.consume(); } } } } else { // field is not nullable // handleNotNullableField(text, c, e, _textComponent); }
Clone fragments detected by clone detection tool
File path: /sql12/fw/src/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeLong.java File path: /sql12/fw/src/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeShort.java
Method name: void keyTyped(KeyEvent) Method name: void keyTyped(KeyEvent)
Number of AST nodes: 32 Number of AST nodes: 32
1
char c = e.getKeyChar();
1
char c = e.getKeyChar();
2
				
2
				
3
				// as a coding convenience, create a reference to the text component
3
				// as a coding convenience, create a reference to the text component
4
				// that is typecast to JTextComponent.  this is not essential, as we
4
				// that is typecast to JTextComponent.  this is not essential, as we
5
				// could typecast every reference, but this makes the code cleaner
5
				// could typecast every reference, but this makes the code cleaner
6
				JTextComponent _theComponent = (JTextComponent)DataTypeLong.this._textComponent;
6
				JTextComponent _theComponent = (JTextComponent)DataTypeShort.this._textComponent;
7
				String text = _theComponent.getText();
7
				String text = _theComponent.getText();
8
	
8
	
9
				// look for illegal chars
9
				// look for illegal chars
10
				if ( ! DataTypeLong.this._isSigned && c == '-') {
10
				if ( ! DataTypeShort.this._isSigned && c == '-') {
11
					// cannot use '-' when unsigned
11
					// cannot use '-' when unsigned
12
					_beepHelper.beep(_theComponent);
12
					_beepHelper.beep(_theComponent);
13
					e.consume();
13
					e.consume();
14
				}
14
				}
15
												
15
												
16
				// tabs and newlines get put into the text before this check,
16
				// tabs and newlines get put into the text before this check,
17
				// so remove them
17
				// so remove them
18
				// This only applies to Popup editing since these chars are
18
				// This only applies to Popup editing since these chars are
19
				// not passed to this level by the in-cell editor.
19
				// not passed to this level by the in-cell editor.
20
				if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) {
20
				if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) {
21
					// remove all instances of the offending char
21
					// remove all instances of the offending char
22
					int index = text.indexOf(c);
22
					int index = text.indexOf(c);
23
					if (index != -1) {
23
					if (index != -1) {
24
						if (index == text.length() -1) {
24
						if (index == text.length() -1) {
25
							text = text.substring(0, text.length()-1);	// truncate string
25
							text = text.substring(0, text.length()-1);	// truncate string
26
						}
26
						}
27
						else {
27
						else {
28
							text = text.substring(0, index) + text.substring(index+1);
28
							text = text.substring(0, index) + text.substring(index+1);
29
						}					
29
						}
30
						((IRestorableTextComponent)_theComponent).updateText( text);
30
						((IRestorableTextComponent)_theComponent).updateText( text);
31
						_beepHelper.beep(_theComponent);
31
						_beepHelper.beep(_theComponent);
32
					}
32
					}
33
					e.consume();
33
					e.consume();
34
				}
34
				}
35
				if ( ! ( Character.isDigit(c) ||
35
				if ( ! ( Character.isDigit(c) ||
36
					(c == '-') ||
36
					(c == '-') ||
37
					(c == KeyEvent.VK_BACK_SPACE) ||
37
					(c == KeyEvent.VK_BACK_SPACE) ||
38
					(c == KeyEvent.VK_DELETE) ) ) {
38
					(c == KeyEvent.VK_DELETE) ) ) {
39
					_beepHelper.beep(_theComponent);
39
					_beepHelper.beep(_theComponent);
40
					e.consume();
40
					e.consume();
41
				}
41
				}
42
				// check for max size reached (only works when DB provides non-zero scale info
42
				// check for max size reached (only works when DB provides non-zero scale info
43
				if (DataTypeLong.this._scale > 0 &&
43
				if (DataTypeShort.this._scale > 0 &&
44
					text.length() == DataTypeLong.this._scale &&
44
					text.length() == DataTypeShort.this._scale &&
45
					c != KeyEvent.VK_BACK_SPACE &&
45
					c != KeyEvent.VK_BACK_SPACE &&
46
					c != KeyEvent.VK_DELETE) {
46
					c != KeyEvent.VK_DELETE) {
47
					// max size reached
47
					// max size reached
48
					e.consume();
48
					e.consume();
49
					_beepHelper.beep(_theComponent);
49
					_beepHelper.beep(_theComponent);
50
				}
50
				}
51
				// handle cases of null
51
				// handle cases of null
52
				// The processing is different when nulls are allowed and when they are not.
52
				// The processing is different when nulls are allowed and when they are not.
53
				//
53
				//
54
				if ( DataTypeLong.this._isNullable) {
54
				if ( DataTypeShort.this._isNullable) {
55
					// user enters something when field is null
55
					// user enters something when field is null
56
					if (text.equals("<null>")) {
56
					if (text.equals("<null>")) {
57
						if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
57
						if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
58
							// delete when null => original value
58
							// delete when null => original value
59
							DataTypeLong.this._textComponent.restoreText();
59
							DataTypeShort.this._textComponent.restoreText();
60
							e.consume();
60
							e.consume();
61
						}
61
						}
62
						else {
62
						else {
63
							// non-delete when null => clear field and add text
63
							// non-delete when null => clear field and add text
64
							DataTypeLong.this._textComponent.updateText("");
64
							DataTypeShort.this._textComponent.updateText("");
65
							// fall through to normal processing of this key stroke
65
							// fall through to normal processing of this key stroke
66
						}
66
						}
67
					}
67
					}
68
					else {
68
					else {
69
						// check for user deletes last thing in field
69
						// check for user deletes last thing in field
70
						if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
70
						if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
71
							if (text.length() <= 1 ) {
71
							if (text.length() <= 1 ) {
72
								// about to delete last thing in field, so replace with null
72
								// about to delete last thing in field, so replace with null
73
								DataTypeLong.this._textComponent.updateText("<null>");
73
								DataTypeShort.this._textComponent.updateText("<null>");
74
								e.consume();
74
								e.consume();
75
							}
75
							}
76
						}
76
						}
77
					}
77
					}
78
				}
78
				}
79
				else {
79
				else {
80
                    // field is not nullable
80
                    // field is not nullable
81
                    //
81
                    //
82
                    handleNotNullableField(text, c, e, _textComponent);
82
                    handleNotNullableField(text, c, e, _textComponent);
83
				}
83
				}
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)9.1
Clones locationClones are in different classes having the same super class
Number of node comparisons123
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements32
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)159.2
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    char c = e.getKeyChar();
    1
    char c = e.getKeyChar();
    2
    JTextComponent _theComponent = (JTextComponent)DataTypeLong.this._textComponent;
    2
    JTextComponent _theComponent = (JTextComponent)DataTypeLong.this._textComponent;
    2
    JTextComponent _theComponent = (JTextComponent)DataTypeShort.this._textComponent;
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeLongnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeShortSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeLong cannot be unified with expression DataTypeShort , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    2
    JTextComponent _theComponent = (JTextComponent)DataTypeShort.this._textComponent;
    3
    String text = _theComponent.getText();
    3
    String text = _theComponent.getText();
    4
    if (!DataTypeLong.this._isSigned && c == '-')
    4
    if (!DataTypeLong.this._isSigned && c == '-')
    4
    if (!DataTypeShort.this._isSigned && c == '-')
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeLongnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeShortSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeLong cannot be unified with expression DataTypeShort , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private boolean _isSigned
    4
    if (!DataTypeShort.this._isSigned && c == '-')
    5
    _beepHelper.beep(_theComponent);
    5
    _beepHelper.beep(_theComponent);
    6
    e.consume();
    6
    e.consume();
    7
    if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER)
    7
    if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER)
    8
    int index = text.indexOf(c);
    8
    int index = text.indexOf(c);
    9
    if (index != -1)
    9
    if (index != -1)
    10
    if (index == text.length() - 1)
    10
    if (index == text.length() - 1)
    11
    text = text.substring(0, text.length() - 1);
    11
    text = text.substring(0, text.length() - 1);
    else
    else
    12
    text = text.substring(0, index) + text.substring(index + 1);
    12
    text = text.substring(0, index) + text.substring(index + 1);
    13
    ((IRestorableTextComponent)_theComponent).updateText(text);
    13
    ((IRestorableTextComponent)_theComponent).updateText(text);
    14
    _beepHelper.beep(_theComponent);
    14
    _beepHelper.beep(_theComponent);
    15
    e.consume();
    15
    e.consume();
    16
    if (!(Character.isDigit(c) || (c == '-') || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)))
    16
    if (!(Character.isDigit(c) || (c == '-') || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)))
    17
    _beepHelper.beep(_theComponent);
    17
    _beepHelper.beep(_theComponent);
    18
    e.consume();
    18
    e.consume();
    19
    if (DataTypeLong.this._scale > 0 && text.length() == DataTypeLong.this._scale && c != KeyEvent.VK_BACK_SPACE && c != KeyEvent.VK_DELETE)
    19
    if (DataTypeLong.this._scale > 0 && text.length() == DataTypeLong.this._scale && c != KeyEvent.VK_BACK_SPACE && c != KeyEvent.VK_DELETE)
    19
    if (DataTypeShort.this._scale > 0 && text.length() == DataTypeShort.this._scale && c != KeyEvent.VK_BACK_SPACE && c != KeyEvent.VK_DELETE)
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeLongnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeShortSUBCLASS_TYPE_MISMATCH
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeLongnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeShortSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeLong cannot be unified with expression DataTypeShort , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private int _scale
    Expression DataTypeLong cannot be unified with expression DataTypeShort , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private int _scale
    19
    if (DataTypeShort.this._scale > 0 && text.length() == DataTypeShort.this._scale && c != KeyEvent.VK_BACK_SPACE && c != KeyEvent.VK_DELETE)
    20
    e.consume();
    20
    e.consume();
    21
    _beepHelper.beep(_theComponent);
    21
    _beepHelper.beep(_theComponent);
    22
    if (DataTypeLong.this._isNullable)
    22
    if (DataTypeLong.this._isNullable)
    22
    if (DataTypeShort.this._isNullable)
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeLongnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeShortSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeLong cannot be unified with expression DataTypeShort , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private boolean _isNullable
    22
    if (DataTypeShort.this._isNullable)
    23
    if (text.equals("<null>"))
    23
    if (text.equals("<null>"))
    24
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    24
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    25
    DataTypeLong.this._textComponent.restoreText();
    25
    DataTypeLong.this._textComponent.restoreText();
    25
    DataTypeShort.this._textComponent.restoreText();
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeLongnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeShortSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeLong cannot be unified with expression DataTypeShort , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    25
    DataTypeShort.this._textComponent.restoreText();
    26
    e.consume();
    26
    e.consume();
    else
    else
    27
    DataTypeLong.this._textComponent.updateText("");
    27
    DataTypeLong.this._textComponent.updateText("");
    27
    DataTypeShort.this._textComponent.updateText("");
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeLongnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeShortSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeLong cannot be unified with expression DataTypeShort , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    27
    DataTypeShort.this._textComponent.updateText("");
    else
    else
    28
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    28
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    29
    if (text.length() <= 1)
    29
    if (text.length() <= 1)
    30
    DataTypeLong.this._textComponent.updateText("<null>");
    30
    DataTypeLong.this._textComponent.updateText("<null>");
    30
    DataTypeShort.this._textComponent.updateText("<null>");
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeLongnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeShortSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeLong cannot be unified with expression DataTypeShort , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    30
    DataTypeShort.this._textComponent.updateText("<null>");
    31
    e.consume();
    31
    e.consume();
    else
    else
    32
    handleNotNullableField(text, c, e, _textComponent);
    32
    handleNotNullableField(text, c, e, _textComponent);
    Precondition Violations (8)
    Row Violation
    1Expression DataTypeLong cannot be unified with expression DataTypeShort , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    2Expression DataTypeLong cannot be unified with expression DataTypeShort , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private boolean _isSigned
    3Expression DataTypeLong cannot be unified with expression DataTypeShort , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private int _scale
    4Expression DataTypeLong cannot be unified with expression DataTypeShort , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private int _scale
    5Expression DataTypeLong cannot be unified with expression DataTypeShort , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private boolean _isNullable
    6Expression DataTypeLong cannot be unified with expression DataTypeShort , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    7Expression DataTypeLong cannot be unified with expression DataTypeShort , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    8Expression DataTypeLong cannot be unified with expression DataTypeShort , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent