--- a/SmallSense__JavaEditSupport.st Wed Jan 22 12:52:34 2014 +0000
+++ b/SmallSense__JavaEditSupport.st Wed Jan 22 21:54:51 2014 +0000
@@ -49,67 +49,82 @@
!JavaEditSupport methodsFor:'editing'!
-insertElectricSnippet
- | tokens lastToken0 |
+electricInsertSnippet
+ | tokens lastToken0 |
tokens := self scanLineAtCursor.
- tokens isEmptyOrNil ifTrue:[ ^ false ].
- lastToken0 := tokens at: (tokens size - 3).
- lastToken0 = 'Error' ifTrue:[ ^ false ].
- (tokens last > service textView cursorCol) ifTrue:[ ^ false ].
-
+ tokens isEmptyOrNil ifTrue:[
+ ^ false
+ ].
+ lastToken0 := tokens at:(tokens size - 3).
+ lastToken0 = 'Error' ifTrue:[
+ ^ false
+ ].
+ (tokens last > service textView cursorCol) ifTrue:[
+ ^ false
+ ].
+
"/ Insert try { ... }
+
lastToken0 == #try ifTrue:[
- (tokens size == 4 or:[(tokens size > 4) and:[(tokens at: tokens size -7) ~~ $.]]) ifTrue:[
- self insertElectricBlockOpenedBy: ' {' closedBy: '}'.
- ^ true.
- ]
+ (tokens size == 4
+ or:[ (tokens size > 4) and:[ (tokens at:tokens size - 7) ~~ $. ] ])
+ ifTrue:[
+ self electricInsertBlockOpenedBy:' {' closedBy:'}'.
+ ^ true.
+ ]
].
-
+
"/ Insert catch ( ) { ... }
+
lastToken0 == #catch ifTrue:[
- (tokens size > 4 and:[(tokens at: tokens size -7) == $}]) ifTrue:[
- | cursorLine cursorCol |
+ (tokens size > 4 and:[ (tokens at:tokens size - 7) == $} ]) ifTrue:[
+ | cursorLine cursorCol |
+
cursorLine := service textView cursorLine.
cursorCol := service textView cursorCol.
- self insertElectricBlockOpenedBy: ' ( ) {' closedBy: '}'.
- service textView cursorLine: cursorLine col: cursorCol + 3.
+ self electricInsertBlockOpenedBy:' ( ) {' closedBy:'}'.
+ service textView cursorLine:cursorLine col:cursorCol + 3.
^ true.
].
].
-
+
"/ Insert finally { ... }
+
lastToken0 == #finally ifTrue:[
- (tokens size > 4 and:[(tokens at: tokens size -7) == $}]) ifTrue:[
- self insertElectricBlockOpenedBy: ' {' closedBy: '}'.
+ (tokens size > 4 and:[ (tokens at:tokens size - 7) == $} ]) ifTrue:[
+ self electricInsertBlockOpenedBy:' {' closedBy:'}'.
^ true.
].
].
-
+
"/ Insert if/while/synchronized ( ) { ... }
- (#(if while synchronized) includes: lastToken0) ifTrue:[
+
+ (#( #if #while #synchronized ) includes:lastToken0) ifTrue:[
(tokens size = 4) ifTrue:[
- | cursorLine cursorCol |
+ | cursorLine cursorCol |
+
cursorLine := service textView cursorLine.
cursorCol := service textView cursorCol.
- self insertElectricBlockOpenedBy: ' ( ) {' closedBy: '}'.
- service textView cursorLine: cursorLine col: cursorCol + 3.
+ self electricInsertBlockOpenedBy:' ( ) {' closedBy:'}'.
+ service textView cursorLine:cursorLine col:cursorCol + 3.
^ true.
].
].
-
+
"/ Insert for ( ; ; ) { ... }
+
(lastToken0 == #for) ifTrue:[
(tokens size = 4) ifTrue:[
- | cursorLine cursorCol |
+ | cursorLine cursorCol |
+
cursorLine := service textView cursorLine.
cursorCol := service textView cursorCol.
- self insertElectricBlockOpenedBy: ' ( ; ; ) {' closedBy: '}'.
- service textView cursorLine: cursorLine col: cursorCol + 3.
+ self electricInsertBlockOpenedBy:' ( ; ; ) {' closedBy:'}'.
+ service textView cursorLine:cursorLine col:cursorCol + 3.
^ true.
].
].
-
^ false
"Created: / 22-10-2013 / 01:53:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -139,7 +154,7 @@
].
key == Character space ifTrue:[
- ^ self insertElectricSnippet
+ ^ self electricInsertSnippet
].
^ false
@@ -158,7 +173,7 @@
(i ~~ 0 and:[service codeView cursorCol < i]) ifTrue:[
^ false. ].
] ifFalse:[
- self insertElectricBlockOpenedBy: '{' closedBy: '}'.
+ self electricInsertBlockOpenedBy:'{' closedBy:'}'.
^ true
].
@@ -172,13 +187,13 @@
(column between: (tokens at: i + 2) and: (tokens at: i + 3)) ifTrue:[
(tokens at: i) == #String ifTrue:[ ^ false ].
- self insertElectricBlockOpenedBy: '{' closedBy: '}'.
+ self electricInsertBlockOpenedBy:'{' closedBy:'}'.
^ true.
].
].
].
- self insertElectricBlockOpenedBy: '{' closedBy: '}'.
+ self electricInsertBlockOpenedBy:'{' closedBy:'}'.
^ true
"Created: / 04-08-2013 / 01:54:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"