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