/plugins/InspectionGadgets/src/com/siyeh/ig/threading/NotifyCalledOnConditionInspection.java

https://bitbucket.org/nbargnesi/idea · Java · 63 lines · 41 code · 7 blank · 15 comment · 1 complexity · 0ea47ad4c768a5d7ef85ce326a1ae550 MD5 · raw file

  1. /*
  2. * Copyright 2003-20067 Dave Griffith, Bas Leijdekkers
  3. *
  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
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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.
  15. */
  16. package com.siyeh.ig.threading;
  17. import com.intellij.psi.PsiMethodCallExpression;
  18. import com.intellij.psi.PsiType;
  19. import com.siyeh.HardcodedMethodConstants;
  20. import com.siyeh.InspectionGadgetsBundle;
  21. import com.siyeh.ig.BaseInspection;
  22. import com.siyeh.ig.BaseInspectionVisitor;
  23. import com.siyeh.ig.psiutils.MethodCallUtils;
  24. import org.jetbrains.annotations.NotNull;
  25. public class NotifyCalledOnConditionInspection extends BaseInspection {
  26. @NotNull
  27. public String getDisplayName() {
  28. return InspectionGadgetsBundle.message(
  29. "notify.called.on.condition.display.name");
  30. }
  31. @NotNull
  32. protected String buildErrorString(Object... infos) {
  33. return InspectionGadgetsBundle.message(
  34. "notify.called.on.condition.problem.descriptor");
  35. }
  36. public BaseInspectionVisitor buildVisitor() {
  37. return new NotifyCalledOnConditionVisitor();
  38. }
  39. private static class NotifyCalledOnConditionVisitor
  40. extends BaseInspectionVisitor {
  41. @Override
  42. public void visitMethodCallExpression(
  43. @NotNull PsiMethodCallExpression expression) {
  44. super.visitMethodCallExpression(expression);
  45. if (!MethodCallUtils.isCallToMethod(expression,
  46. "java.util.concurrent.locks.Condition", PsiType.VOID,
  47. HardcodedMethodConstants.NOTIFY) &&
  48. !MethodCallUtils.isCallToMethod(expression,
  49. "java.util.concurrent.locks.Condition", PsiType.VOID,
  50. HardcodedMethodConstants.NOTIFY_ALL)) {
  51. return;
  52. }
  53. registerMethodCallError(expression);
  54. }
  55. }
  56. }