diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/AbstractMethodWithMissingImplementationsInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/AbstractMethodWithMissingImplementationsInspection.java index aa74dc2498a8..bada670da023 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/AbstractMethodWithMissingImplementationsInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/inheritance/AbstractMethodWithMissingImplementationsInspection.java @@ -67,7 +67,7 @@ public class AbstractMethodWithMissingImplementationsInspection if (containingClass == null) { return; } - if (!containingClass.isInterface() && + if (!containingClass.isInterface() || !method.hasModifierProperty(PsiModifier.ABSTRACT)) { return; } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/maturity/ThrowablePrintStackTraceInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/maturity/ThrowablePrintStackTraceInspection.java index 8a48858fe78b..e7e90e003985 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/maturity/ThrowablePrintStackTraceInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/maturity/ThrowablePrintStackTraceInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2013 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. @@ -15,17 +15,24 @@ */ package com.siyeh.ig.maturity; -import com.intellij.psi.PsiExpressionList; -import com.intellij.psi.PsiMethodCallExpression; +import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel; +import com.intellij.psi.*; import com.siyeh.HardcodedMethodConstants; import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.BaseInspection; import com.siyeh.ig.BaseInspectionVisitor; import com.siyeh.ig.psiutils.MethodCallUtils; +import com.siyeh.ig.psiutils.TestUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; public class ThrowablePrintStackTraceInspection extends BaseInspection { + @SuppressWarnings("PublicField") + public boolean ignoreInTestCode = false; + @Override @NotNull public String getID() { @@ -35,15 +42,19 @@ public class ThrowablePrintStackTraceInspection extends BaseInspection { @Override @NotNull public String getDisplayName() { - return InspectionGadgetsBundle.message( - "printstacktrace.call.display.name"); + return InspectionGadgetsBundle.message("printstacktrace.call.display.name"); } @Override @NotNull public String buildErrorString(Object... infos) { - return InspectionGadgetsBundle.message( - "printstacktrace.call.problem.descriptor"); + return InspectionGadgetsBundle.message("printstacktrace.call.problem.descriptor"); + } + + @Nullable + @Override + public JComponent createOptionsPanel() { + return new SingleCheckboxOptionsPanel(InspectionGadgetsBundle.message("ignore.in.test.code"), this, "ignoreInTestCode"); } @Override @@ -51,22 +62,34 @@ public class ThrowablePrintStackTraceInspection extends BaseInspection { return new ThrowablePrintStackTraceVisitor(); } - private static class ThrowablePrintStackTraceVisitor - extends BaseInspectionVisitor { + private class ThrowablePrintStackTraceVisitor extends BaseInspectionVisitor { @Override - public void visitMethodCallExpression( - @NotNull PsiMethodCallExpression expression) { + public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) { super.visitMethodCallExpression(expression); final String methodName = MethodCallUtils.getMethodName(expression); - if (!HardcodedMethodConstants.PRINT_STACK_TRACE.equals( - methodName)) { + if (!HardcodedMethodConstants.PRINT_STACK_TRACE.equals(methodName)) { return; } final PsiExpressionList argumentList = expression.getArgumentList(); if (argumentList.getExpressions().length != 0) { return; } + final PsiMethod method = expression.resolveMethod(); + if (method == null) { + return; + } + final PsiClass containingClass = method.getContainingClass(); + if (containingClass == null) { + return; + } + final String name = containingClass.getQualifiedName(); + if (!CommonClassNames.JAVA_LANG_THROWABLE.equals(name)) { + return; + } + if (ignoreInTestCode && TestUtils.isInTestCode(expression)) { + return; + } registerMethodCallError(expression); } } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/inheritance/abstract_method_with_missing_implementations/AbstractMethodWithMissingImplementations.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/inheritance/abstract_method_with_missing_implementations/AbstractMethodWithMissingImplementations.java new file mode 100644 index 000000000000..f6743260c5ea --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/inheritance/abstract_method_with_missing_implementations/AbstractMethodWithMissingImplementations.java @@ -0,0 +1,9 @@ +package com.siyeh.igtest.inheritance.abstract_method_with_missing_implementations; + +class WithDefaultMethods { + interface A { + default void foo() {} + } + + class B implements A {} +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/inheritance/abstract_method_with_missing_implementations/expected.xml b/plugins/InspectionGadgets/test/com/siyeh/igtest/inheritance/abstract_method_with_missing_implementations/expected.xml new file mode 100644 index 000000000000..4704d91e891d --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/inheritance/abstract_method_with_missing_implementations/expected.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/maturity/ThrowablePrintStackTraceInspection.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/maturity/ThrowablePrintStackTraceInspection.java deleted file mode 100644 index fb06eb5c9ba8..000000000000 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/maturity/ThrowablePrintStackTraceInspection.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.siyeh.igtest.maturity; - -import java.io.IOException; -import java.io.PrintStream; - -public class ThrowablePrintStackTraceInspection -{ - public ThrowablePrintStackTraceInspection() - { - } - - public void foo() - { - new Throwable().printStackTrace(); - } -} \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/ThrowablePrintStackTraceInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/ThrowablePrintStackTraceInspectionTest.java new file mode 100644 index 000000000000..2da012333ee8 --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/ThrowablePrintStackTraceInspectionTest.java @@ -0,0 +1,46 @@ +/* + * Copyright 2000-2013 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; + +import com.intellij.codeInspection.InspectionProfileEntry; +import com.siyeh.ig.maturity.ThrowablePrintStackTraceInspection; + +/** + * @author Bas Leijdekkers + */ +public class ThrowablePrintStackTraceInspectionTest extends LightInspectionTestCase { + + public void testSimple() { + doStatementTest("new Throwable()./*Call to 'printStackTrace()' should probably be replaced with more robust logging*/printStackTrace/**/();"); + } + + public void testInTestCode() { + addEnvironmentClass("package org.junit;" + + "@Retention(RetentionPolicy.RUNTIME) " + + "@Target({ElementType.METHOD}) " + + "public @interface Test {}"); + doMemberTest("@org.junit.Test public void testSomething() {" + + " new RuntimeException().printStackTrace();" + + "}"); + } + + @Override + protected InspectionProfileEntry getInspection() { + final ThrowablePrintStackTraceInspection inspection = new ThrowablePrintStackTraceInspection(); + inspection.ignoreInTestCode = true; + return inspection; + } +} diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/AbstractMethodWithMissingImplementationsInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/AbstractMethodWithMissingImplementationsInspectionTest.java new file mode 100644 index 000000000000..6df8511ca6c9 --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/AbstractMethodWithMissingImplementationsInspectionTest.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2013 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.inheritance; + +import com.siyeh.ig.IGInspectionTestCase; + +public class AbstractMethodWithMissingImplementationsInspectionTest extends IGInspectionTestCase { + + public void test() throws Exception { + final AbstractMethodWithMissingImplementationsInspection tool = new AbstractMethodWithMissingImplementationsInspection(); + doTest("com/siyeh/igtest/inheritance/abstract_method_with_missing_implementations", tool); + } +} diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrAssignabilityTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrAssignabilityTest.groovy index af78e1848081..0709db7b9a51 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrAssignabilityTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GrAssignabilityTest.groovy @@ -690,7 +690,7 @@ interface I {} def T foo1(Class x = String ) {} def T foo2(Class x = PsiElement ) {} def T foo3(Class x = PsiElement ) {} -def T foo4(Class x = PsiElement ) {} +def T foo4(Class x = PsiElement ) {} def T foo5(Class x = Foo ) {} ''') }