2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.codeInsight
.completion
;
18 import com
.intellij
.codeInsight
.lookup
.LookupElement
;
19 import com
.intellij
.psi
.*;
20 import com
.intellij
.psi
.javadoc
.PsiDocComment
;
21 import com
.intellij
.psi
.util
.PsiTreeUtil
;
22 import org
.jetbrains
.annotations
.NotNull
;
27 public class StaticMembersWeigher
extends CompletionWeigher
{
28 public Comparable
weigh(@NotNull LookupElement element
, CompletionLocation loc
) {
29 if (loc
.getCompletionType() != CompletionType
.BASIC
) return 0;
31 final PsiElement position
= loc
.getCompletionParameters().getPosition();
32 if (!position
.isValid()) return 0;
34 if (PsiTreeUtil
.getParentOfType(position
, PsiDocComment
.class) != null) return 0;
35 if (position
.getParent() instanceof PsiReferenceExpression
) {
36 final PsiReferenceExpression refExpr
= (PsiReferenceExpression
)position
.getParent();
37 final PsiElement qualifier
= refExpr
.getQualifier();
38 if (qualifier
== null) {
41 if (!(qualifier
instanceof PsiJavaCodeReferenceElement
) || !(((PsiJavaCodeReferenceElement
)qualifier
).resolve() instanceof PsiClass
)) {
46 final Object o
= element
.getObject();
47 if (!(o
instanceof PsiMember
)) return 0;
49 if (((PsiMember
)o
).hasModifierProperty(PsiModifier
.STATIC
)) {
50 if (o
instanceof PsiMethod
) return 5;
51 if (o
instanceof PsiField
) return 4;
54 if (o
instanceof PsiClass
&& ((PsiClass
) o
).getContainingClass() != null) {
58 //instance method or field