PsiElement (@Nullable PsiElement element) { if (element == null) return null; TargetElementEvaluatorEx2 evaluator = getElementEvaluatorsEx2(element.getLanguage()); if (evaluator != null) { PsiElement result = evaluator.getNamedElement(element); if (result != null) return result; } PsiElement parent; if ((parent = PsiTreeUtil.getParentOfType(element, PsiNamedElement.class, false)) != null) { // A bit hacky: depends on the named element's text offset being overridden correctly if (!(parent instanceof PsiFile) && parent.getTextOffset() == element.getTextRange().getStartOffset()) { if (evaluator == null || evaluator.isAcceptableNamedParent(parent)) { return parent; } } } return null; }