MyResult (@NotNull LookupElement item) { final Object object = item.getObject(); if (object instanceof PsiKeyword) { ThreeState result = isProbableKeyword(((PsiKeyword)object).getText()); if (result == ThreeState.YES) return MyResult.probableKeyword; if (result == ThreeState.NO) return MyResult.improbableKeyword; } if (item.as(CastingLookupElementDecorator.CLASS_CONDITION_KEY) != null) { return MyResult.castVariable; } JavaChainLookupElement chain = item.as(JavaChainLookupElement.CLASS_CONDITION_KEY); if (chain != null) { if (myCompletionType == CompletionType.BASIC) { return MyResult.basicChain; } Object qualifier = chain.getQualifier().getObject(); if (qualifier instanceof PsiVariable && PsiUtil.isJvmLocalVariable((PsiVariable)qualifier)) { return MyResult.variable; } if (qualifier instanceof PsiField) { return MyResult.qualifiedWithField; } if (isGetter(qualifier)) { return MyResult.qualifiedWithGetter; } if (chain.getQualifier().getUserData(INTRODUCED_VARIABLE) == Boolean.TRUE) { return MyResult.introducedVariable; } if (myCompletionType == CompletionType.SMART && qualifier instanceof PsiMethod && isGetter(object)) { return MyResult.getterQualifiedByMethod; } } if (object instanceof PsiLocalVariable || object instanceof PsiParameter || object instanceof PsiThisExpression || object instanceof PsiField && !((PsiField)object).hasModifierProperty(PsiModifier.STATIC)) { if (PsiTreeUtil.getParentOfType(myPosition, PsiDocComment.class) == null) { return isComparisonWithItself((PsiElement)object) ? MyResult.unlikelyItem : isExpectedTypeItem(item) ? MyResult.expectedTypeVariable : MyResult.variable; } } if (object instanceof String && item.getUserData(JavaCompletionUtil.SUPER_METHOD_PARAMETERS) == Boolean.TRUE) { return MyResult.superMethodParameters; } if (item.getUserData(FunctionalExpressionCompletionProvider.LAMBDA_ITEM) != null) { return MyResult.lambda; } Boolean methodRefPreference = item.getUserData(FunctionalExpressionCompletionProvider.METHOD_REF_PREFERRED); if (methodRefPreference != null) { return methodRefPreference ? MyResult.likelyMethodRef : MyResult.methodRef; } if (object instanceof PsiMethod) { PsiClass containingClass = ((PsiMethod)object).getContainingClass(); if (containingClass != null && CommonClassNames.JAVA_UTIL_COLLECTIONS.equals(containingClass.getQualifiedName())) { return MyResult.collectionFactory; } } if (object instanceof PsiClass && CommonClassNames.JAVA_LANG_STRING.equals(((PsiClass)object).getQualifiedName()) && JavaSmartCompletionContributor.AFTER_NEW.accepts(myPosition)) { return MyResult.unlikelyItem; } Boolean expectedTypeMember = item.getUserData(MembersGetter.EXPECTED_TYPE_MEMBER); if (expectedTypeMember != null) { return expectedTypeMember ? (object instanceof PsiField ? MyResult.expectedTypeConstant : MyResult.expectedTypeMethod) : MyResult.classNameOrGlobalStatic; } if (item instanceof TypeArgumentCompletionProvider.TypeArgsLookupElement) { return MyResult.expectedTypeArgument; } if (myCompletionType == CompletionType.SMART) { if (isGetter(object)) { return chain == null && isAccessibleFieldGetter(object) ? MyResult.accessibleFieldGetter : MyResult.getter; } return MyResult.normal; } if (myCompletionType == CompletionType.BASIC) { StaticallyImportable callElement = item.as(StaticallyImportable.CLASS_CONDITION_KEY); if (callElement != null && callElement.canBeImported() && !callElement.willBeImported()) { return MyResult.classNameOrGlobalStatic; } JavaConstructorCallElement constructorCall = item.as(JavaConstructorCallElement.class); if (constructorCall != null) { return myClassSuitability.apply(constructorCall.getConstructedClass()); } if (object instanceof PsiMethod && PsiUtil.isAnnotationMethod((PsiElement)object)) { return MyResult.annoMethod; } if (object instanceof PsiClass) { return myClassSuitability.apply((PsiClass)object); } if (object instanceof PsiField && myNonInitializedFields.contains(object)) { return MyResult.nonInitialized; } if (object instanceof PsiPackage) { String name = ((PsiPackage)object).getName(); if (name != null && !name.isEmpty() && Character.isUpperCase(name.charAt(0))) { // Disprefer package names starting with uppercase letter, as they could pop up before classes return MyResult.unlikelyItem; } } } return MyResult.normal; }