Skip to content

Commit

Permalink
Covering case package /* comment */ ....
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisl committed Nov 15, 2021
1 parent a530286 commit 4954abd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,25 @@ private CaretLocation getCaretLocationFromRequest() {
// are we in the package statement?
ts.move(position); // back on the caret position
boolean isPackageStatement = true;
boolean blockComment = false;
int countOfWhitespaces = 0;
while (ts.isValid() && ts.movePrevious() && ts.offset() >= 0 && isPackageStatement) {
Token<GroovyTokenId> t = ts.token();
if (t.id() == GroovyTokenId.LITERAL_package) {
break;
} else if (t.id() == GroovyTokenId.WHITESPACE) {
countOfWhitespaces++;
} else if (t.id() == GroovyTokenId.BLOCK_COMMENT) {
// cases:
// package /* comment */ org.apache.something
// package /* comment */org.apache.something
// package/* comment */org.apache.something
blockComment = true;
} else {
isPackageStatement = (t.id() == GroovyTokenId.DOT || t.id() == GroovyTokenId.IDENTIFIER);
}
}
if (isPackageStatement && countOfWhitespaces == 1) {
if (isPackageStatement && (countOfWhitespaces == 1 || (blockComment && countOfWhitespaces < 3))) {
// we are just behind the package keyword
return CaretLocation.INSIDE_PACKAGE;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package /* a comment */ or
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Code completion result for source line:
package /* a comment */ or|
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
------------------------------------
PACKAGE org null
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.netbeans.modules.groovy.editor.api.completion;

import org.junit.Before;

/**
*
* @author Petr Pisl
Expand All @@ -29,8 +31,8 @@ public PackageKeywordCCTest(String testName) {
}

@Override
protected String getTestType() {
return "package";
protected String getTestType() {
return "package";
}

public void testPackageKeyword01() throws Exception {
Expand All @@ -45,4 +47,8 @@ public void testPackageKeyword03() throws Exception {
checkCompletion(BASE + "PackageKeyword03.groovy", "pac^", true);
}

public void testPackagesCC01() throws Exception {
checkCompletion(BASE + "PackagesCC01.groovy", "package /* a comment */ or^", true);
}

}

0 comments on commit 4954abd

Please sign in to comment.