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)DataTypeTimestamp.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(); } // handle cases of null // The processing is different when nulls are allowed and when they are not. // if ( DataTypeTimestamp.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 DataTypeTimestamp.this._textComponent.restoreText(); e.consume(); } else { // non-delete when null => clear field and add text DataTypeTimestamp.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 DataTypeTimestamp.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)DataTypeDate.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(); } // handle cases of null // The processing is different when nulls are allowed and when they are not. // if ( DataTypeDate.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 DataTypeDate.this._textComponent.restoreText(); e.consume(); } else { // non-delete when null => clear field and add text DataTypeDate.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 DataTypeDate.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/DataTypeTimestamp.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: 23 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)DataTypeTimestamp.this._textComponent;
5
				JTextComponent _theComponent = (JTextComponent)DataTypeDate.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 {
19
	                  
18
					}
19
						else {
20
text = text.substring(0, index) + text.substring(index+1);
20
							text = text.substring(0, index) + text.substring(index+1);
21
	               }
21
	
22
	               
22
					}
23
((IRestorableTextComponent)_theComponent).updateText( text);
23
						((IRestorableTextComponent)_theComponent).updateText( text);
24
	               _beepHelper.beep(_theComponent);
24
						_beepHelper.beep(_theComponent);
25
               }
26
               e.consume();
27
            }
28
            
25
					}
26
					e.consume();
27
				}
29
// handle cases of null
28
				// handle cases of null
30
            // 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.
31
            //
32
            
30
				//
33
if ( DataTypeTimestamp.this._isNullable) {
31
				if ( DataTypeDate.this._isNullable) {
34
               // user enters something when field is null
32
					// user enters something when field is null
35
               if (text.equals("<null>")) {
33
					if (text.equals("<null>")) {
36
                  if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
34
						if ((c==KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
37
                     // delete when null => original value
35
							// delete when null => original value
38
                     DataTypeTimestamp.this._textComponent.restoreText();
39
                     e.consume();
40
                  }
41
                  else {
42
                     
36
							DataTypeDate.this._textComponent.restoreText();
37
							e.consume();
38
						}
39
						else {
43
// non-delete when null => clear field and add text
40
							// non-delete when null => clear field and add text
44
                     DataTypeTimestamp.this._textComponent.updateText("");
41
							DataTypeDate.this._textComponent.updateText("");
45
                     // fall through to normal processing of this key stroke
42
							// fall through to normal processing of this key stroke
46
                  }
47
               }
48
               else {
49
                  
43
						}
44
					}
45
					else {
50
// check for user deletes last thing in field
46
						// check for user deletes last thing in field
51
                  if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
47
						if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE)) {
52
                     if (text.length() <= 1 ) {
48
							if (text.length() <= 1 ) {
53
                        // about to delete last thing in field, so replace with null
49
								// about to delete last thing in field, so replace with null
54
                        DataTypeTimestamp.this._textComponent.updateText("<null>");
50
								DataTypeDate.this._textComponent.updateText("<null>");
55
                        e.consume();
56
                     }
57
                  }
58
               }
59
            }
60
            else {
61
                    // field is not nullable
62
                    //
63
                  
51
								e.consume();
52
							}
53
						}
54
					}
55
				}
56
				else {
57
						  // field is not nullable
58
						  //
64
  handleNotNullableField(text, c, e, _textComponent);
59
						  handleNotNullableField(text, c, e, _textComponent);
65
            }
60
				}
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)2.5
Clones locationClones are in different classes having the same super class
Number of node comparisons84
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements23
    Number of unmapped statements in the first code fragment0
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)16.8
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    char c = e.getKeyChar();
    1
    char c = e.getKeyChar();
    2
    JTextComponent _theComponent = (JTextComponent)DataTypeTimestamp.this._textComponent;
    2
    JTextComponent _theComponent = (JTextComponent)DataTypeTimestamp.this._textComponent;
    2
    JTextComponent _theComponent = (JTextComponent)DataTypeDate.this._textComponent;
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeTimestampnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeDateSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeTimestamp 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
    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 (DataTypeTimestamp.this._isNullable)
    13
    if (DataTypeTimestamp.this._isNullable)
    13
    if (DataTypeDate.this._isNullable)
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeTimestampnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeDateSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeTimestamp 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
    13
    if (DataTypeDate.this._isNullable)
    14
    if (text.equals("<null>"))
    14
    if (text.equals("<null>"))
    15
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    15
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    16
    DataTypeTimestamp.this._textComponent.restoreText();
    16
    DataTypeTimestamp.this._textComponent.restoreText();
    16
    DataTypeDate.this._textComponent.restoreText();
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeTimestampnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeDateSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeTimestamp 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
    16
    DataTypeDate.this._textComponent.restoreText();
    17
    e.consume();
    17
    e.consume();
    else
    else
    18
    DataTypeTimestamp.this._textComponent.updateText("");
    18
    DataTypeTimestamp.this._textComponent.updateText("");
    18
    DataTypeDate.this._textComponent.updateText("");
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeTimestampnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeDateSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeTimestamp 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
    18
    DataTypeDate.this._textComponent.updateText("");
    else
    else
    19
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    19
    if ((c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))
    20
    if (text.length() <= 1)
    20
    if (text.length() <= 1)
    21
    DataTypeTimestamp.this._textComponent.updateText("<null>");
    21
    DataTypeTimestamp.this._textComponent.updateText("<null>");
    21
    DataTypeDate.this._textComponent.updateText("<null>");
    Differences
    Expression1Expression2Difference
    net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeTimestampnet.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeDateSUBCLASS_TYPE_MISMATCH
    Preondition Violations
    Expression DataTypeTimestamp 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
    21
    DataTypeDate.this._textComponent.updateText("<null>");
    22
    e.consume();
    22
    e.consume();
    else
    else
    23
    handleNotNullableField(text, c, e, _textComponent);
    23
    handleNotNullableField(text, c, e, _textComponent);
    Precondition Violations (5)
    Row Violation
    1Expression DataTypeTimestamp 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
    2Expression DataTypeTimestamp 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
    3Expression DataTypeTimestamp 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
    4Expression DataTypeTimestamp 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
    5Expression DataTypeTimestamp 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