@Override
 public void duringCompletion(@NotNull CompletionInitializationContext context) {
   JavaClassReference reference =
       findJavaClassReference(context.getFile(), context.getStartOffset());
   if (reference != null && reference.getExtendClassNames() != null) {
     JavaClassReferenceSet set = reference.getJavaClassReferenceSet();
     context.setReplacementOffset(
         set.getRangeInElement().getEndOffset()
             + set.getElement().getTextRange().getStartOffset());
   }
 }
  @Override
  public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) {
    PsiElement position = parameters.getPosition();
    JavaClassReference reference =
        findJavaClassReference(position.getContainingFile(), parameters.getOffset());
    if (reference == null) {
      return;
    }

    String[] extendClassNames = reference.getExtendClassNames();
    PsiElement context = reference.getCompletionContext();
    if (extendClassNames != null && context instanceof PsiJavaPackage) {
      if (parameters.getCompletionType() == CompletionType.SMART) {
        JavaClassReferenceSet set = reference.getJavaClassReferenceSet();
        int setStart =
            set.getRangeInElement().getStartOffset()
                + set.getElement().getTextRange().getStartOffset();
        String fullPrefix =
            parameters
                .getPosition()
                .getContainingFile()
                .getText()
                .substring(setStart, parameters.getOffset());
        reference.processSubclassVariants(
            (PsiJavaPackage) context, extendClassNames, result.withPrefixMatcher(fullPrefix));
        return;
      }
      result.addLookupAdvertisement(
          "Press "
              + getActionShortcut(IdeActions.ACTION_SMART_TYPE_COMPLETION)
              + " to see inheritors of "
              + StringUtil.join(extendClassNames, ", "));
    }

    if (parameters.getCompletionType() == CompletionType.SMART) {
      return;
    }

    if (parameters.isExtendedCompletion()
        || parameters.getCompletionType() == CompletionType.CLASS_NAME) {
      JavaClassNameCompletionContributor.addAllClasses(parameters, result);
    } else {
      LegacyCompletionContributor.completeReference(parameters, result);
    }
    result.stopHere();
  }
Ejemplo n.º 3
0
 public JavaResolveResult[] resolve(
     JavaClassReference javaClassReference, boolean incompleteCode) {
   return new JavaResolveResult[] {javaClassReference.doAdvancedResolve()};
 }