sdedic commented on a change in pull request #3316:
URL: https://github.com/apache/netbeans/pull/3316#discussion_r749230138



##########
File path: 
groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/KeywordCompletion.java
##########
@@ -98,6 +110,27 @@ public boolean complete(Map<Object, CompletionProposal> 
proposals, CompletionCon
         return true;
     }
 
+    boolean isFirstStatement(final CompletionContext request) {
+        TokenSequence<GroovyTokenId> ts = 
LexUtilities.getGroovyTokenSequence(request.doc, 1);
+
+        if (ts != null) {
+            ts.move(request.lexOffset);
+            if (ts.movePrevious()) {
+                while (ts.isValid() && ts.movePrevious() && ts.offset() >= 0) {
+                    Token<GroovyTokenId> t = ts.token();
+                    if (!(t.id() == GroovyTokenId.NLS || t.id() == 
GroovyTokenId.WHITESPACE 

Review comment:
       This could be moved off to some utilities a a 
`Predicate<Token<GroovyTokenId>>` as I fear that whitespace-traversing code is 
on many places and does not take all the WS/comment tokens into account (see 
for example the package name back traversal code in this PR).

##########
File path: 
groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/completion/KeywordCompletion.java
##########
@@ -98,6 +110,27 @@ public boolean complete(Map<Object, CompletionProposal> 
proposals, CompletionCon
         return true;
     }
 
+    boolean isFirstStatement(final CompletionContext request) {
+        TokenSequence<GroovyTokenId> ts = 
LexUtilities.getGroovyTokenSequence(request.doc, 1);
+
+        if (ts != null) {
+            ts.move(request.lexOffset);
+            if (ts.movePrevious()) {
+                while (ts.isValid() && ts.movePrevious() && ts.offset() >= 0) {

Review comment:
       Nitpick: IMHO ts.offset() >= 0 is redundant on all places -- if 
`movePrevious` had failed bcs there's no previous token, it would return 
`false`; and the 1st token is always at offset 0.
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to