File path: /sql12/fw/src/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeByte.java | File path: /sql12/fw/src/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeInteger.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)DataTypeByte.this._textComponent;↵ | 6 | JTextComponent _theComponent = (JTextComponent)DataTypeInteger.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 ( ! DataTypeByte.this._isSigned && c == '-') {↵ | 10 | if ( ! DataTypeInteger.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) {↵ | |||
24 | ↵ | 23 | if(-1 != index)↵ | |
24 | {↵ | |||
25 | if (index == text.length() -1) {↵ | 25 | if (index == text.length() -1) {↵ | |
26 | text = text.substring(0, text.length()-1); // truncate string↵ | 26 | text = text.substring(0, text.length()-1); // truncate string↵ | |
27 | }↵ | |||
28 | else {↵ | |||
29 | ↵ | 27 | }↵ | |
28 | else {↵ | |||
30 | text = text.substring(0, index) + text.substring(index+1);↵ | 29 | text = text.substring(0, index) + text.substring(index+1);↵ | |
31 | }↵ | |||
32 | ↵ | 30 | }↵ | |
31 | }↵ | |||
33 | ((IRestorableTextComponent)_theComponent).updateText( text);↵ | 32 | ((IRestorableTextComponent)_theComponent).updateText( text);↵ | |
34 | _beepHelper.beep(_theComponent);↵ | 33 | _beepHelper.beep(_theComponent);↵ | |
35 | }↵ | 34 | ↵ | |
36 | e.consume();↵ | 35 | e.consume();↵ | |
37 | }↵ | 36 | }↵ | |
38 | if ( ! ( Character.isDigit(c) ||↵ | 37 | if ( ! ( Character.isDigit(c) ||↵ | |
39 | (c == '-') ||↵ | 38 | (c == '-') ||↵ | |
40 | (c == KeyEvent.VK_BACK_SPACE) ||↵ | 39 | (c == KeyEvent.VK_BACK_SPACE) ||↵ | |
41 | (c == KeyEvent.VK_DELETE) ) ) {↵ | 40 | (c == KeyEvent.VK_DELETE) ) ) {↵ | |
42 | _beepHelper.beep(_theComponent);↵ | 41 | _beepHelper.beep(_theComponent);↵ | |
43 | e.consume();↵ | 42 | e.consume();↵ | |
44 | }↵ | 43 | }↵ | |
45 | // check for max size reached (only works when DB provides non-zero scale info↵ | 44 | // check for max size reached (only works when DB provides non-zero scale info↵ | |
46 | if (DataTypeByte.this._scale > 0 &&↵ | 45 | if (DataTypeInteger.this._scale > 0 &&↵ | |
47 | text.length() == DataTypeByte.this._scale &&↵ | 46 | text.length() == DataTypeInteger.this._scale &&↵ | |
48 | c != KeyEvent.VK_BACK_SPACE &&↵ | 47 | c != KeyEvent.VK_BACK_SPACE &&↵ | |
49 | c != KeyEvent.VK_DELETE) {↵ | 48 | c != KeyEvent.VK_DELETE) {↵ | |
50 | // max size reached↵ | 49 | // max size reached↵ | |
51 | e.consume();↵ | 50 | e.consume();↵ | |
52 | _beepHelper.beep(_theComponent);↵ | 51 | _beepHelper.beep(_theComponent);↵ | |
53 | }↵ | 52 | }↵ | |
54 | // handle cases of null↵ | 53 | // handle cases of null↵ | |
55 | // The processing is different when nulls are allowed and when they are not.↵ | 54 | // The processing is different when nulls are allowed and when they are not.↵ | |
56 | //↵ | 55 | //↵ | |
57 | if ( DataTypeByte.this._isNullable) {↵ | 56 | if ( DataTypeInteger.this._isNullable) {↵ | |
58 | // user enters something when field is null↵ | 57 | // user enters something when field is null↵ | |
59 | if (text.equals("<null>")) {↵ | 58 | if (text.equals("<null>")) {↵ | |
60 | if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {↵ | 59 | if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {↵ | |
61 | // delete when null => original value↵ | 60 | // delete when null => original value↵ | |
62 | DataTypeByte.this._textComponent.restoreText();↵ | 61 | DataTypeInteger.this._textComponent.restoreText();↵ | |
63 | e.consume();↵ | 62 | e.consume();↵ | |
64 | }↵ | 63 | }↵ | |
65 | else {↵ | 64 | else {↵ | |
66 | // non-delete when null => clear field and add text↵ | 65 | // non-delete when null => clear field and add text↵ | |
67 | DataTypeByte.this._textComponent.updateText("");↵ | 66 | DataTypeInteger.this._textComponent.updateText("");↵ | |
68 | // fall through to normal processing of this key stroke↵ | 67 | // fall through to normal processing of this key stroke↵ | |
69 | }↵ | 68 | }↵ | |
70 | }↵ | 69 | }↵ | |
71 | else {↵ | 70 | else {↵ | |
72 | // check for user deletes last thing in field↵ | 71 | // check for user deletes last thing in field↵ | |
73 | if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {↵ | 72 | if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {↵ | |
74 | if (text.length() <= 1 ) {↵ | 73 | if (text.length() <= 1 ) {↵ | |
75 | // about to delete last thing in field, so replace with null↵ | 74 | // about to delete last thing in field, so replace with null↵ | |
76 | DataTypeByte.this._textComponent.updateText("<null>");↵ | 75 | DataTypeInteger.this._textComponent.updateText("<null>");↵ | |
77 | e.consume();↵ | 76 | e.consume();↵ | |
78 | }↵ | 77 | }↵ | |
79 | }↵ | 78 | }↵ | |
80 | }↵ | 79 | }↵ | |
81 | }↵ | 80 | }↵ | |
82 | else {↵ | 81 | else {↵ | |
83 | // field is not nullable↵ | 82 | // field is not nullable↵ | |
84 | //↵ | 83 | //↵ | |
85 | handleNotNullableField(text, c, e, _textComponent);↵ | 84 | handleNotNullableField(text, c, e, _textComponent);↵ | |
86 | } | 85 |
| |
See real code fragment | See real code fragment |
Number of common nesting structure subtrees | 1 |
Number of refactorable cases | 0 |
Number of non-refactorable cases | 1 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 6.8 |
Clones location | Clones are in different classes having the same super class |
Number of node comparisons | 123 |
Number of mapped statements | 30 |
Number of unmapped statements in the first code fragment | 2 |
Number of unmapped statements in the second code fragment | 2 |
Time elapsed for statement mapping (ms) | 26.5 |
Clone type | Type 3 |
ID | Statement | ID | Statement | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | char c = e.getKeyChar(); | 1 | char c = e.getKeyChar(); | ||||||||||||||||
2 | JTextComponent _theComponent = (JTextComponent)DataTypeByte.this._textComponent; |
| 2 | JTextComponent _theComponent = (JTextComponent)DataTypeInteger.this._textComponent; | |||||||||||||||
3 | String text = _theComponent.getText(); | 3 | String text = _theComponent.getText(); | ||||||||||||||||
4 | if (!DataTypeByte.this._isSigned && c == '-') |
| 4 | if (!DataTypeInteger.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 (-1 != index) | |||||||||||||||
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); |
| | ||||||||||||||||
14 | _beepHelper.beep(_theComponent); |
| | ||||||||||||||||
|
| 13 | ((IRestorableTextComponent)_theComponent).updateText(text); | ||||||||||||||||
|
| 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 (DataTypeByte.this._scale > 0 && text.length() == DataTypeByte.this._scale && c != KeyEvent.VK_BACK_SPACE && c != KeyEvent.VK_DELETE) |
| 19 | if (DataTypeInteger.this._scale > 0 && text.length() == DataTypeInteger.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 (DataTypeByte.this._isNullable) |
| 22 | if (DataTypeInteger.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 | DataTypeByte.this._textComponent.restoreText(); |
| 25 | DataTypeInteger.this._textComponent.restoreText(); | |||||||||||||||
26 | e.consume(); | 26 | e.consume(); | ||||||||||||||||
else | else | ||||||||||||||||||
27 | DataTypeByte.this._textComponent.updateText(""); |
| 27 | DataTypeInteger.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 | DataTypeByte.this._textComponent.updateText("<null>"); |
| 30 | DataTypeInteger.this._textComponent.updateText("<null>"); | |||||||||||||||
31 | e.consume(); | 31 | e.consume(); | ||||||||||||||||
else | else | ||||||||||||||||||
32 | handleNotNullableField(text, c, e, _textComponent); | 32 | handleNotNullableField(text, c, e, _textComponent); |
Row | Violation |
---|---|
1 | Expression DataTypeByte cannot be unified with expression DataTypeInteger , 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 | Expression DataTypeByte cannot be unified with expression DataTypeInteger , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private boolean _isSigned |
3 | Expression index cannot be parameterized, because it has dependencies to/from statements that will be extracted |
4 | Expression index cannot be parameterized, because it has dependencies to/from statements that will be extracted |
5 | Unmatched statement ((IRestorableTextComponent)_theComponent).updateText(text); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
6 | Unmatched statement _beepHelper.beep(_theComponent); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
7 | Unmatched statement ((IRestorableTextComponent)_theComponent).updateText(text); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
8 | Unmatched statement _beepHelper.beep(_theComponent); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
9 | Expression DataTypeByte cannot be unified with expression DataTypeInteger , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private int _scale |
10 | Expression DataTypeByte cannot be unified with expression DataTypeInteger , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private int _scale |
11 | Expression DataTypeByte cannot be unified with expression DataTypeInteger , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private boolean _isNullable |
12 | Expression DataTypeByte cannot be unified with expression DataTypeInteger , 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 |
13 | Expression DataTypeByte cannot be unified with expression DataTypeInteger , 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 |
14 | Expression DataTypeByte cannot be unified with expression DataTypeInteger , 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 |