PsiVariable () { final PsiElement declarationStatement = myPointer != null ? myPointer.getElement() : null; if (declarationStatement instanceof PsiDeclarationStatement) { PsiElement[] declaredElements = ((PsiDeclarationStatement)declarationStatement).getDeclaredElements(); return declaredElements.length == 0 ? null : (PsiVariable)declaredElements[0]; } else if (declarationStatement instanceof PsiInstanceOfExpression) { PsiPattern pattern = ((PsiInstanceOfExpression)declarationStatement).getPattern(); if (pattern instanceof PsiTypeTestPattern) { return ((PsiTypeTestPattern)pattern).getPatternVariable(); } } return declarationStatement instanceof PsiVariable ? (PsiVariable)declarationStatement : null; }