#KT-2981 Fixed Show deprecated items after not deprecated in completion list

This commit is contained in:
Natalia.Ukhorskaya
2012-10-23 13:21:59 +04:00
parent a79a31cf01
commit 37288a337b
4 changed files with 65 additions and 1 deletions
@@ -0,0 +1,52 @@
/*
* Copyright 2010-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.
*/
package org.jetbrains.jet.plugin.completion.weigher;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementWeigher;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.plugin.completion.JetLookupObject;
class JetAccessibleWeigher extends LookupElementWeigher {
JetAccessibleWeigher() {
super("JetAccessibleWeigher");
}
private enum MyResult {
normal,
deprecated
}
@NotNull
@Override
public MyResult weigh(@NotNull LookupElement element) {
Object object = element.getObject();
if (object instanceof JetLookupObject) {
JetLookupObject lookupObject = (JetLookupObject) object;
DeclarationDescriptor descriptor = lookupObject.getDescriptor();
if (descriptor != null) {
if (KotlinBuiltIns.getInstance().isDeprecated(descriptor)) {
return MyResult.deprecated;
}
}
}
return MyResult.normal;
}
}
@@ -32,7 +32,8 @@ public final class JetCompletionSorting {
CompletionSorter sorter = CompletionSorter.defaultSorter(parameters, result.getPrefixMatcher());
sorter = sorter.weighAfter("negativeStats",
new JetLocalPreferableWeigher(),
new JetExplicitlyImportedWeigher((JetFile)parameters.getOriginalFile()));
new JetExplicitlyImportedWeigher((JetFile)parameters.getOriginalFile()),
new JetAccessibleWeigher());
return result.withRelevanceSorter(sorter);
}
}
@@ -0,0 +1,7 @@
fun foo1() {}
deprecated("Use foo3 instead") fun foo2() {}
fun foo3 {}
fun test() {
<caret>
}
@@ -34,6 +34,10 @@ public class CompletionWeigherTest extends CompletionAutoPopupTestCase {
doTest("va", "val ... = ...", "var ... = ...", "vararg", "values", "variables");
}
public void testDeprecatedFun() {
doTest("foo", "foo1", "foo3", "foo2");
}
public void doTest(String type, @NonNls String... expected) {
new WriteCommandAction(myFixture.getProject(), myFixture.getFile()) {
@Override