be prepared to middle matching with one char prefix

This commit is contained in:
peter
2012-08-28 16:24:51 +02:00
parent b6f42f0385
commit f412b09ef8
24 changed files with 53 additions and 100 deletions
@@ -147,7 +147,7 @@ public class JavaMemberNameCompletionContributor extends CompletionContributor {
}
private static boolean hasStartMatches(Set<LookupElement> set, PrefixMatcher matcher) {
for (LookupElement lookupElement : set) {
if (hasStartMatches(matcher, lookupElement.getAllLookupStrings())) {
if (matcher.isStartMatch(lookupElement)) {
return true;
}
}
@@ -21,9 +21,9 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiKeyword;
import com.intellij.psi.PsiPrimitiveType;
import com.intellij.psi.PsiType;
import org.jetbrains.annotations.NonNls;
import java.util.Collection;
import java.util.LinkedHashSet;
import static com.intellij.patterns.PsiJavaPatterns.psiElement;
import static com.intellij.patterns.StandardPatterns.and;
@@ -38,17 +38,23 @@ public class NullSmartCompletionContributor extends CompletionContributor{
not(psiElement().afterLeaf("."))), new ExpectedTypeBasedCompletionProvider() {
protected void addCompletions(final CompletionParameters parameters,
final CompletionResultSet result, final Collection<ExpectedTypeInfo> infos) {
final boolean empty = result.runRemainingContributors(parameters, true).isEmpty();
if (!StringUtil.startsWithChar(result.getPrefixMatcher().getPrefix(), 'n')) {
return;
}
@NonNls final String prefix = result.getPrefixMatcher().getPrefix();
if (empty && StringUtil.startsWithChar(prefix, 'n')) {
for (final ExpectedTypeInfo info : infos) {
if (!(info.getType() instanceof PsiPrimitiveType)) {
final LookupItem item = (LookupItem)BasicExpressionCompletionContributor.createKeywordLookupItem(parameters.getPosition(), PsiKeyword.NULL);
item.setAttribute(LookupItem.TYPE, PsiType.NULL);
result.addElement(JavaSmartCompletionContributor.decorate(item, infos));
return;
}
LinkedHashSet<CompletionResult> results = result.runRemainingContributors(parameters, true);
for (CompletionResult completionResult : results) {
if (completionResult.isStartMatch()) {
return;
}
}
for (final ExpectedTypeInfo info : infos) {
if (!(info.getType() instanceof PsiPrimitiveType)) {
final LookupItem item = (LookupItem)BasicExpressionCompletionContributor.createKeywordLookupItem(parameters.getPosition(), PsiKeyword.NULL);
item.setAttribute(LookupItem.TYPE, PsiType.NULL);
result.addElement(JavaSmartCompletionContributor.decorate(item, infos));
return;
}
}
}
@@ -1,20 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed 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.
*/
public class A{
public void method(){
boolean x = this i<caret>
boolean x = this ins<caret>
}
}
@@ -1,18 +1,3 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed 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.
*/
public class A{
public void method(){
boolean x = this instanceof <caret>
@@ -1,21 +1,6 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed 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.
*/
public class A{
public void method(){
String str = "";
boolean x = str i<caret>
boolean x = str ins<caret>
}
}
@@ -1,18 +1,3 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed 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.
*/
public class A{
public void method(){
String str = "";
@@ -1,3 +1,3 @@
class Foo {
java.l<caret>
java.la<caret>
}
@@ -3,7 +3,7 @@ public class Bar {
{
int a = 1;
Object java;
java.e<caret>
java.eq<caret>
a = 2;
}
@@ -1,6 +1,6 @@
public class Foo {
{
String s = n<caret>
String s = nu<caret>
}
}
@@ -4,6 +4,6 @@ class A<T>{
void put(String str);
{
put(new A<String>().g<caret>)
put(new A<String>().ge<caret>)
}
}
@@ -4,6 +4,6 @@ class A<T>{
void put(T str);
{
new A<String>().put(new A<String>().g<caret>)
new A<String>().put(new A<String>().ge<caret>)
}
}
@@ -4,6 +4,6 @@ class A{
}
{
String str = new Map<Object, String>().g<caret>
String str = new Map<Object, String>().ge<caret>
}
}
@@ -1,6 +1,6 @@
class Goo {
{
boolean[] ls;
boolean a = ls[<caret>];
boolean[] los;
boolean a = los[<caret>];
}
}
@@ -1,6 +1,6 @@
class Goo {
{
boolean[] ls;
boolean a = l<caret>
boolean[] los;
boolean a = los<caret>
}
}
@@ -3,6 +3,6 @@ class Goo {
{
boolean a = this.a<caret>
boolean a = this.ar<caret>
}
}
@@ -4,7 +4,7 @@ class Foo {
{
Foo[] foos;
Collection<Foo> c = f<caret>
Collection<Foo> c = foo<caret>
}
}
@@ -6,7 +6,7 @@ class Foo implements Bar {
{
Foo[] foos;
Collection<? extends Bar> c = f<caret>
Collection<? extends Bar> c = foo<caret>
}
}
@@ -1,5 +1,5 @@
class Goo {
void foo(boolean... ls) {
boolean a = ls[<caret>];
void foo(boolean... los) {
boolean a = los[<caret>];
}
}
@@ -1,5 +1,5 @@
class Goo {
void foo(boolean... ls) {
boolean a = l<caret>
void foo(boolean... los) {
boolean a = los<caret>
}
}
@@ -5,6 +5,6 @@ class A{
{
int aaa = 0;
foo(a<caret>
foo(aa<caret>
}
}
@@ -589,7 +589,7 @@ public class ListUtils {
public void testFillCommonPrefixOnSecondCompletion() throws Throwable {
configureByFile(getTestName(false) + ".java");
type('g');
type('ge');
complete();
checkResult()
assertStringItems("getBar", "getFoo", "getClass");
@@ -61,4 +61,8 @@ public class CompletionResult {
return new CompletionResult(element, myMatcher, mySorter);
}
public boolean isStartMatch() {
return myMatcher.isStartMatch(myLookupElement);
}
}
@@ -23,6 +23,15 @@ public abstract class PrefixMatcher {
return false;
}
public boolean isStartMatch(LookupElement element) {
for (String s : element.getAllLookupStrings()) {
if (isStartMatch(s)) {
return true;
}
}
return false;
}
public boolean isStartMatch(String name) {
return prefixMatches(name);
}
@@ -279,13 +279,7 @@ public class CompletionServiceImpl extends CompletionService{
}
public static boolean isStartMatch(LookupElement element, Lookup lookup) {
PrefixMatcher itemMatcher = getItemMatcher(element, lookup);
for (String ls : element.getAllLookupStrings()) {
if (itemMatcher.isStartMatch(ls)) {
return true;
}
}
return false;
return getItemMatcher(element, lookup).isStartMatch(element);
}
private static PrefixMatcher getItemMatcher(LookupElement element, Lookup lookup) {