void (PsiElement context) { context.accept(new JavaRecursiveElementWalkingVisitor() { private int m_numLocksHeld; @Override public void visitClass(@NotNull PsiClass aClass) { // Do not recurse into } @Override public void visitLambdaExpression(@NotNull PsiLambdaExpression expression) { // Ignore } @Override public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) { super.visitMethodCallExpression(expression); if (m_numLocksHeld < 2) { return; } final PsiReferenceExpression methodExpression = expression.getMethodExpression(); @NonNls final String methodName = methodExpression.getReferenceName(); if (!HardcodedMethodConstants.WAIT.equals(methodName)) { return; } final PsiMethod method = expression.resolveMethod(); if (method == null) { return; } final PsiParameterList parameterList = method.getParameterList(); final int numParams = parameterList.getParametersCount(); if (numParams > 2) { return; } final PsiParameter[] parameters = parameterList.getParameters(); if (numParams > 0) { final PsiType parameterType = parameters[0].getType(); if (!parameterType.equals(PsiTypes.longType())) { return; } } if (numParams > 1) { final PsiType parameterType = parameters[1].getType(); if (!parameterType.equals(PsiTypes.intType())) { return; } } registerMethodCallError(expression); } @Override public void visitMethod(@NotNull PsiMethod method) { if (method.hasModifierProperty(PsiModifier.SYNCHRONIZED)) { m_numLocksHeld++; } super.visitMethod(method); } @Override public void visitSynchronizedStatement( @NotNull PsiSynchronizedStatement synchronizedStatement) { m_numLocksHeld++; super.visitSynchronizedStatement(synchronizedStatement); } @Override protected void elementFinished(@NotNull PsiElement element) { super.elementFinished(element); if (element instanceof PsiMethod && ((PsiMethod)element).hasModifierProperty(PsiModifier.SYNCHRONIZED) || element instanceof PsiSynchronizedStatement) { m_numLocksHeld--; } } }); }