File path: /sql12/fw/src/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeFloat.java | File path: /sql12/fw/src/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDate.java | |||
Method name: void keyTyped(KeyEvent)
|
Method name: void keyTyped(KeyEvent)
|
|||
Number of AST nodes: 26 | Number of AST nodes: 23 | |||
1 | char c = e.getKeyChar();↵ | 1 | char c = e.getKeyChar();↵ | |
2 | // as a coding convenience, create a reference to the text component↵ | 2 | // as a coding convenience, create a reference to the text component↵ | |
3 | // that is typecast to JTextComponent. this is not essential, as we↵ | 3 | // that is typecast to JTextComponent. this is not essential, as we↵ | |
4 | // could typecast every reference, but this makes the code cleaner↵ | 4 | // could typecast every reference, but this makes the code cleaner↵ | |
5 | JTextComponent _theComponent = (JTextComponent)DataTypeFloat.this._textComponent;↵ | 5 | JTextComponent _theComponent = (JTextComponent)DataTypeDate.this._textComponent;↵ | |
6 | String text = _theComponent.getText();↵ | 6 | String text = _theComponent.getText();↵ | |
7 | ↵ | |||
8 | // tabs and newlines get put into the text before this check,↵ | 7 | // tabs and newlines get put into the text before this check,↵ | |
9 | // so remove them↵ | 8 | // so remove them↵ | |
10 | // This only applies to Popup editing since these chars are↵ | 9 | // This only applies to Popup editing since these chars are↵ | |
11 | // not passed to this level by the in-cell editor.↵ | 10 | // not passed to this level by the in-cell editor.↵ | |
12 | if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) {↵ | 11 | if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) {↵ | |
13 | // remove all instances of the offending char↵ | 12 | // remove all instances of the offending char↵ | |
14 | int index = text.indexOf(c);↵ | 13 | int index = text.indexOf(c);↵ | |
15 | if (index != -1) {↵ | 14 | if (index != -1) {↵ | |
16 | if (index == text.length() -1) {↵ | 15 | if (index == text.length() -1) {↵ | |
17 | text = text.substring(0, text.length()-1); // truncate string↵ | 16 | text = text.substring(0, text.length()-1); // truncate string↵ | |
18 | }↵ | 17 | ↵ | |
19 | else {↵ | |||
20 | ↵ | 18 | }↵ | |
19 | else {↵ | |||
21 | text = text.substring(0, index) + text.substring(index+1);↵ | 20 | text = text.substring(0, index) + text.substring(index+1);↵ | |
22 | }↵ | 21 | ↵ | |
23 | ↵ | 22 | }↵ | |
24 | ((IRestorableTextComponent)_theComponent).updateText( text);↵ | 23 | ((IRestorableTextComponent)_theComponent).updateText( text);↵ | |
25 | _beepHelper.beep(_theComponent);↵ | 24 | _beepHelper.beep(_theComponent);↵ | |
26 | }↵ | |||
27 | e.consume();↵ | |||
28 | }↵ | |||
29 | if ( ! ( Character.isDigit(c) ||↵ | |||
30 | (c == '-') || (c == '+') ||↵ | |||
31 | (c == 'e') || (c == 'E') ||↵ | |||
32 | (c == 'f') || (c == 'F') ||↵ | |||
33 | (c == '.') || (c == ',') || // several number formats use '.' as decimal separator, others use ','↵ | |||
34 | (c == KeyEvent.VK_BACK_SPACE) ||↵ | |||
35 | (c == KeyEvent.VK_DELETE) ) ) {↵ | |||
36 | _beepHelper.beep(_theComponent);↵ | |||
37 | e.consume();↵ | |||
38 | }↵ | |||
39 | ↵ | 25 | }↵ | |
26 | e.consume();↵ | |||
27 | }↵ | |||
40 | // handle cases of null↵ | 28 | // handle cases of null↵ | |
41 | // The processing is different when nulls are allowed and when they are not.↵ | 29 | // The processing is different when nulls are allowed and when they are not.↵ | |
42 | //↵ | |||
43 | ↵ | 30 | //↵ | |
44 | if ( DataTypeFloat.this._isNullable) {↵ | 31 | if ( DataTypeDate.this._isNullable) {↵ | |
45 | // user enters something when field is null↵ | 32 | // user enters something when field is null↵ | |
46 | if (text.equals("<null>")) {↵ | 33 | if (text.equals("<null>")) {↵ | |
47 | if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {↵ | 34 | if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {↵ | |
48 | // delete when null => original value↵ | 35 | // delete when null => original value↵ | |
49 | DataTypeFloat.this._textComponent.restoreText();↵ | 36 | DataTypeDate.this._textComponent.restoreText();↵ | |
50 | e.consume();↵ | |||
51 | }↵ | |||
52 | else {↵ | |||
53 | ↵ | 37 | e.consume();↵ | |
38 | }↵ | |||
39 | else {↵ | |||
54 | // non-delete when null => clear field and add text↵ | 40 | // non-delete when null => clear field and add text↵ | |
55 | DataTypeFloat.this._textComponent.updateText("");↵ | 41 | DataTypeDate.this._textComponent.updateText("");↵ | |
56 | // fall through to normal processing of this key stroke↵ | 42 | // fall through to normal processing of this key stroke↵ | |
57 | }↵ | |||
58 | }↵ | |||
59 | else {↵ | |||
60 | ↵ | 43 | }↵ | |
44 | }↵ | |||
45 | else {↵ | |||
61 | // check for user deletes last thing in field↵ | 46 | // check for user deletes last thing in field↵ | |
62 | if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {↵ | 47 | if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {↵ | |
63 | if (text.length() <= 1 ) {↵ | 48 | if (text.length() <= 1 ) {↵ | |
64 | // about to delete last thing in field, so replace with null↵ | 49 | // about to delete last thing in field, so replace with null↵ | |
65 | DataTypeFloat.this._textComponent.updateText("<null>");↵ | 50 | DataTypeDate.this._textComponent.updateText("<null>");↵ | |
66 | e.consume();↵ | |||
67 | }↵ | |||
68 | }↵ | |||
69 | }↵ | |||
70 | }↵ | |||
71 | else {↵ | |||
72 | // field is not nullable↵ | |||
73 | //↵ | |||
74 | ↵ | 51 | e.consume();↵ | |
52 | }↵ | |||
53 | }↵ | |||
54 | }↵ | |||
55 | }↵ | |||
56 | else {↵ | |||
57 | // field is not nullable↵ | |||
58 | //↵ | |||
75 | handleNotNullableField(text, c, e, _textComponent);↵ | 59 | handleNotNullableField(text, c, e, _textComponent);↵ | |
76 | } | 60 | } | |
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) | 2.8 |
Clones location | Clones are in different classes having the same super class |
Number of node comparisons | 86 |
Number of mapped statements | 23 |
Number of unmapped statements in the first code fragment | 3 |
Number of unmapped statements in the second code fragment | 0 |
Time elapsed for statement mapping (ms) | 18.4 |
Clone type | Type 3 |
ID | Statement | ID | Statement | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | char c = e.getKeyChar(); | 1 | char c = e.getKeyChar(); | ||||||||||||
2 | JTextComponent _theComponent = (JTextComponent)DataTypeFloat.this._textComponent; |
| 2 | JTextComponent _theComponent = (JTextComponent)DataTypeDate.this._textComponent; | |||||||||||
3 | String text = _theComponent.getText(); | 3 | String text = _theComponent.getText(); | ||||||||||||
4 | if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) | 4 | if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER) | ||||||||||||
5 | int index = text.indexOf(c); | 5 | int index = text.indexOf(c); | ||||||||||||
6 | if (index != -1) | 6 | if (index != -1) | ||||||||||||
7 | if (index == text.length() - 1) | 7 | if (index == text.length() - 1) | ||||||||||||
8 | text = text.substring(0, text.length() - 1); | 8 | text = text.substring(0, text.length() - 1); | ||||||||||||
else | else | ||||||||||||||
9 | text = text.substring(0, index) + text.substring(index + 1); | 9 | text = text.substring(0, index) + text.substring(index + 1); | ||||||||||||
10 | ((IRestorableTextComponent)_theComponent).updateText(text); | 10 | ((IRestorableTextComponent)_theComponent).updateText(text); | ||||||||||||
11 | _beepHelper.beep(_theComponent); | 11 | _beepHelper.beep(_theComponent); | ||||||||||||
12 | e.consume(); | 12 | e.consume(); | ||||||||||||
13 | if (!(Character.isDigit(c) || (c == '-') || (c == '+') || (c == 'e') || (c == 'E') || (c == 'f') || (c == 'F') || (c == '.') || (c == ',') || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))) |
| | ||||||||||||
14 | _beepHelper.beep(_theComponent); |
| | ||||||||||||
15 | e.consume(); | | |||||||||||||
16 | if (DataTypeFloat.this._isNullable) |
| 13 | if (DataTypeDate.this._isNullable) | |||||||||||
17 | if (text.equals("<null>")) | 14 | if (text.equals("<null>")) | ||||||||||||
18 | if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) | 15 | if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) | ||||||||||||
19 | DataTypeFloat.this._textComponent.restoreText(); |
| 16 | DataTypeDate.this._textComponent.restoreText(); | |||||||||||
20 | e.consume(); | 17 | e.consume(); | ||||||||||||
else | else | ||||||||||||||
21 | DataTypeFloat.this._textComponent.updateText(""); |
| 18 | DataTypeDate.this._textComponent.updateText(""); | |||||||||||
else | else | ||||||||||||||
22 | if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) | 19 | if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) | ||||||||||||
23 | if (text.length() <= 1) | 20 | if (text.length() <= 1) | ||||||||||||
24 | DataTypeFloat.this._textComponent.updateText("<null>"); |
| 21 | DataTypeDate.this._textComponent.updateText("<null>"); | |||||||||||
25 | e.consume(); | 22 | e.consume(); | ||||||||||||
else | else | ||||||||||||||
26 | handleNotNullableField(text, c, e, _textComponent); | 23 | handleNotNullableField(text, c, e, _textComponent); |
Row | Violation |
---|---|
1 | Expression DataTypeFloat cannot be unified with expression DataTypeDate , 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 | Unmatched statement if(!(Character.isDigit(c) || (c == '-') || (c == '+')|| (c == 'e')|| (c == 'E')|| (c == 'f')|| (c == 'F')|| (c == '.')|| (c == ',')|| (c == KeyEvent.VK_BACK_SPACE)|| (c == KeyEvent.VK_DELETE))) cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
3 | 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 |
4 | Expression DataTypeFloat cannot be unified with expression DataTypeDate , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.BaseDataTypeComponent does not declare member(s) private boolean _isNullable |
5 | Expression DataTypeFloat cannot be unified with expression DataTypeDate , 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 |
6 | Expression DataTypeFloat cannot be unified with expression DataTypeDate , 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 |
7 | Expression DataTypeFloat cannot be unified with expression DataTypeDate , 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 |