-
Notifications
You must be signed in to change notification settings - Fork 935
[NETBEANS-6196] Package code completion doesn't work in empty groovy … #3316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,7 +82,19 @@ public boolean complete(Map<Object, CompletionProposal> proposals, CompletionCon | |
| // filter-out keywords in a step-by-step approach | ||
| filterPackageStatement(havePackage); | ||
| filterPrefix(prefix); | ||
| filterLocation(request.location); | ||
| if (keywords.contains(GroovyKeyword.KEYWORD_package) && isFirstStatement(request)) { | ||
| // This is a hack for offering package keyword in the script as the first statement. | ||
| // The current implementation use INSIDE_LOCATION for the top context in script, which is OK, | ||
| // but package is only above class keyword and will not be displayed here. | ||
| // This covers case, when you have empty file and you want to write package as the first. | ||
| filterLocation(request.location); | ||
| if (!keywords.contains(GroovyKeyword.KEYWORD_package)) { | ||
| // the package is only above class keyword, but on the first position we should offer it | ||
| keywords.add(GroovyKeyword.KEYWORD_package); | ||
| } | ||
| } else { | ||
| filterLocation(request.location); | ||
| } | ||
| filterClassInterfaceOrdering(request.context); | ||
| filterMethodDefinitions(request.context); | ||
| filterKeywordsNextToEachOther(request.context); | ||
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be moved off to some utilities a a Edit: correction - there's some support already: see findPreviousNonWsNonComment, so maybe
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is good idea. Do you want to do it in this PR?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps yes, but a possible retrofit of other code (that should use the helper instead of custom WS token checks) should be perhaps done separately. Your call. |
||
| || t.id() == GroovyTokenId.SH_COMMENT || t.id() == GroovyTokenId.SL_COMMENT | ||
| || t.id() == GroovyTokenId.BLOCK_COMMENT || t.id() == GroovyTokenId.LINE_COMMENT)) { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| boolean checkForPackageStatement(final CompletionContext request) { | ||
| TokenSequence<GroovyTokenId> ts = LexUtilities.getGroovyTokenSequence(request.doc, 1); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pac |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Code completion result for source line: | ||
| pac| | ||
| (QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) | ||
| ------------------------------------ | ||
| CLASS Package null | ||
| CLASS PackageKeyword01 null | ||
| KEYWORD package null |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pac | ||
|
|
||
| class AA { | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Code completion result for source line: | ||
| pac| | ||
| (QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) | ||
| ------------------------------------ | ||
| CLASS Package null | ||
| CLASS PackageKeyword02 null | ||
| KEYWORD package null |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| /** | ||
| comment | ||
| */ | ||
|
|
||
| pac |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Code completion result for source line: | ||
| pac| | ||
| (QueryType=COMPLETION, prefixSearch=true, caseSensitive=true) | ||
| ------------------------------------ | ||
| CLASS Package null | ||
| CLASS PackageKeyword03 null | ||
| KEYWORD package null |
| 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 |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.netbeans.modules.groovy.editor.api.completion; | ||
|
|
||
| import org.junit.Before; | ||
|
|
||
| /** | ||
| * | ||
| * @author Petr Pisl | ||
| */ | ||
| public class PackageKeywordCCTest extends GroovyCCTestBase { | ||
|
|
||
| public PackageKeywordCCTest(String testName) { | ||
| super(testName); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getTestType() { | ||
| return "package"; | ||
| } | ||
|
|
||
| public void testPackageKeyword01() throws Exception { | ||
| checkCompletion(BASE + "PackageKeyword01.groovy", "pac^", true); | ||
| } | ||
|
|
||
| public void testPackageKeyword02() throws Exception { | ||
| checkCompletion(BASE + "PackageKeyword02.groovy", "pac^", true); | ||
| } | ||
|
|
||
| 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); | ||
| } | ||
|
|
||
| } |
Uh oh!
There was an error while loading. Please reload this page.