PsiElement () { final PsiElement[] result = new PsiElement[1]; process(new PsiElementProcessor<>() { final String canonicalText = getCanonicalText(); @Override public boolean execute(@NotNull final PsiElement element) { final String idValue = getIdValue(element); if (idValue != null && idValue.equals(canonicalText)) { result[0] = getIdValueElement(element); return false; } return true; } }); return result[0]; }