IDEADEV-40452
[fedora-idea.git] / plugins / InspectionGadgets / src / com / siyeh / ig / threading / BusyWaitInspection.java
blob24338e99c5d56f284346fe82e7c399b3211277ec
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.PsiMethodCallExpression;
19 import com.intellij.psi.PsiType;
20 import com.siyeh.InspectionGadgetsBundle;
21 import com.siyeh.ig.BaseInspection;
22 import com.siyeh.ig.BaseInspectionVisitor;
23 import com.siyeh.ig.psiutils.ControlFlowUtils;
24 import com.siyeh.ig.psiutils.MethodCallUtils;
25 import org.jetbrains.annotations.NotNull;
27 public class BusyWaitInspection extends BaseInspection {
29 @NotNull
30 public String getDisplayName() {
31 return InspectionGadgetsBundle.message("busy.wait.display.name");
34 @NotNull
35 protected String buildErrorString(Object... infos) {
36 return InspectionGadgetsBundle.message("busy.wait.problem.descriptor");
39 public BaseInspectionVisitor buildVisitor() {
40 return new BusyWaitVisitor();
43 private static class BusyWaitVisitor extends BaseInspectionVisitor {
45 @Override public void visitMethodCallExpression(
46 @NotNull PsiMethodCallExpression expression) {
47 super.visitMethodCallExpression(expression);
48 if (!MethodCallUtils.isCallToMethod(expression, "java.lang.Thread",
49 PsiType.VOID, "sleep", PsiType.LONG) &&
50 !MethodCallUtils.isCallToMethod(expression,
51 "java.lang.Thread", PsiType.VOID, "sleep",
52 PsiType.LONG, PsiType.INT)) {
53 return;
55 if (!ControlFlowUtils.isInLoop(expression)) {
56 return;
58 registerMethodCallError(expression);