mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Properties should be before accessors in completion, current class members are more relevant than superclass members
This commit is contained in:
@@ -236,8 +236,13 @@
|
||||
<completion.confidence language="Groovy" implementationClass="org.jetbrains.plugins.groovy.lang.completion.GroovyCompletionConfidence" id="groovyAdvanced" order="after groovyNameIdentifier"/>
|
||||
<completion.confidence language="Groovy" implementationClass="com.intellij.codeInsight.completion.UnfocusedComments" id="groovyComments"/>
|
||||
<completion.confidence language="Groovy" implementationClass="com.intellij.codeInsight.completion.AlwaysFocusLookup" id="groovyTrue" order="last"/>
|
||||
<weigher key="completion" implementationClass="org.jetbrains.plugins.groovy.lang.completion.weighers.GrKindWeigher" id="groovyKindWeigher" order="after negativeStats, before stats"/>
|
||||
<weigher key="completion" implementationClass="org.jetbrains.plugins.groovy.lang.completion.weighers.GrTopClassMembersWeigher" id="groovyTopClassWeigher" order="after prefix, before proximity"/>
|
||||
<weigher key="completion" implementationClass="org.jetbrains.plugins.groovy.lang.completion.weighers.GrKindWeigher" id="groovyKindWeigher" order=" after prefix"/>
|
||||
<weigher key="completion" implementationClass="org.jetbrains.plugins.groovy.lang.completion.weighers.GrTopClassMembersWeigher" id="groovyTopClassWeigher" order="after groovyKindWeigher"/>
|
||||
<weigher key="completion" implementationClass="org.jetbrains.plugins.groovy.lang.completion.weighers.GrAccessorWeigher" id="groovyAccessorWeigher" order="after groovyTopClassWeigher, before proximity"/>
|
||||
|
||||
<!--<weigher key="completion" implementationClass="org.jetbrains.plugins.groovy.lang.completion.weighers.GrKindWeigher" id="groovyKindWeigher" order="after negativeStats, after prefix"/>
|
||||
<weigher key="completion" implementationClass="org.jetbrains.plugins.groovy.lang.completion.weighers.GrTopClassMembersWeigher" id="groovyTopClassWeigher" order="after groovyKindWeigher"/>
|
||||
<weigher key="completion" implementationClass="org.jetbrains.plugins.groovy.lang.completion.weighers.GrAccessorWeigher" id="groovyAccessorWeigher" order="after groovyTopClassWeigher "/>-->
|
||||
|
||||
<debuggerClassFilterProvider implementation="org.jetbrains.plugins.groovy.debugger.filters.GroovyDebuggerClassFilterProvider"/>
|
||||
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.plugins.groovy.lang.completion.weighers;
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionLocation;
|
||||
import com.intellij.codeInsight.completion.CompletionWeigher;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.ResolveResult;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils;
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public class GrAccessorWeigher extends CompletionWeigher {
|
||||
@Override
|
||||
public Integer weigh(@NotNull LookupElement element, @NotNull CompletionLocation location) {
|
||||
Object o = element.getObject();
|
||||
if (o instanceof ResolveResult) {
|
||||
o = ((ResolveResult)o).getElement();
|
||||
}
|
||||
|
||||
if (o instanceof PsiMethod &&
|
||||
(GroovyPropertyUtils.isSimplePropertyAccessor((PsiMethod)o) || "setProperty".equals(((PsiMethod)o).getName()))) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+13
-6
@@ -22,13 +22,16 @@ import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
|
||||
|
||||
/**
|
||||
* set priority to current class members
|
||||
*
|
||||
* @author Maxim.Medvedev
|
||||
*/
|
||||
public class GrTopClassMembersWeigher extends CompletionWeigher {
|
||||
@Override
|
||||
public Comparable weigh(@NotNull LookupElement element, @NotNull CompletionLocation location) {
|
||||
public Integer weigh(@NotNull LookupElement element, @NotNull CompletionLocation location) {
|
||||
Object o = element.getObject();
|
||||
if (o instanceof ResolveResult) {
|
||||
o = ((ResolveResult)o).getElement();
|
||||
@@ -41,12 +44,16 @@ public class GrTopClassMembersWeigher extends CompletionWeigher {
|
||||
if (!(parent instanceof GrReferenceExpression)) return 0;
|
||||
|
||||
final GrExpression qualifier = ((GrReferenceExpression)parent).getQualifierExpression();
|
||||
if (qualifier == null) return 0;
|
||||
final PsiClass psiClass;
|
||||
if (qualifier == null) {
|
||||
psiClass = PsiUtil.getContextClass(position);
|
||||
}
|
||||
else {
|
||||
final PsiType type = qualifier.getType();
|
||||
if (!(type instanceof PsiClassType)) return 0;
|
||||
|
||||
final PsiType type = qualifier.getType();
|
||||
if (!(type instanceof PsiClassType)) return 0;
|
||||
|
||||
final PsiClass psiClass = ((PsiClassType)type).resolve();
|
||||
psiClass = ((PsiClassType)type).resolve();
|
||||
}
|
||||
if (psiClass == null) return 0;
|
||||
|
||||
if (PsiManager.getInstance(location.getProject()).areElementsEquivalent(((PsiMember)o).getContainingClass(), psiClass)) {
|
||||
|
||||
+8
@@ -829,4 +829,12 @@ class X {
|
||||
public void testClassNameBeforeParentheses(){
|
||||
doBasicTest()
|
||||
}
|
||||
|
||||
public void testPropertyBeforeAccessor() {
|
||||
doVariantableTest 'soSe', 'setSoSe'
|
||||
}
|
||||
|
||||
public void testSortOrder0() {
|
||||
doVariantableTest 'se', 'setSe', 'setMetaClass', 'setProperty'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class X {
|
||||
def soSe
|
||||
def foo() {
|
||||
ss<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
class Foo extends GroovyObjectSupport{
|
||||
def se
|
||||
|
||||
def a() {
|
||||
se<caret>
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class GroovyObjectSupport {
|
||||
public Object getProperty(String property) {
|
||||
null
|
||||
}
|
||||
|
||||
public void setProperty(String property, Object newValue) {
|
||||
}
|
||||
|
||||
public Object invokeMethod(String name, Object args) {
|
||||
null
|
||||
}
|
||||
|
||||
public MetaClass getMetaClass() {
|
||||
null
|
||||
}
|
||||
|
||||
public void setMetaClass(MetaClass metaClass) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user