PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { if (!PsiUtil.isLanguageLevel16OrHigher(holder.getFile())) { return PsiElementVisitor.EMPTY_VISITOR; } return new JavaElementVisitor() { @Override public void visitSynchronizedStatement(@NotNull final PsiSynchronizedStatement statement) { final PsiExpression monitor = statement.getLockExpression(); if (monitor == null) return; final PsiType monitorType = monitor.getType(); if (monitorType == null) return; if (!isValueBasedClass(monitorType)) { final TypeConstraint constraint = TypeConstraint.fromDfType(CommonDataflow.getDfType(monitor)); final PsiType inferredType = constraint.getPsiType(statement.getProject()); if (monitorType.equals(inferredType)) return; if (!isValueBasedClass(inferredType)) return; } holder.registerProblem(monitor, JavaBundle.message("inspection.value.based.warnings.synchronization")); } }; }