@Nullable private static PsiElement[] convertToPsiElementsArray(final Object[] selectedElements) { if (selectedElements == null) return null; ArrayList<PsiElement> psiElements = new ArrayList<PsiElement>(); for (Object selectedElement : selectedElements) { if (selectedElement instanceof PsiElement && ((PsiElement) selectedElement).isValid()) { psiElements.add((PsiElement) selectedElement); } } return PsiUtilBase.toPsiElementArray(psiElements); }
@NotNull private static PsiElement[] filterPsiElements(Object[] selectedElements) { if (selectedElements == null) { return PsiElement.EMPTY_ARRAY; } ArrayList<PsiElement> psiElements = new ArrayList<PsiElement>(); for (Object selectedElement : selectedElements) { if (selectedElement instanceof PsiElement) { psiElements.add((PsiElement) selectedElement); } } return PsiUtilBase.toPsiElementArray(psiElements); }
@Override @NotNull public PsiElement[] getSecondaryElements() { PsiElement element = getPsiElement(); if (ApplicationManager.getApplication().isUnitTestMode()) return PsiElement.EMPTY_ARRAY; if (element instanceof PsiField) { final PsiField field = (PsiField) element; PsiClass containingClass = field.getContainingClass(); if (containingClass != null) { String fieldName = field.getName(); final String propertyName = JavaCodeStyleManager.getInstance(getProject()) .variableNameToPropertyName(fieldName, VariableKind.FIELD); Set<PsiMethod> accessors = new THashSet<PsiMethod>(); boolean isStatic = field.hasModifierProperty(PsiModifier.STATIC); PsiMethod getter = PropertyUtil.findPropertyGetterWithType( propertyName, isStatic, field.getType(), ContainerUtil.iterate(containingClass.getMethods())); if (getter != null) accessors.add(getter); PsiMethod setter = PropertyUtil.findPropertySetterWithType( propertyName, isStatic, field.getType(), ContainerUtil.iterate(containingClass.getMethods())); if (setter != null) accessors.add(setter); accessors.addAll(PropertyUtil.getAccessors(containingClass, fieldName)); if (!accessors.isEmpty()) { final boolean doSearch; boolean containsPhysical = ContainerUtil.find( accessors, new Condition<PsiMethod>() { @Override public boolean value(PsiMethod psiMethod) { return psiMethod.isPhysical(); } }) != null; if (!containsPhysical) { doSearch = true; } else { doSearch = Messages.showOkCancelDialog( FindBundle.message("find.field.accessors.prompt", fieldName), FindBundle.message("find.field.accessors.title"), CommonBundle.getYesButtonText(), CommonBundle.getNoButtonText(), Messages.getQuestionIcon()) == DialogWrapper.OK_EXIT_CODE; } if (doSearch) { final Set<PsiElement> elements = new THashSet<PsiElement>(); for (PsiMethod accessor : accessors) { ContainerUtil.addAll( elements, SuperMethodWarningUtil.checkSuperMethods(accessor, ACTION_STRING)); } return PsiUtilBase.toPsiElementArray(elements); } } } } return super.getSecondaryElements(); }
public static PsiElement[] collect(final Matcher matcher) { if (matcher == null) return PsiElement.EMPTY_ARRAY; final List<PsiElement> found = process(matcher, false); return PsiUtilBase.toPsiElementArray(found); }