IG: merge two inspections into one "'wait()' or 'notify()' while not synchronized...
authorBas Leijdekkers <basleijdekkers@gmail.com>
Fri, 30 Sep 2016 07:47:29 +0000 (09:47 +0200)
committerBas Leijdekkers <basleijdekkers@gmail.com>
Fri, 30 Sep 2016 07:48:34 +0000 (09:48 +0200)
12 files changed:
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/META-INF/InspectionGadgets.xml
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/InspectionGadgetsBundle.properties
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/NotifyNotInSynchronizedContextInspection.java [deleted file]
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/WaitNotInSynchronizedContextInspection.java [deleted file]
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/WaitNotifyNotInSynchronizedContextInspection.java [new file with mode: 0644]
plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/WaitNotifyNotInSynchronizedContextInspectionMerger.java [new file with mode: 0644]
plugins/InspectionGadgets/src/inspectionDescriptions/NotifyNotInSynchronizedContext.html [deleted file]
plugins/InspectionGadgets/src/inspectionDescriptions/WaitNotInSynchronizedContext.html [deleted file]
plugins/InspectionGadgets/src/inspectionDescriptions/WaitNotifyNotInSynchronizedContext.html [new file with mode: 0644]
plugins/InspectionGadgets/test/com/siyeh/igtest/threading/NotifyNotInSynchronizedContextInspection.java [deleted file]
plugins/InspectionGadgets/test/com/siyeh/igtest/threading/wait_notify_not_in_synchronized_context/WaitNotifyNotInSynchronizedContext.java [moved from plugins/InspectionGadgets/test/com/siyeh/igtest/threading/wait_not_in_synchronized_context/WaitNotInSynchronizedContext.java with 53% similarity]
plugins/InspectionGadgets/testsrc/com/siyeh/ig/threading/WaitNotifyNotInSynchronizedContextInspectionTest.java [moved from plugins/InspectionGadgets/testsrc/com/siyeh/ig/threading/WaitNotInSynchronizedContextInspectionTest.java with 80% similarity]

index 9e947794298003d676ba73ab52221b0b9544e80d..abfa68934cc5f455572ed47b6b37e854ad6b0a7f 100644 (file)
@@ -6,6 +6,7 @@
     <inspectionElementsMerger implementation="com.siyeh.ig.naming.MisspelledMethodNameInspectionMerger"/>
     <inspectionElementsMerger implementation="com.siyeh.ig.junit.MalformedSetUpTearDownInspectionMerger"/>
     <inspectionElementsMerger implementation="com.siyeh.ig.inheritance.MethodDoesntCallSuperMethodInspectionMerger"/>
+    <inspectionElementsMerger implementation="com.siyeh.ig.threading.WaitNotifyNotInSynchronizedContextInspectionMerger"/>
 
     <!--group.names.abstraction.issues-->
     <localInspection groupPath="Java" language="JAVA" shortName="BooleanParameter" bundle="com.siyeh.InspectionGadgetsBundle" key="boolean.parameter.display.name"
                      key="notify.called.on.condition.display.name" groupBundle="messages.InspectionsBundle"
                      groupKey="group.names.threading.issues" enabledByDefault="false" level="WARNING"
                      implementationClass="com.siyeh.ig.threading.NotifyCalledOnConditionInspection"/>
-    <localInspection groupPath="Java" language="JAVA" shortName="NotifyNotInSynchronizedContext" bundle="com.siyeh.InspectionGadgetsBundle"
-                     key="notify.not.in.synchronized.context.display.name" groupBundle="messages.InspectionsBundle"
-                     groupKey="group.names.threading.issues" enabledByDefault="false" level="WARNING"
-                     implementationClass="com.siyeh.ig.threading.NotifyNotInSynchronizedContextInspection"/>
     <localInspection groupPath="Java" language="JAVA" shortName="NotifyWithoutCorrespondingWait" bundle="com.siyeh.InspectionGadgetsBundle"
                      key="notify.without.corresponding.wait.display.name" groupBundle="messages.InspectionsBundle"
                      groupKey="group.names.threading.issues" enabledByDefault="false" level="WARNING"
     <localInspection groupPath="Java" language="JAVA" shortName="WaitNotInLoop" bundle="com.siyeh.InspectionGadgetsBundle" key="wait.not.in.loop.display.name"
                      groupBundle="messages.InspectionsBundle" groupKey="group.names.threading.issues" enabledByDefault="false"
                      level="WARNING" implementationClass="com.siyeh.ig.threading.WaitNotInLoopInspection"/>
-    <localInspection groupPath="Java" language="JAVA" suppressId="WaitWhileNotSynced" shortName="WaitNotInSynchronizedContext" bundle="com.siyeh.InspectionGadgetsBundle"
-                     key="wait.not.in.synchronized.context.display.name" groupBundle="messages.InspectionsBundle"
-                     groupKey="group.names.threading.issues" enabledByDefault="false" level="WARNING"
-                     implementationClass="com.siyeh.ig.threading.WaitNotInSynchronizedContextInspection"/>
+    <localInspection groupPath="Java" language="JAVA" suppressId="WaitNotifyWhileNotSynced" shortName="WaitNotifyNotInSynchronizedContext"
+                     bundle="com.siyeh.InspectionGadgetsBundle" key="wait.notify.not.in.synchronized.context.display.name"
+                     groupBundle="messages.InspectionsBundle" groupKey="group.names.threading.issues" enabledByDefault="false" level="WARNING"
+                     implementationClass="com.siyeh.ig.threading.WaitNotifyNotInSynchronizedContextInspection"/>
     <localInspection groupPath="Java" language="JAVA" shortName="WaitOrAwaitWithoutTimeout" bundle="com.siyeh.InspectionGadgetsBundle"
                      key="wait.or.await.without.timeout.display.name" groupBundle="messages.InspectionsBundle"
                      groupKey="group.names.threading.issues" enabledByDefault="false" level="WARNING"
index d7f7da3307f93a8758c6ff2e6480e6ab220d2c66..9c0fc63d5657613c722ab55a3bae3c19dbc6b595 100644 (file)
@@ -725,7 +725,6 @@ unnecessary.constructor.display.name=Redundant no-arg constructor
 method.name.same.as.parent.name.display.name=Method name same as parent class name
 while.can.be.foreach.display.name='while' loop replaceable with 'foreach'
 big.decimal.equals.display.name='equals()' called on 'java.math.BigDecimal'
-wait.not.in.synchronized.context.display.name='wait()' while not synchronized
 implicit.call.to.super.display.name=Implicit call to 'super()'
 empty.catch.block.display.name=Empty 'catch' block
 unqualified.static.usage.display.name=Unqualified static access
@@ -739,7 +738,6 @@ unnecessary.this.ignore.assignments.option=Ignore field assignments
 runtime.exec.with.non.constant.string.display.name=Call to 'Runtime.exec()' with non-constant string
 system.properties.display.name=Access of system properties
 chained.method.call.display.name=Chained method calls
-notify.not.in.synchronized.context.display.name='notify()' or 'notifyAll()' while not synchronized
 safe.lock.display.name=Lock acquired but not safely unlocked
 system.run.finalizers.on.exit.display.name=Call to 'System.runFinalizersOnExit()'
 for.can.be.foreach.display.name='for' loop replaceable with 'foreach'
@@ -1016,9 +1014,7 @@ wait.not.in.loop.problem.descriptor=Call to <code>#ref()</code> is not made in a
 await.not.in.loop.problem.descriptor=Call to <code>#ref()</code> is not made in a loop #loc
 wait.called.on.condition.problem.descriptor=Call to <code>#ref()</code> on Condition object #loc
 notify.called.on.condition.problem.descriptor=Call to <code>#ref()</code> on Condition object #loc
-wait.not.in.synchronized.context.problem.descriptor=Call to <code>#ref</code> while not synchronized on ''{0}'' #loc
 wait.while.holding.two.locks.problem.descriptor=Call to <code>#ref()</code> is made while holding two locks #loc
-notify.not.in.synchronized.context.problem.descriptor=Call to <code>#ref()</code> is made outside of a synchronized context #loc
 thread.run.problem.descriptor=Calls to <code>#ref()</code> should probably be replaced with 'start()' #loc
 thread.start.in.construction.problem.descriptor=Call to <code>#ref</code> during object construction #loc
 synchronize.on.lock.problem.descriptor=Synchronization on a ''{0}'' object is unlikely to be intentional #loc
@@ -2199,4 +2195,6 @@ malformed.set.up.tear.down.problem.descriptor='#ref()' has incorrect signature #
 method.missing.return.statement.display.name=Method contains logic but is missing a 'return' statement
 method.missing.return.statement.problem.descriptor=Method <code>#ref</code> contains logic but is missing a 'return' statement
 overly.long.lambda.display.name=Overly long lambda expression
-overly.long.lambda.problem.descriptor=Lambda expression is too long (# Non-comment source statements = {0}) #loc
\ No newline at end of file
+overly.long.lambda.problem.descriptor=Lambda expression is too long (# Non-comment source statements = {0}) #loc
+wait.notify.not.in.synchronized.context.display.name='wait()' or 'notify()' while not synchronized
+wait.notify.while.not.synchronized.on.problem.descriptor=Call to <code>#ref</code> while not synchronized on ''{0}'' #loc
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/NotifyNotInSynchronizedContextInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/NotifyNotInSynchronizedContextInspection.java
deleted file mode 100644 (file)
index a985ff9..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.siyeh.ig.threading;
-
-import com.intellij.psi.PsiMethod;
-import com.intellij.psi.PsiMethodCallExpression;
-import com.intellij.psi.PsiParameterList;
-import com.intellij.psi.PsiReferenceExpression;
-import com.siyeh.HardcodedMethodConstants;
-import com.siyeh.InspectionGadgetsBundle;
-import com.siyeh.ig.BaseInspection;
-import com.siyeh.ig.BaseInspectionVisitor;
-import com.siyeh.ig.psiutils.SynchronizationUtil;
-import org.jetbrains.annotations.NotNull;
-
-public class NotifyNotInSynchronizedContextInspection
-  extends BaseInspection {
-
-  @Override
-  @NotNull
-  public String getDisplayName() {
-    return InspectionGadgetsBundle.message(
-      "notify.not.in.synchronized.context.display.name");
-  }
-
-  @Override
-  @NotNull
-  protected String buildErrorString(Object... infos) {
-    return InspectionGadgetsBundle.message(
-      "notify.not.in.synchronized.context.problem.descriptor");
-  }
-
-  @Override
-  public BaseInspectionVisitor buildVisitor() {
-    return new NotifyNotInSynchronizedContextVisitor();
-  }
-
-  private static class NotifyNotInSynchronizedContextVisitor
-    extends BaseInspectionVisitor {
-
-    @Override
-    public void visitMethodCallExpression(
-      @NotNull PsiMethodCallExpression expression) {
-      final PsiReferenceExpression methodExpression =
-        expression.getMethodExpression();
-      final String methodName = methodExpression.getReferenceName();
-      if (!HardcodedMethodConstants.NOTIFY.equals(methodName) &&
-          !HardcodedMethodConstants.NOTIFY_ALL.equals(methodName)) {
-        return;
-      }
-      final PsiMethod method = expression.resolveMethod();
-      if (method == null) {
-        return;
-      }
-      final PsiParameterList parameterList = method.getParameterList();
-      if (parameterList.getParametersCount() != 0) {
-        return;
-      }
-      if (SynchronizationUtil.isInSynchronizedContext(expression)) {
-        return;
-      }
-      registerMethodCallError(expression);
-    }
-  }
-}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/WaitNotInSynchronizedContextInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/WaitNotInSynchronizedContextInspection.java
deleted file mode 100644 (file)
index 8074217..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.siyeh.ig.threading;
-
-import com.intellij.psi.*;
-import com.intellij.psi.util.PsiTreeUtil;
-import com.siyeh.HardcodedMethodConstants;
-import com.siyeh.InspectionGadgetsBundle;
-import com.siyeh.ig.BaseInspection;
-import com.siyeh.ig.BaseInspectionVisitor;
-import org.jetbrains.annotations.NonNls;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-public class WaitNotInSynchronizedContextInspection
-  extends BaseInspection {
-
-  @Override
-  @NotNull
-  public String getID() {
-    return "WaitWhileNotSynced";
-  }
-
-  @Override
-  @NotNull
-  public String getDisplayName() {
-    return InspectionGadgetsBundle.message(
-      "wait.not.in.synchronized.context.display.name");
-  }
-
-  @Override
-  @NotNull
-  protected String buildErrorString(Object... infos) {
-    @NonNls final String text;
-    if (infos.length > 0) {
-      final PsiElement element = (PsiElement)infos[0];
-      text = element.getText();
-    }
-    else {
-      text = PsiKeyword.THIS;
-    }
-    return InspectionGadgetsBundle.message(
-      "wait.not.in.synchronized.context.problem.descriptor", text);
-  }
-
-  @Override
-  public BaseInspectionVisitor buildVisitor() {
-    return new WaitNotInSynchronizedContextVisitor();
-  }
-
-  private static class WaitNotInSynchronizedContextVisitor
-    extends BaseInspectionVisitor {
-
-    @Override
-    public void visitMethodCallExpression(
-      @NotNull PsiMethodCallExpression expression) {
-      super.visitMethodCallExpression(expression);
-      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 PsiClass aClass = method.getContainingClass();
-      if (aClass == null) {
-        return;
-      }
-      final String qualifiedName = aClass.getQualifiedName();
-      if (!CommonClassNames.JAVA_LANG_OBJECT.equals(qualifiedName)) {
-        return;
-      }
-      final PsiExpression qualifier =
-        methodExpression.getQualifierExpression();
-      if (qualifier == null ||
-          qualifier instanceof PsiThisExpression ||
-          qualifier instanceof PsiSuperExpression) {
-        if (isSynchronizedOnThis(expression)) {
-          return;
-        }
-        registerError(expression);
-      }
-      else if (qualifier instanceof PsiReferenceExpression) {
-        final PsiReferenceExpression referenceExpression =
-          (PsiReferenceExpression)qualifier;
-        final PsiElement target = referenceExpression.resolve();
-        if (isSynchronizedOn(expression, target)) {
-          return;
-        }
-        registerError(expression, qualifier);
-      }
-    }
-
-    private static boolean isSynchronizedOn(@NotNull PsiElement element,
-                                            @Nullable PsiElement target) {
-      if (target == null) {
-        return false;
-      }
-      final PsiElement context =
-        PsiTreeUtil.getParentOfType(element,
-                                    PsiSynchronizedStatement.class);
-      if (context == null) {
-        return false;
-      }
-      final PsiSynchronizedStatement synchronizedStatement =
-        (PsiSynchronizedStatement)context;
-      final PsiExpression lockExpression =
-        synchronizedStatement.getLockExpression();
-      if (!(lockExpression instanceof PsiReferenceExpression)) {
-        return false;
-      }
-      final PsiReferenceExpression referenceExpression =
-        (PsiReferenceExpression)lockExpression;
-      final PsiElement lockTarget = referenceExpression.resolve();
-      return target.equals(lockTarget) ||
-             isSynchronizedOn(synchronizedStatement, target);
-    }
-
-    private static boolean isSynchronizedOnThis(
-      @NotNull PsiElement element) {
-      final PsiElement context =
-        PsiTreeUtil.getParentOfType(element, PsiMethod.class,
-                                    PsiSynchronizedStatement.class);
-      if (context instanceof PsiSynchronizedStatement) {
-        final PsiSynchronizedStatement synchronizedStatement =
-          (PsiSynchronizedStatement)context;
-        final PsiExpression lockExpression =
-          synchronizedStatement.getLockExpression();
-        return lockExpression instanceof PsiThisExpression ||
-               isSynchronizedOnThis(synchronizedStatement);
-      }
-      else if (context instanceof PsiMethod) {
-        final PsiMethod method = (PsiMethod)context;
-        if (method.hasModifierProperty(PsiModifier.SYNCHRONIZED)) {
-          return true;
-        }
-      }
-      return false;
-    }
-  }
-}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/WaitNotifyNotInSynchronizedContextInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/WaitNotifyNotInSynchronizedContextInspection.java
new file mode 100644 (file)
index 0000000..9abfdc0
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.siyeh.ig.threading;
+
+import com.intellij.psi.*;
+import com.intellij.psi.util.PsiTreeUtil;
+import com.siyeh.HardcodedMethodConstants;
+import com.siyeh.InspectionGadgetsBundle;
+import com.siyeh.ig.BaseInspection;
+import com.siyeh.ig.BaseInspectionVisitor;
+import com.siyeh.ig.psiutils.EquivalenceChecker;
+import com.siyeh.ig.psiutils.ParenthesesUtils;
+import org.jetbrains.annotations.Nls;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author Bas Leijdekkers
+ */
+public class WaitNotifyNotInSynchronizedContextInspection extends BaseInspection {
+
+  @Override
+  public boolean isSuppressedFor(@NotNull PsiElement element) {
+    return super.isSuppressedFor(element);
+  }
+
+  @Nls
+  @NotNull
+  @Override
+  public String getDisplayName() {
+    return InspectionGadgetsBundle.message("wait.notify.not.in.synchronized.context.display.name");
+  }
+
+  @Override
+  @NotNull
+  protected String buildErrorString(Object... infos) {
+    final String text = (String)infos[0];
+    return InspectionGadgetsBundle.message("wait.notify.while.not.synchronized.on.problem.descriptor", text);
+  }
+
+  @Override
+  public BaseInspectionVisitor buildVisitor() {
+    return new WaiNotifyNotInSynchronizedContextVisitor();
+  }
+
+  private static class WaiNotifyNotInSynchronizedContextVisitor extends BaseInspectionVisitor {
+
+    @Override
+    public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) {
+      super.visitMethodCallExpression(expression);
+      final PsiReferenceExpression methodExpression = expression.getMethodExpression();
+      @NonNls final String methodName = methodExpression.getReferenceName();
+      if (!HardcodedMethodConstants.WAIT.equals(methodName) &&
+          !HardcodedMethodConstants.NOTIFY.equals(methodName) &&
+          !HardcodedMethodConstants.NOTIFY_ALL.equals(methodName)) {
+        return;
+      }
+      final PsiMethod method = expression.resolveMethod();
+      if (method == null) {
+        return;
+      }
+      final PsiClass aClass = method.getContainingClass();
+      if (aClass == null) {
+        return;
+      }
+      final String qualifiedName = aClass.getQualifiedName();
+      if (!CommonClassNames.JAVA_LANG_OBJECT.equals(qualifiedName)) {
+        return;
+      }
+      final PsiExpression qualifier = ParenthesesUtils.stripParentheses(methodExpression.getQualifierExpression());
+      if (qualifier == null || qualifier instanceof PsiThisExpression || qualifier instanceof PsiSuperExpression) {
+        if (isSynchronizedOnThis(expression)) {
+          return;
+        }
+        registerError(expression, PsiKeyword.THIS);
+      }
+      else if (qualifier instanceof PsiReferenceExpression) {
+        if (isSynchronizedOn(expression, qualifier)) {
+          return;
+        }
+        registerError(expression, qualifier.getText());
+      }
+    }
+
+    private static boolean isSynchronizedOn(@NotNull PsiElement element, @NotNull PsiExpression target) {
+      final PsiElement context = PsiTreeUtil.getParentOfType(element, PsiSynchronizedStatement.class);
+      if (context == null) {
+        return false;
+      }
+      final PsiSynchronizedStatement synchronizedStatement = (PsiSynchronizedStatement)context;
+      final PsiExpression lockExpression = ParenthesesUtils.stripParentheses(synchronizedStatement.getLockExpression());
+      final EquivalenceChecker checker = EquivalenceChecker.getCanonicalPsiEquivalence();
+      return checker.expressionsAreEquivalent(lockExpression, target) || isSynchronizedOn(synchronizedStatement, target);
+    }
+
+    private static boolean isSynchronizedOnThis(@NotNull PsiElement element) {
+      final PsiElement context = PsiTreeUtil.getParentOfType(element, PsiMethod.class, PsiSynchronizedStatement.class);
+      if (context instanceof PsiSynchronizedStatement) {
+        final PsiSynchronizedStatement synchronizedStatement = (PsiSynchronizedStatement)context;
+        final PsiExpression lockExpression = ParenthesesUtils.stripParentheses(synchronizedStatement.getLockExpression());
+        return lockExpression instanceof PsiThisExpression || isSynchronizedOnThis(synchronizedStatement);
+      }
+      else if (context instanceof PsiMethod) {
+        final PsiMethod method = (PsiMethod)context;
+        if (method.hasModifierProperty(PsiModifier.SYNCHRONIZED)) {
+          return true;
+        }
+      }
+      return false;
+    }
+  }
+}
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/WaitNotifyNotInSynchronizedContextInspectionMerger.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/WaitNotifyNotInSynchronizedContextInspectionMerger.java
new file mode 100644 (file)
index 0000000..b9791e2
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.siyeh.ig.threading;
+
+import com.intellij.codeInspection.ex.InspectionElementsMerger;
+
+/**
+ * @author Bas Leijdekkers
+ */
+public class WaitNotifyNotInSynchronizedContextInspectionMerger extends InspectionElementsMerger {
+  @Override
+  public String getMergedToolName() {
+    return "WaitNotifyNotInSynchronizedContext";
+  }
+
+  @Override
+  public String[] getSourceToolNames() {
+    return new String[] {
+      "WaitNotInSynchronizedContext",
+      "NotifyNotInSynchronizedContext"
+    };
+  }
+
+  @Override
+  public String[] getSuppressIds() {
+    return new String[]{
+      "WaitWhileNotSynced",
+      "WaitNotInSynchronizedContext"
+    };
+  }
+}
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/NotifyNotInSynchronizedContext.html b/plugins/InspectionGadgets/src/inspectionDescriptions/NotifyNotInSynchronizedContext.html
deleted file mode 100644 (file)
index f014325..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<html>
-<body>
-Reports on any call to <b>notify()</b> not made inside a corresponding synchronized
-statement or synchronized method. Calling <b>notify()</b> on an object
-without holding a lock on that object will result in an IllegalMonitorStateException being thrown.
-Such a construct is not necessarily an error, as the necessary lock may be acquired before
-the containing method is called, but it's worth looking at.
-<!-- tooltip end -->
-<p>
-
-</body>
-</html>
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/WaitNotInSynchronizedContext.html b/plugins/InspectionGadgets/src/inspectionDescriptions/WaitNotInSynchronizedContext.html
deleted file mode 100644 (file)
index 81b11b6..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<html>
-<body>
-Reports on any call to <b>wait()</b> not made inside a corresponding synchronized
-statement or synchronized method. Calling <b>wait()</b> on an object
-without holding a lock on that object will result in an IllegalMonitorStateException being thrown.
-Such a construct is not necessarily an error, as the necessary lock may be acquired before
-the containing method is called, but its worth looking at.
-<!-- tooltip end -->
-<p>
-
-</body>
-</html>
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/WaitNotifyNotInSynchronizedContext.html b/plugins/InspectionGadgets/src/inspectionDescriptions/WaitNotifyNotInSynchronizedContext.html
new file mode 100644 (file)
index 0000000..f68ef0c
--- /dev/null
@@ -0,0 +1,12 @@
+<html>
+<body>
+Reports on any call to <b>wait()</b>, <b>notify()</b> or <b>notifyAll()</b> not made inside a corresponding synchronized
+statement or synchronized method. Calling <b>wait()</b>, <b>notify()</b> or <b>notifyAll()</b> on an object
+without holding a lock on that object will result in an <b>IllegalMonitorStateException</b> being thrown.
+Such a construct is not necessarily an error, as the necessary lock may be acquired before
+the containing method is called, but its worth looking at.
+<!-- tooltip end -->
+<p>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/threading/NotifyNotInSynchronizedContextInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/threading/NotifyNotInSynchronizedContextInspection.java
deleted file mode 100644 (file)
index 5f48ad7..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.siyeh.igtest.threading;
-
-public class NotifyNotInSynchronizedContextInspection
-{
-    private final Object lock = new Object();
-
-    public  void foo()
-    {
-        lock.notify();
-    }
-    public  synchronized void bar()
-    {
-        lock.notify();
-    }
-
-    public  void barzoomb() {
-        synchronized (lock) {
-            lock.notify();
-        }
-    }
-    
-    public  void fooAll()
-    {
-        lock.notifyAll();
-    }
-    public  synchronized void barAll()
-    {
-        lock.notifyAll();
-    }
-
-    public  void barzoombAll() {
-        synchronized (lock) {
-            lock.notifyAll();
-        }
-    }
-}
@@ -1,6 +1,6 @@
 package com.siyeh.igtest.threading.wait_not_in_synchronized_context;
 
-public class WaitNotInSynchronizedContext {
+public class WaitNotifyNotInSynchronizedContext {
   private final Object lock = new Object();
   private final Object otherLock = new Object();
 
@@ -19,7 +19,7 @@ public class WaitNotInSynchronizedContext {
   }
 
   public static void main(String[] args) throws InterruptedException {
-    new WaitNotInSynchronizedContext().foo();
+    new WaitNotifyNotInSynchronizedContext().foo();
   }
 
 }
@@ -38,3 +38,37 @@ class More {
     }
   }
 }
+class NotifyNotInSynchronizedContext
+{
+  private final Object lock = new Object();
+
+  public  void foo()
+  {
+    <warning descr="Call to 'lock.notify()' while not synchronized on 'lock'">lock.notify()</warning>;
+  }
+  public  synchronized void bar()
+  {
+    <warning descr="Call to 'lock.notify()' while not synchronized on 'lock'">lock.notify()</warning>;
+  }
+
+  public  void barzoomb() {
+    synchronized (lock) {
+      lock.notify();
+    }
+  }
+
+  public  void fooAll()
+  {
+    <warning descr="Call to 'lock.notifyAll()' while not synchronized on 'lock'">lock.notifyAll()</warning>;
+  }
+  public  synchronized void barAll()
+  {
+    <warning descr="Call to 'lock.notifyAll()' while not synchronized on 'lock'">lock.notifyAll()</warning>;
+  }
+
+  public  void barzoombAll() {
+    synchronized (lock) {
+      lock.notifyAll();
+    }
+  }
+}
similarity index 80%
rename from plugins/InspectionGadgets/testsrc/com/siyeh/ig/threading/WaitNotInSynchronizedContextInspectionTest.java
rename to plugins/InspectionGadgets/testsrc/com/siyeh/ig/threading/WaitNotifyNotInSynchronizedContextInspectionTest.java
index 4c229dba3ffce8ab1eadc7d747b765832efb215c..c1554f9791714b21ad3eb7a9019381ca5b5ec016 100644 (file)
@@ -19,15 +19,15 @@ import com.intellij.codeInspection.InspectionProfileEntry;
 import com.siyeh.ig.LightInspectionTestCase;
 import org.jetbrains.annotations.Nullable;
 
-public class WaitNotInSynchronizedContextInspectionTest extends LightInspectionTestCase {
+public class WaitNotifyNotInSynchronizedContextInspectionTest extends LightInspectionTestCase {
 
-  public void testWaitNotInSynchronizedContext() {
+  public void testWaitNotifyNotInSynchronizedContext() {
     doTest();
   }
 
   @Nullable
   @Override
   protected InspectionProfileEntry getInspection() {
-    return new WaitNotInSynchronizedContextInspection();
+    return new WaitNotifyNotInSynchronizedContextInspection();
   }
 }
\ No newline at end of file