@Nullable
 private PsiElement resolveElement() {
   PsiElement element = getParent();
   while (element != null
       && (!(element instanceof PsiClass) || element instanceof PsiTypeParameter)) {
     if (element instanceof PsiMethod) {
       final PsiMethod method = (PsiMethod) element;
       final PsiTypeParameterList list = method.getTypeParameterList();
       if (list != null) {
         final PsiTypeParameter[] parameters = list.getTypeParameters();
         for (int i = 0; parameters != null && i < parameters.length; i++) {
           final PsiTypeParameter parameter = parameters[i];
           if (myQualifiedName.equals(parameter.getName())) return parameter;
         }
       }
     }
     element = element.getParent();
   }
   if (element == null) return null;
   for (PsiTypeParameter parameter :
       PsiUtil.typeParametersIterable((PsiTypeParameterListOwner) element)) {
     if (myQualifiedName.equals(parameter.getName())) return parameter;
   }
   return resolveClassPreferringMyJar();
 }
コード例 #2
0
 private static void addUnfinishedMethodTypeParameters(
     PsiElement position, final Consumer<LookupElement> result) {
   final ProcessingContext context = new ProcessingContext();
   if (psiElement()
       .inside(
           psiElement(PsiTypeElement.class)
               .afterLeaf(
                   psiElement()
                       .withText(">")
                       .withParent(
                           psiElement(PsiTypeParameterList.class)
                               .withParent(PsiErrorElement.class)
                               .save("typeParameterList"))))
       .accepts(position, context)) {
     final PsiTypeParameterList list = (PsiTypeParameterList) context.get("typeParameterList");
     PsiElement current = list.getParent().getParent();
     if (current instanceof PsiField) {
       current = current.getParent();
     }
     if (current instanceof PsiClass) {
       for (PsiTypeParameter typeParameter : list.getTypeParameters()) {
         result.consume(new JavaPsiClassReferenceElement(typeParameter));
       }
     }
   }
 }
コード例 #3
0
  private static void findTypeParameterExternalUsages(
      final PsiTypeParameter typeParameter, final Collection<UsageInfo> usages) {
    PsiTypeParameterListOwner owner = typeParameter.getOwner();
    if (owner != null) {
      final PsiTypeParameterList parameterList = owner.getTypeParameterList();
      if (parameterList != null) {
        final int paramsCount = parameterList.getTypeParameters().length;
        final int index = parameterList.getTypeParameterIndex(typeParameter);

        ReferencesSearch.search(owner)
            .forEach(
                reference -> {
                  if (reference instanceof PsiJavaCodeReferenceElement) {
                    final PsiReferenceParameterList parameterList1 =
                        ((PsiJavaCodeReferenceElement) reference).getParameterList();
                    if (parameterList1 != null) {
                      PsiTypeElement[] typeArgs = parameterList1.getTypeParameterElements();
                      if (typeArgs.length > index) {
                        if (typeArgs.length == 1
                            && paramsCount > 1
                            && typeArgs[0].getType() instanceof PsiDiamondType) return true;
                        usages.add(
                            new SafeDeleteReferenceJavaDeleteUsageInfo(
                                typeArgs[index], typeParameter, true));
                      }
                    }
                  }
                  return true;
                });
      }
    }
  }
コード例 #4
0
 @NotNull
 public static PsiTypeParameter[] getTypeParameters(@NotNull PsiTypeParameterListOwner owner) {
   final PsiTypeParameterList typeParameterList = owner.getTypeParameterList();
   if (typeParameterList != null) {
     return typeParameterList.getTypeParameters();
   }
   return PsiTypeParameter.EMPTY_ARRAY;
 }
コード例 #5
0
 public static int getTypeParameterIndex(
     @NotNull PsiTypeParameter typeParameter, @NotNull PsiTypeParameterList typeParameterList) {
   PsiTypeParameter[] typeParameters = typeParameterList.getTypeParameters();
   for (int i = 0; i < typeParameters.length; i++) {
     if (typeParameter.equals(typeParameters[i])) return i;
   }
   LOG.assertTrue(false);
   return -1;
 }
 private static void createTypeParamsListComment(
     final StringBuilder buffer,
     final Project project,
     final CodeDocumentationAwareCommenter commenter,
     final PsiTypeParameterList typeParameterList) {
   final PsiTypeParameter[] typeParameters = typeParameterList.getTypeParameters();
   for (PsiTypeParameter typeParameter : typeParameters) {
     buffer.append(CodeDocumentationUtil.createDocCommentLine(PARAM_TAG, project, commenter));
     buffer.append("<").append(typeParameter.getName()).append(">");
     buffer.append(LINE_SEPARATOR);
   }
 }
コード例 #7
0
 public static boolean hasTypeParameters(@NotNull PsiTypeParameterListOwner owner) {
   final PsiTypeParameterList typeParameterList = owner.getTypeParameterList();
   return typeParameterList != null && typeParameterList.getTypeParameters().length != 0;
 }