void (@NotNull PsiSynchronizedStatement statement) { super.visitSynchronizedStatement(statement); final PsiElement parent = statement.getParent(); if (!(parent instanceof PsiCodeBlock)) { return; } final PsiElement grandParent = parent.getParent(); if (!(grandParent instanceof PsiMethod method)) { return; } if (!ControlFlowUtils.hasStatementCount(method.getBody(), 1)) { return; } final PsiExpression lockExpression = statement.getLockExpression(); if (method.hasModifierProperty(PsiModifier.STATIC)) { if (!(lockExpression instanceof PsiClassObjectAccessExpression classExpression)) { return; } final PsiTypeElement typeElement = classExpression.getOperand(); final PsiType type = typeElement.getType(); if (!(type instanceof PsiClassType classType)) { return; } final PsiClass aClass = classType.resolve(); final PsiClass containingClass = method.getContainingClass(); if (aClass != containingClass) { return; } } else { if (!(lockExpression instanceof PsiThisExpression thisExpression)) { return; } final PsiJavaCodeReferenceElement qualifier = thisExpression.getQualifier(); if (qualifier != null) { final PsiElement target = qualifier.resolve(); final PsiClass containingClass = method.getContainingClass(); if (containingClass == null || !containingClass.equals(target)) { return; } } } registerMethodError(method); }