Java completion: handle cases when no completion could be done.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Fri, 27 Mar 2015 18:15:33 +0000
changeset 449 5c253d838e86
parent 448 cc62f655db88
child 450 8b0bf216cc64
Java completion: handle cases when no completion could be done. Such a situation is reported by throwing an InvalidCursorLocation. Handle it and return an empty result if this situation happens.
SmallSense__JavaCompletionEngine.st
--- a/SmallSense__JavaCompletionEngine.st	Tue Mar 10 10:08:49 2015 +0000
+++ b/SmallSense__JavaCompletionEngine.st	Fri Mar 27 18:15:33 2015 +0000
@@ -166,7 +166,6 @@
 
     source := JAVA stx libjava tools Source new.
     source setContents: textView list asStringWithoutEmphasis.
-"/    parser := JAVA stx libjava tools parser Parser new.
     rslt := JAVA org eclipse jdt internal compiler CompilationResult
                 new: source _: 1 _: 1 _: 1000.  
     problemReporter := JAVA org eclipse jdt internal compiler problem ProblemReporter
@@ -176,9 +175,11 @@
 
     parser := JAVA org eclipse jdt internal codeassist complete CompletionParser 
                 new: problemReporter _: true.
-
-"/    tree := parser parse: source diet: true resolve: true.
-    tree := parser dietParse: source _: rslt _: position - 1"Java is 0-based" - 1"cursor is actualy one fter the end of token".
+    [
+        tree := parser dietParse: source _: rslt _: position - 1"Java is 0-based" - 1"cursor is actualy one fter the end of token".
+    ] on: JAVA org eclipse jdt internal codeassist complete InvalidCursorLocation do:[:icl |
+        ^ result
+    ].
     searcher := JAVA org eclipse jdt core dom NodeSearcher new: position - 1"Java is 0-based" - 1"cursor is actualy one fter the end of token".
     tree traverse: searcher _: tree scope.
     (searcher found notNil and:[searcher found isKindOf: JAVA org eclipse jdt internal compiler ast AbstractMethodDeclaration]) ifTrue:[ 
@@ -209,6 +210,13 @@
     ^ result
 
     "Created: / 02-10-2013 / 13:55:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 12-02-2015 / 00:13:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (comment): / 27-03-2015 / 18:09:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!JavaCompletionEngine class methodsFor:'documentation'!
+
+version_HG
+
+    ^ '$Changeset: <not expanded> $'
+! !
+