Java 类com.intellij.psi.filters.getters.MembersGetter 实例源码

项目:tools-idea    文件:PreferByKindWeigher.java   
@NotNull
@Override
public MyResult weigh(@NotNull LookupElement item) {
  final Object object = item.getObject();

  if (object instanceof PsiKeyword) {
    String keyword = ((PsiKeyword)object).getText();
    if (PsiKeyword.RETURN.equals(keyword) && isLastStatement(PsiTreeUtil.getParentOfType(myPosition, PsiStatement.class))) {
      return MyResult.probableKeyword;
    }
    if (PsiKeyword.ELSE.equals(keyword) || PsiKeyword.FINALLY.equals(keyword)) {
      return MyResult.probableKeyword;
    }
  }

  if (myCompletionType == CompletionType.SMART) {
    if (object instanceof PsiLocalVariable || object instanceof PsiParameter || object instanceof PsiThisExpression) {
      return MyResult.localOrParameter;
    }
  }

  if (object instanceof String && item.getUserData(JavaCompletionUtil.SUPER_METHOD_PARAMETERS) == Boolean.TRUE) {
    return MyResult.superMethodParameters;
  }

  if (myCompletionType == CompletionType.SMART) {
    if (item.getUserData(CollectionsUtilityMethodsProvider.COLLECTION_FACTORY) != null) {
      return MyResult.collectionFactory;
    }
    if (Boolean.TRUE.equals(item.getUserData(MembersGetter.EXPECTED_TYPE_INHERITOR_MEMBER))) {
      return MyResult.expectedTypeMember;
    }

    final JavaChainLookupElement chain = item.as(JavaChainLookupElement.CLASS_CONDITION_KEY);
    if (chain != null) {
      Object qualifier = chain.getQualifier().getObject();
      if (qualifier instanceof PsiLocalVariable || qualifier instanceof PsiParameter) {
        return MyResult.localOrParameter;
      }
      if (qualifier instanceof PsiField) {
        return MyResult.qualifiedWithField;
      }
      if (qualifier instanceof PsiMethod && PropertyUtil.isSimplePropertyGetter((PsiMethod)qualifier)) {
        return MyResult.qualifiedWithGetter;
      }
    }

    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;
    }

    if (object instanceof PsiKeyword && PsiKeyword.CLASS.equals(item.getLookupString())) {
      return MyResult.classLiteral;
    }

    if (object instanceof PsiMethod && PsiUtil.isAnnotationMethod((PsiElement)object)) {
      return MyResult.annoMethod;
    }

    if (object instanceof PsiClass) {
      if (myRequiredSuper.value((PsiClass)object)) {
        return MyResult.suitableClass;
      }
      return MyResult.classNameOrGlobalStatic;
    }

    if (object instanceof PsiField && myNonInitializedFields.contains(object)) {
      return MyResult.nonInitialized;
    }
  }

  return MyResult.normal;
}