PsiTryStatement (PsiReferenceExpression expression, String guard) { PsiTryStatement tryStatement = PsiTreeUtil.getParentOfType(expression, PsiTryStatement.class); while (tryStatement != null) { PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock(); if (finallyBlock != null) { for (PsiStatement psiStatement : finallyBlock.getStatements()) { if (isLockGuardStatement(guard, psiStatement, "unlock")) { return tryStatement; } } } tryStatement = PsiTreeUtil.getParentOfType(tryStatement, PsiTryStatement.class); } return null; }