コード例 #1
0
  public String calcGenerics(@NotNull PsiElement context, InsertionContext insertionContext) {
    if (insertionContext.getCompletionChar() == '<') {
      return "";
    }

    assert context.isValid();
    if (myDiamond) {
      return "<>";
    }

    if (getObject() instanceof PsiClass) {
      PsiClass psiClass = (PsiClass) getObject();
      PsiResolveHelper resolveHelper =
          JavaPsiFacade.getInstance(psiClass.getProject()).getResolveHelper();
      PsiSubstitutor substitutor = getSubstitutor();
      StringBuilder builder = new StringBuilder();
      for (PsiTypeParameter parameter : psiClass.getTypeParameters()) {
        PsiType substitute = substitutor.substitute(parameter);
        if (substitute == null
            || (PsiUtil.resolveClassInType(substitute) == parameter
                && resolveHelper.resolveReferencedClass(parameter.getName(), context)
                    != CompletionUtil.getOriginalOrSelf(parameter))) {
          return "";
        }
        if (builder.length() > 0) {
          builder.append(", ");
        }
        builder.append(substitute.getCanonicalText());
      }
      if (builder.length() > 0) {
        return "<" + builder + ">";
      }
    }
    return "";
  }
コード例 #2
0
 private static boolean isInitializedImplicitly(PsiField field) {
   field = CompletionUtil.getOriginalOrSelf(field);
   for (ImplicitUsageProvider provider : ImplicitUsageProvider.EP_NAME.getExtensions()) {
     if (provider.isImplicitWrite(field)) {
       return true;
     }
   }
   return false;
 }
コード例 #3
0
  private boolean shouldQualify(PsiField field, InsertionContext context) {
    if (myHelper != null && !myHelper.willBeImported()) {
      return true;
    }

    if (getAttribute(FORCE_QUALIFY) != null) {
      return true;
    }

    PsiReference reference = context.getFile().findReferenceAt(context.getStartOffset());
    if (reference instanceof PsiReferenceExpression
        && !((PsiReferenceExpression) reference).isQualified()) {
      final PsiVariable target =
          JavaPsiFacade.getInstance(context.getProject())
              .getResolveHelper()
              .resolveReferencedVariable(field.getName(), (PsiElement) reference);
      return !field
          .getManager()
          .areElementsEquivalent(target, CompletionUtil.getOriginalOrSelf(field));
    }
    return false;
  }