boolean (PsiElement element) { final PsiElement context = PsiTreeUtil.getParentOfType(element, PsiMethod.class, PsiSynchronizedStatement.class, PsiClass.class, PsiLambdaExpression.class); if (context instanceof PsiSynchronizedStatement) { return true; } if (context instanceof PsiMethod) { final PsiModifierListOwner modifierListOwner = (PsiModifierListOwner)context; if (modifierListOwner.hasModifierProperty(PsiModifier.SYNCHRONIZED)) { return true; } } if (context instanceof PsiMethod || context instanceof PsiLambdaExpression) { PsiAssertStatement assertStatement = findHoldsLockAssertion(context); return assertStatement != null && assertStatement.getTextOffset() + assertStatement.getTextLength() < element.getTextOffset(); } return false; }