@Override public Collection<String> findConflicts( PsiElement element, PsiElement[] elements, UsageInfo[] usages) { String methodRefFound = null; if (!ApplicationManager.getApplication().isUnitTestMode() && (element instanceof PsiMethod || element instanceof PsiParameter)) { for (UsageInfo usage : usages) { final PsiElement refElement = usage.getElement(); if (refElement instanceof PsiMethodReferenceExpression) { methodRefFound = RefactoringBundle.message("expand.method.reference.warning"); break; } } } if (methodRefFound != null) { Collection<String> result = new ArrayList<>(); result.add(methodRefFound); final Collection<String> conflicts = super.findConflicts(element, elements, usages); if (conflicts != null) { result.addAll(conflicts); } return result; } return super.findConflicts(element, elements, usages); }
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; }); } } }
private void captureUsagesExpandState(TreePath pathFrom, final Collection<UsageState> states) { if (!myTree.isExpanded(pathFrom)) { return; } final DefaultMutableTreeNode node = (DefaultMutableTreeNode) pathFrom.getLastPathComponent(); final int childCount = node.getChildCount(); for (int idx = 0; idx < childCount; idx++) { final TreeNode child = node.getChildAt(idx); if (child instanceof UsageNode) { final Usage usage = ((UsageNode) child).getUsage(); states.add( new UsageState( usage, myTree.getSelectionModel().isPathSelected(pathFrom.pathByAddingChild(child)))); } else { captureUsagesExpandState(pathFrom.pathByAddingChild(child), states); } } }