IDEADEV-40452
[fedora-idea.git] / plugins / InspectionGadgets / src / com / siyeh / ig / threading / NotifyNotInSynchronizedContextInspection.java
blob6a3844241de8ef0f6ce00a40e69a825dcf152781
1 /*
2 * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.siyeh.ig.threading;
18 import com.intellij.psi.PsiMethod;
19 import com.intellij.psi.PsiMethodCallExpression;
20 import com.intellij.psi.PsiParameterList;
21 import com.intellij.psi.PsiReferenceExpression;
22 import com.siyeh.HardcodedMethodConstants;
23 import com.siyeh.InspectionGadgetsBundle;
24 import com.siyeh.ig.BaseInspection;
25 import com.siyeh.ig.BaseInspectionVisitor;
26 import com.siyeh.ig.psiutils.SynchronizationUtil;
27 import org.jetbrains.annotations.NotNull;
29 public class NotifyNotInSynchronizedContextInspection
30 extends BaseInspection {
32 @NotNull
33 public String getDisplayName() {
34 return InspectionGadgetsBundle.message(
35 "notify.not.in.synchronized.context.display.name");
38 @NotNull
39 protected String buildErrorString(Object... infos) {
40 return InspectionGadgetsBundle.message(
41 "notify.not.in.synchronized.context.problem.descriptor");
44 public BaseInspectionVisitor buildVisitor() {
45 return new NotifyNotInSynchronizedContextVisitor();
48 private static class NotifyNotInSynchronizedContextVisitor
49 extends BaseInspectionVisitor {
51 @Override public void visitMethodCallExpression(
52 @NotNull PsiMethodCallExpression expression) {
53 final PsiReferenceExpression methodExpression =
54 expression.getMethodExpression();
55 final String methodName = methodExpression.getReferenceName();
56 if (!HardcodedMethodConstants.NOTIFY.equals(methodName) &&
57 !HardcodedMethodConstants.NOTIFY_ALL.equals(methodName)) {
58 return;
60 final PsiMethod method = expression.resolveMethod();
61 if (method == null) {
62 return;
64 final PsiParameterList parameterList = method.getParameterList();
65 if (parameterList.getParametersCount() != 0) {
66 return;
68 if (SynchronizationUtil.isInSynchronizedContext(expression)) {
69 return;
71 registerMethodCallError(expression);