update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / codeInsight / completion / PreferLocalVariablesLiteralsAndAnnoMethodsWeigher.java
blobcbb08c4bfc612251809abe0a64b0ca9e4b914445
1 /*
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 org.jetbrains.annotations.NotNull;
22 /**
23 * @author peter
25 public class PreferLocalVariablesLiteralsAndAnnoMethodsWeigher extends CompletionWeigher {
27 enum MyResult {
28 classLiteral,
29 normal,
30 superMethodParameters,
31 localOrParameter,
32 annoMethod,
35 public MyResult weigh(@NotNull final LookupElement item, final CompletionLocation location) {
36 final Object object = item.getObject();
38 if (location.getCompletionType() == CompletionType.SMART) {
39 if (object instanceof PsiLocalVariable || object instanceof PsiParameter || object instanceof PsiThisExpression) {
40 return MyResult.localOrParameter;
42 if (object instanceof String && item.getUserData(JavaCompletionUtil.SUPER_METHOD_PARAMETERS) == Boolean.TRUE) {
43 return MyResult.superMethodParameters;
45 return MyResult.normal;
48 if (location.getCompletionType() == CompletionType.BASIC) {
49 if (object instanceof PsiKeyword && PsiKeyword.CLASS.equals(item.getLookupString())) {
50 return MyResult.classLiteral;
53 if (object instanceof PsiAnnotationMethod && ((PsiAnnotationMethod)object).getContainingClass().isAnnotationType()) {
54 return MyResult.annoMethod;
58 return MyResult.normal;