From 30beb70ce4f8f588af03b89700c65f6afd3826a0 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 25 Sep 2014 16:09:58 +0200 Subject: [PATCH] honor super method contracts --- .../dataFlow/ControlFlowAnalyzer.java | 2 +- .../contractCheck/CheckSuperContract.java | 29 +++++++++++++++++++ .../codeInspection/ContractCheckTest.java | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/inspection/dataFlow/contractCheck/CheckSuperContract.java diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java index 36b195da9b0d..36b633068b87 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/ControlFlowAnalyzer.java @@ -1471,7 +1471,7 @@ public class ControlFlowAnalyzer extends JavaElementVisitor { @Nullable public static PsiAnnotation findContractAnnotation(PsiMethod method) { - return AnnotationUtil.findAnnotation(method, ORG_JETBRAINS_ANNOTATIONS_CONTRACT); + return AnnotationUtil.findAnnotationInHierarchy(method, Collections.singleton(ORG_JETBRAINS_ANNOTATIONS_CONTRACT)); } public static boolean isPure(PsiMethod method) { diff --git a/java/java-tests/testData/inspection/dataFlow/contractCheck/CheckSuperContract.java b/java/java-tests/testData/inspection/dataFlow/contractCheck/CheckSuperContract.java new file mode 100644 index 000000000000..35ca5b837961 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/contractCheck/CheckSuperContract.java @@ -0,0 +1,29 @@ +/* + * Copyright 2000-2014 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. + */ +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +interface I { + @Contract("true->fail") void assertFalse(boolean fail); +} + +class Foo implements I { + + public void assertFalse(boolean fail) { + } + +} diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/ContractCheckTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/ContractCheckTest.java index 5fbc4fbca11b..84ffb5244d96 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/ContractCheckTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/ContractCheckTest.java @@ -36,6 +36,7 @@ public class ContractCheckTest extends LightCodeInsightFixtureTestCase { public void testDelegationWithUnknownArgument() { doTest(); } public void testEqualsUnknownValue() { doTest(); } public void testMissingFail() { doTest(); } + public void testCheckSuperContract() { doTest(); } public void testSignatureIssues() { doTest(); } }