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)DataTypeTime.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 == 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(); } // handle cases of null // The processing is different when nulls are allowed and when they are not. // if ( DataTypeTime.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 DataTypeTime.this._textComponent.restoreText(); e.consume(); } else { // non-delete when null => clear field and add text DataTypeTime.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 DataTypeTime.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/DataTypeTime.java
Method name: void keyTyped(KeyEvent) Method name: void keyTyped(KeyEvent)
Number of AST nodes: 26 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)DataTypeFloat.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
	               }
16
               }
18
	               else {
17
               else {
19
	                  text = text.substring(0, index) + text.substring(index+1);
18
                  text = text.substring(0, index) + text.substring(index+1);
20
	               }
19
               }
21
	               ((IRestorableTextComponent)_theComponent).updateText( text);
20
               ((IRestorableTextComponent)_theComponent).updateText( text);
22
	               _beepHelper.beep(_theComponent);
21
               _beepHelper.beep(_theComponent);
23
               }
24
               e.consume();
22
               e.consume();
25
            }
23
            }
26
            if ( ! ( Character.isDigit(c) ||
27
               (c == '-') || (c == '+') ||
28
               (c == 'e') || (c == 'E') ||
29
               (c == 'f') || (c == 'F') ||
30
               (c == '.') || (c == ',') ||  // several number formats use '.' as decimal separator, others use ','
31
               (c == KeyEvent.VK_BACK_SPACE) ||
32
               (c == KeyEvent.VK_DELETE) ) ) {
33
            	_beepHelper.beep(_theComponent);
34
               e.consume();
35
            }
36
            // handle cases of null
24
            // handle cases of null
37
            // 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.
38
            //
26
            //
39
            if ( DataTypeFloat.this._isNullable) {
27
            if ( DataTypeTime.this._isNullable) {
40
               // user enters something when field is null
28
               // user enters something when field is null
41
               if (text.equals("<null>")) {
29
               if (text.equals("<null>")) {
42
                  if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
30
                  if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
43
                     // delete when null => original value
31
                     // delete when null => original value
44
                     DataTypeFloat.this._textComponent.restoreText();
32
                     DataTypeTime.this._textComponent.restoreText();
45
                     e.consume();
33
                     e.consume();
46
                  }
34
                  }
47
                  else {
35
                  else {
48
                     // non-delete when null => clear field and add text
36
                     // non-delete when null => clear field and add text
49
                     DataTypeFloat.this._textComponent.updateText("");
37
                     DataTypeTime.this._textComponent.updateText("");
50
                     // fall through to normal processing of this key stroke
38
                     // fall through to normal processing of this key stroke
51
                  }
39
                  }
52
               }
40
               }
53
               else {
41
               else {
54
                  // check for user deletes last thing in field
42
                  // check for user deletes last thing in field
55
                  if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
43
                  if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
56
                     if (text.length() <= 1 ) {
44
                     if (text.length() <= 1 ) {
57
                        // about to delete last thing in field, so replace with null
45
                        // about to delete last thing in field, so replace with null
58
                        DataTypeFloat.this._textComponent.updateText("<null>");
46
                        DataTypeTime.this._textComponent.updateText("<null>");
59
                        e.consume();
47
                        e.consume();
60
                     }
48
                     }
61
                  }
49
                  }
62
               }
50
               }
63
            }
51
            }
64
            else {
52
            else {
65
                    // field is not nullable
53
                    // field is not nullable
66
                    //
54
                    //
67
                    handleNotNullableField(text, c, e, _textComponent);
55
                    handleNotNullableField(text, c, e, _textComponent);
68
            }
56
            }
Summary
Number of common nesting structure subtrees2
Number of refactorable cases0
Number of non-refactorable cases2
Time elapsed for finding largest common nesting structure subtrees (ms)3.6
Clones locationClones are in different classes having the same super class
Number of node comparisons78
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements6
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment5
    Time elapsed for statement mapping (ms)5.5
    Clone typeType 3
    Mapped Statements
    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)
    6
    if (index != -1)
    4
    if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER)
    Differences
    Expression1Expression2Difference
    !=||OPERATOR_MISMATCH
    indexc == KeyEvent.VK_TABINFIX_LEFT_OPERAND_MISMATCH
    -1c == KeyEvent.VK_ENTERINFIX_RIGHT_OPERAND_MISMATCH
    Preondition Violations
    Expression index != -1 cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4
    if (c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER)
                                                              
    5
    int index = text.indexOf(c);
    Preondition Violations
    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
    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();
    Precondition Violations (3)
    Row Violation
    1Expression index != -1 cannot be parameterized, because it has dependencies to/from statements that will be extracted
    2Expression c == KeyEvent.VK_TAB || c == KeyEvent.VK_ENTER cannot be parameterized, because it has dependencies to/from statements that will be extracted
    3Unmatched statement int index=text.indexOf(c); cannot be moved before the extracted code, because it has control dependencies from statements that will be extracted
  2. {Non-refactorable}
    Mapping Summary
    Number of mapped statements14
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)11.3
    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)DataTypeTime.this._textComponent;
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeFloatnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeTimeSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeFloat 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
    JTextComponent _theComponent = (JTextComponent)DataTypeTime.this._textComponent;
    3
    String text = _theComponent.getText();
    3
    String text = _theComponent.getText();
    16
    if (DataTypeFloat.this._isNullable)
    16
    if (DataTypeFloat.this._isNullable)
    12
    if (DataTypeTime.this._isNullable)
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeFloatnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeTimeSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeFloat 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
    12
    if (DataTypeTime.this._isNullable)
    17
    if (text.equals("<null>"))
    13
    if (text.equals("<null>"))
    18
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    14
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    19
    DataTypeFloat.this._textComponent.restoreText();
    19
    DataTypeFloat.this._textComponent.restoreText();
    15
    DataTypeTime.this._textComponent.restoreText();
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeFloatnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeTimeSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeFloat 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
    15
    DataTypeTime.this._textComponent.restoreText();
    20
    e.consume();
    16
    e.consume();
    else
    else
    21
    DataTypeFloat.this._textComponent.updateText("");
    21
    DataTypeFloat.this._textComponent.updateText("");
    17
    DataTypeTime.this._textComponent.updateText("");
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeFloatnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeTimeSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeFloat 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
    17
    DataTypeTime.this._textComponent.updateText("");
    else
    else
    22
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    18
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    23
    if (text.length() <= 1)
    19
    if (text.length() <= 1)
    24
    DataTypeFloat.this._textComponent.updateText("<null>");
    24
    DataTypeFloat.this._textComponent.updateText("<null>");
    20
    DataTypeTime.this._textComponent.updateText("<null>");
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeFloatnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeTimeSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeFloat 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
    20
    DataTypeTime.this._textComponent.updateText("<null>");
    25
    e.consume();
    21
    e.consume();
    else
    else
    26
    handleNotNullableField(text, c, e, _textComponent);
    22
    handleNotNullableField(text, c, e, _textComponent);
    Precondition Violations (6)
    Row Violation
    1Expression DataTypeFloat 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
    2Expression DataTypeFloat 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
    3Expression DataTypeFloat 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
    4Expression DataTypeFloat 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
    5Expression DataTypeFloat 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
    6Clone fragment #1 returns variables c, text, _theComponent , while Clone fragment #2 returns variables c, text, _theComponent