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)DataTypeFloat.this._textComponent; String text = _theComponent.getText(); // 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 == '+') || (c == 'e') || (c == 'E') || (c == 'f') || (c == 'F') || (c == '.') || (c == ',') || // several number formats use '.' as decimal separator, others use ',' (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE) ) ) { _beepHelper.beep(_theComponent); e.consume(); } // handle cases of null // The processing is different when nulls are allowed and when they are not. // if ( DataTypeFloat.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 DataTypeFloat.this._textComponent.restoreText(); e.consume(); } else { // non-delete when null => clear field and add text DataTypeFloat.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 DataTypeFloat.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)DataTypeDouble.this._textComponent; String text = _theComponent.getText(); // 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 == '+') || (c == 'e') || (c == 'E') || (c == 'f') || (c == 'F') || (c == 'd') || (c == 'D') || (c == '.') || (c == ',') || // several number formats use '.' as decimal separator, others use ',' (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE) ) ) { _beepHelper.beep(_theComponent); e.consume(); } // handle cases of null // The processing is different when nulls are allowed and when they are not. // if ( DataTypeDouble.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 DataTypeDouble.this._textComponent.restoreText(); e.consume(); } else { // non-delete when null => clear field and add text DataTypeDouble.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 DataTypeDouble.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/DataTypeFloat.java File path: /sql12/fw/src/net/sourceforge/squirrel_sql/fw/datasetviewer/cellcomponent/DataTypeDouble.java
Method name: void keyTyped(KeyEvent) Method name: void keyTyped(KeyEvent)
Number of AST nodes: 26 Number of AST nodes: 26
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)DataTypeDouble.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) {
14
               if (index != -1) {
15
	               if (index == text.length() -1) {
15
	               if (index == text.length() -1) {
16
	                  text = text.substring(0, text.length()-1);	// truncate string
16
	                  text = text.substring(0, text.length()-1);	// truncate string
17
	               }
17
	               }
18
	               else {
18
	               else {
19
	                  text = text.substring(0, index) + text.substring(index+1);
19
	                  text = text.substring(0, index) + text.substring(index+1);
20
	               }
20
	               }
21
	               ((IRestorableTextComponent)_theComponent).updateText( text);
21
	               ((IRestorableTextComponent)_theComponent).updateText( text);
22
	               _beepHelper.beep(_theComponent);
22
	               _beepHelper.beep(_theComponent);
23
               }
23
               }
24
               e.consume();
24
               e.consume();
25
            }
25
            }
26
            if ( ! ( Character.isDigit(c) ||
26
            if ( ! ( Character.isDigit(c) ||
27
               (c == '-') || (c == '+') ||
27
               (c == '-') || (c == '+') ||
28
               (c == 'e') || (c == 'E') ||
28
               (c == 'e') || (c == 'E') ||
29
               (c == 'f') || (c == 'F') ||
29
               (c == 'f') || (c == 'F') ||
30
               (c == 'd') || (c == 'D') ||
30
               (c == '.') || (c == ',') ||  // several number formats use '.' as decimal separator, others use ','
31
               (c == '.') || (c == ',') ||  // several number formats use '.' as decimal separator, others use ','
31
               (c == KeyEvent.VK_BACK_SPACE) ||
32
               (c == KeyEvent.VK_BACK_SPACE) ||
32
               (c == KeyEvent.VK_DELETE) ) ) {
33
               (c == KeyEvent.VK_DELETE) ) ) {
33
            	_beepHelper.beep(_theComponent);
34
            	_beepHelper.beep(_theComponent);
34
               e.consume();
35
               e.consume();
35
            }
36
            }
36
            // handle cases of null
37
            // handle cases of null
37
            // The processing is different when nulls are allowed and when they are not.
38
            // The processing is different when nulls are allowed and when they are not.
38
            //
39
            //
39
            if ( DataTypeFloat.this._isNullable) {
40
            if ( DataTypeDouble.this._isNullable) {
40
               // user enters something when field is null
41
               // user enters something when field is null
41
               if (text.equals("<null>")) {
42
               if (text.equals("<null>")) {
42
                  if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
43
                  if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
43
                     // delete when null => original value
44
                     // delete when null => original value
44
                     DataTypeFloat.this._textComponent.restoreText();
45
                     DataTypeDouble.this._textComponent.restoreText();
45
                     e.consume();
46
                     e.consume();
46
                  }
47
                  }
47
                  else {
48
                  else {
48
                     // non-delete when null => clear field and add text
49
                     // non-delete when null => clear field and add text
49
                     DataTypeFloat.this._textComponent.updateText("");
50
                     DataTypeDouble.this._textComponent.updateText("");
50
                     // fall through to normal processing of this key stroke
51
                     // fall through to normal processing of this key stroke
51
                  }
52
                  }
52
               }
53
               }
53
               else {
54
               else {
54
                  // check for user deletes last thing in field
55
                  // check for user deletes last thing in field
55
                  if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
56
                  if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
56
                     if (text.length() <= 1 ) {
57
                     if (text.length() <= 1 ) {
57
                        // about to delete last thing in field, so replace with null
58
                        // about to delete last thing in field, so replace with null
58
                        DataTypeFloat.this._textComponent.updateText("<null>");
59
                        DataTypeDouble.this._textComponent.updateText("<null>");
59
                        e.consume();
60
                        e.consume();
60
                     }
61
                     }
61
                  }
62
                  }
62
               }
63
               }
63
            }
64
            }
64
            else {
65
            else {
65
                    // field is not nullable
66
                    // field is not nullable
66
                    //
67
                    //
67
                    handleNotNullableField(text, c, e, _textComponent);
68
                    handleNotNullableField(text, c, e, _textComponent);
68
            }
69
            }
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)4.2
Clones locationClones are in different classes having the same super class
Number of node comparisons95
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements26
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)21.2
    Clone typeType 2
    Mapped Statements
    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)DataTypeFloat.this._textComponent;
    2
    JTextComponent _theComponent = (JTextComponent)DataTypeDouble.this._textComponent;
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeFloatnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeDoubleSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeFloat cannot be unified with expression DataTypeDouble , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.FloatingPointBase does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    2
    JTextComponent _theComponent = (JTextComponent)DataTypeDouble.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)))
    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)))
    13
    if (!(Character.isDigit(c) || (c == '-') || (c == '+') || (c == 'e') || (c == 'E') || (c == 'f') || (c == 'F') || (c == 'd') || (c == 'D') || (c == '.') || (c == ',') || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)))
    Differences
    Expression1Expression2Difference
    Character.isDigit(c) || (c == '-') || (c == '+')|| (c == 'e')|| (c == 'E')|| (c == 'f')|| (c == 'F')|| (c == '.')|| (c == ',')|| (c == KeyEvent.VK_BACK_SPACE)|| (c == KeyEvent.VK_DELETE)Character.isDigit(c) || (c == '-') || (c == '+')|| (c == 'e')|| (c == 'E')|| (c == 'f')|| (c == 'F')|| (c == 'd')|| (c == 'D')|| (c == '.')|| (c == ',')|| (c == KeyEvent.VK_BACK_SPACE)|| (c == KeyEvent.VK_DELETE)INFIX_EXTENDED_OPERAND_NUMBER_MISMATCH
    Preondition Violations
    Expression 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 parameterized, because it has dependencies to/from statements that will be extracted
    Expression Character.isDigit(c) || (c == '-') || (c == '+')|| (c == 'e')|| (c == 'E')|| (c == 'f')|| (c == 'F')|| (c == 'd')|| (c == 'D')|| (c == '.')|| (c == ',')|| (c == KeyEvent.VK_BACK_SPACE)|| (c == KeyEvent.VK_DELETE) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13
    if (!(Character.isDigit(c) || (c == '-') || (c == '+') || (c == 'e') || (c == 'E') || (c == 'f') || (c == 'F') || (c == 'd') || (c == 'D') || (c == '.') || (c == ',') || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)))
    14
    _beepHelper.beep(_theComponent);
    14
    _beepHelper.beep(_theComponent);
    15
    e.consume();
    15
    e.consume();
    16
    if (DataTypeFloat.this._isNullable)
    16
    if (DataTypeFloat.this._isNullable)
    16
    if (DataTypeDouble.this._isNullable)
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeFloatnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeDoubleSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeFloat cannot be unified with expression DataTypeDouble , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.FloatingPointBase does not declare member(s) private boolean _isNullable
    16
    if (DataTypeDouble.this._isNullable)
    17
    if (text.equals("<null>"))
    17
    if (text.equals("<null>"))
    18
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    18
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    19
    DataTypeFloat.this._textComponent.restoreText();
    19
    DataTypeFloat.this._textComponent.restoreText();
    19
    DataTypeDouble.this._textComponent.restoreText();
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeFloatnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeDoubleSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeFloat cannot be unified with expression DataTypeDouble , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.FloatingPointBase does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    19
    DataTypeDouble.this._textComponent.restoreText();
    20
    e.consume();
    20
    e.consume();
    else
    else
    21
    DataTypeFloat.this._textComponent.updateText("");
    21
    DataTypeFloat.this._textComponent.updateText("");
    21
    DataTypeDouble.this._textComponent.updateText("");
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeFloatnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeDoubleSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeFloat cannot be unified with expression DataTypeDouble , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.FloatingPointBase does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    21
    DataTypeDouble.this._textComponent.updateText("");
    else
    else
    22
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    22
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    23
    if (text.length() <= 1)
    23
    if (text.length() <= 1)
    24
    DataTypeFloat.this._textComponent.updateText("<null>");
    24
    DataTypeFloat.this._textComponent.updateText("<null>");
    24
    DataTypeDouble.this._textComponent.updateText("<null>");
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeFloatnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeDoubleSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeFloat cannot be unified with expression DataTypeDouble , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.FloatingPointBase does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    24
    DataTypeDouble.this._textComponent.updateText("<null>");
    25
    e.consume();
    25
    e.consume();
    else
    else
    26
    handleNotNullableField(text, c, e, _textComponent);
    26
    handleNotNullableField(text, c, e, _textComponent);
    Precondition Violations (7)
    Row Violation
    1Expression DataTypeFloat cannot be unified with expression DataTypeDouble , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.FloatingPointBase does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    2Expression 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 parameterized, because it has dependencies to/from statements that will be extracted
    3Expression Character.isDigit(c) || (c == '-') || (c == '+')|| (c == 'e')|| (c == 'E')|| (c == 'f')|| (c == 'F')|| (c == 'd')|| (c == 'D')|| (c == '.')|| (c == ',')|| (c == KeyEvent.VK_BACK_SPACE)|| (c == KeyEvent.VK_DELETE) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Expression DataTypeFloat cannot be unified with expression DataTypeDouble , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.FloatingPointBase does not declare member(s) private boolean _isNullable
    5Expression DataTypeFloat cannot be unified with expression DataTypeDouble , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.FloatingPointBase does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    6Expression DataTypeFloat cannot be unified with expression DataTypeDouble , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.FloatingPointBase does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent
    7Expression DataTypeFloat cannot be unified with expression DataTypeDouble , because common superclass net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.FloatingPointBase does not declare member(s) private net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.IRestorableTextComponent _textComponent