예제 #1
0
  protected void completeReference(
      final PsiReference reference,
      final PsiElement position,
      final Set<LookupElement> set,
      final TailType tailType,
      final PsiFile file,
      final ElementFilter filter,
      final CompletionVariant variant) {
    if (reference instanceof PsiMultiReference) {
      for (PsiReference ref : getReferences((PsiMultiReference) reference)) {
        completeReference(ref, position, set, tailType, file, filter, variant);
      }
    } else if (reference instanceof PsiDynaReference) {
      for (PsiReference ref : ((PsiDynaReference<?>) reference).getReferences()) {
        completeReference(ref, position, set, tailType, file, filter, variant);
      }
    } else {
      final Object[] completions = reference.getVariants();
      if (completions == null) return;

      for (Object completion : completions) {
        if (completion == null) {
          LOG.assertTrue(
              false,
              "Position="
                  + position
                  + "\n;Reference="
                  + reference
                  + "\n;variants="
                  + Arrays.toString(completions));
        }
        if (completion instanceof PsiElement) {
          final PsiElement psiElement = (PsiElement) completion;
          if (filter.isClassAcceptable(psiElement.getClass())
              && filter.isAcceptable(psiElement, position)) {
            addLookupItem(set, tailType, completion, file, variant);
          }
        } else {
          if (completion instanceof LookupItem) {
            final Object o = ((LookupItem) completion).getObject();
            if (o instanceof PsiElement) {
              if (!filter.isClassAcceptable(o.getClass()) || !filter.isAcceptable(o, position))
                continue;
            }
          }
          addLookupItem(set, tailType, completion, file, variant);
        }
      }
    }
  }
예제 #2
0
 public void addKeywordVariants(
     Set<CompletionVariant> set, PsiElement position, final PsiFile file) {
   set.addAll(Arrays.asList(findVariants(position, file)));
 }