From f8924a9d29792e98aca369488e21cd04cdd7d9f2 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 26 Oct 2017 12:07:50 +0200 Subject: [PATCH] [junit] do not check for type annotations (IDEA-181206) --- .../execution/junit/JUnit4Framework.java | 28 +++++-------------- .../execution/junit/JUnit5Framework.java | 24 ++++------------ .../intellij/execution/junit/TestMethod.java | 18 ++---------- .../JUnit5MalformedParameterizedInspection.kt | 5 ++-- .../junit2/inspection/JUnitEntryPoint.java | 19 ++----------- .../JUnitImplicitUsageProvider.java | 22 ++------------- 6 files changed, 21 insertions(+), 95 deletions(-) diff --git a/plugins/junit/src/com/intellij/execution/junit/JUnit4Framework.java b/plugins/junit/src/com/intellij/execution/junit/JUnit4Framework.java index 666d4068a156..530a59145f26 100644 --- a/plugins/junit/src/com/intellij/execution/junit/JUnit4Framework.java +++ b/plugins/junit/src/com/intellij/execution/junit/JUnit4Framework.java @@ -1,18 +1,4 @@ -/* - * 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.junit; import com.intellij.CommonBundle; @@ -70,7 +56,7 @@ public class JUnit4Framework extends JavaTestFramework { @Override protected PsiMethod findSetUpMethod(@NotNull PsiClass clazz) { for (PsiMethod each : clazz.getMethods()) { - if (AnnotationUtil.isAnnotated(each, JUnitUtil.BEFORE_ANNOTATION_NAME, false)) return each; + if (AnnotationUtil.isAnnotated(each, JUnitUtil.BEFORE_ANNOTATION_NAME, 0)) return each; } return null; } @@ -79,7 +65,7 @@ public class JUnit4Framework extends JavaTestFramework { @Override protected PsiMethod findTearDownMethod(@NotNull PsiClass clazz) { for (PsiMethod each : clazz.getMethods()) { - if (AnnotationUtil.isAnnotated(each, JUnitUtil.AFTER_ANNOTATION_NAME, false)) return each; + if (AnnotationUtil.isAnnotated(each, JUnitUtil.AFTER_ANNOTATION_NAME, 0)) return each; } return null; } @@ -102,7 +88,7 @@ public class JUnit4Framework extends JavaTestFramework { method = createSetUpPatternMethod(factory); PsiMethod existingMethod = clazz.findMethodBySignature(method, false); if (existingMethod != null) { - if (AnnotationUtil.isAnnotated(existingMethod, beforeClassAnnotationName, false)) return existingMethod; + if (AnnotationUtil.isAnnotated(existingMethod, beforeClassAnnotationName, 0)) return existingMethod; int exit = ApplicationManager.getApplication().isUnitTestMode() ? Messages.OK : Messages.showOkCancelDialog("Method setUp already exist but is not annotated as @Before. Annotate?", @@ -127,7 +113,7 @@ public class JUnit4Framework extends JavaTestFramework { @Override public boolean isIgnoredMethod(PsiElement element) { final PsiMethod testMethod = element instanceof PsiMethod ? JUnitUtil.getTestMethod(element) : null; - return testMethod != null && AnnotationUtil.isAnnotated(testMethod, JUnitUtil.IGNORE_ANNOTATION, false); + return testMethod != null && AnnotationUtil.isAnnotated(testMethod, JUnitUtil.IGNORE_ANNOTATION, 0); } @Override @@ -189,9 +175,9 @@ public class JUnit4Framework extends JavaTestFramework { public PsiMethod findParametersMethod(PsiClass clazz) { final PsiMethod[] methods = clazz.getAllMethods(); for (PsiMethod method : methods) { - if (method.hasModifierProperty(PsiModifier.PUBLIC) && + if (method.hasModifierProperty(PsiModifier.PUBLIC) && method.hasModifierProperty(PsiModifier.STATIC) && - AnnotationUtil.isAnnotated(method, "org.junit.runners.Parameterized.Parameters", false)) { + AnnotationUtil.isAnnotated(method, "org.junit.runners.Parameterized.Parameters", 0)) { //todo check return value return method; } diff --git a/plugins/junit/src/com/intellij/execution/junit/JUnit5Framework.java b/plugins/junit/src/com/intellij/execution/junit/JUnit5Framework.java index 9cf4f19521d6..ca7cc7fef22b 100644 --- a/plugins/junit/src/com/intellij/execution/junit/JUnit5Framework.java +++ b/plugins/junit/src/com/intellij/execution/junit/JUnit5Framework.java @@ -1,18 +1,4 @@ -/* - * 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.junit; import com.intellij.CommonBundle; @@ -70,7 +56,7 @@ public class JUnit5Framework extends JavaTestFramework { @Override protected PsiMethod findSetUpMethod(@NotNull PsiClass clazz) { for (PsiMethod each : clazz.getMethods()) { - if (AnnotationUtil.isAnnotated(each, JUnitUtil.BEFORE_EACH_ANNOTATION_NAME, false)) return each; + if (AnnotationUtil.isAnnotated(each, JUnitUtil.BEFORE_EACH_ANNOTATION_NAME, 0)) return each; } return null; } @@ -79,7 +65,7 @@ public class JUnit5Framework extends JavaTestFramework { @Override protected PsiMethod findTearDownMethod(@NotNull PsiClass clazz) { for (PsiMethod each : clazz.getMethods()) { - if (AnnotationUtil.isAnnotated(each, JUnitUtil.AFTER_EACH_ANNOTATION_NAME, false)) return each; + if (AnnotationUtil.isAnnotated(each, JUnitUtil.AFTER_EACH_ANNOTATION_NAME, 0)) return each; } return null; } @@ -96,7 +82,7 @@ public class JUnit5Framework extends JavaTestFramework { method = createSetUpPatternMethod(factory); PsiMethod existingMethod = clazz.findMethodBySignature(method, false); if (existingMethod != null) { - if (AnnotationUtil.isAnnotated(existingMethod, JUnitUtil.BEFORE_ALL_ANNOTATION_NAME, false)) return existingMethod; + if (AnnotationUtil.isAnnotated(existingMethod, JUnitUtil.BEFORE_ALL_ANNOTATION_NAME, 0)) return existingMethod; int exit = ApplicationManager.getApplication().isUnitTestMode() ? Messages.OK : Messages.showOkCancelDialog("Method setUp already exist but is not annotated as @BeforeEach. Annotate?", @@ -121,7 +107,7 @@ public class JUnit5Framework extends JavaTestFramework { @Override public boolean isIgnoredMethod(PsiElement element) { final PsiMethod testMethod = element instanceof PsiMethod ? JUnitUtil.getTestMethod(element) : null; - return testMethod != null && AnnotationUtil.isAnnotated(testMethod, JUnitUtil.IGNORE_ANNOTATION, false); + return testMethod != null && AnnotationUtil.isAnnotated(testMethod, JUnitUtil.IGNORE_ANNOTATION, 0); } @Override diff --git a/plugins/junit/src/com/intellij/execution/junit/TestMethod.java b/plugins/junit/src/com/intellij/execution/junit/TestMethod.java index 05c01c4de37f..340e3c89e73b 100644 --- a/plugins/junit/src/com/intellij/execution/junit/TestMethod.java +++ b/plugins/junit/src/com/intellij/execution/junit/TestMethod.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2009 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.junit; @@ -127,7 +113,7 @@ class TestMethod extends TestObject { throw new RuntimeConfigurationWarning(ExecutionBundle.message("test.method.doesnt.exist.error.message", methodName)); } - if (!AnnotationUtil.isAnnotated(psiClass, JUnitUtil.RUN_WITH, true) && !testAnnotated) { + if (!AnnotationUtil.isAnnotated(psiClass, JUnitUtil.RUN_WITH, AnnotationUtil.CHECK_HIERARCHY) && !testAnnotated) { try { final PsiClass testCaseClass = JUnitUtil.getTestCaseClass(configurationModule.getModule()); if (!psiClass.isInheritor(testCaseClass, true)) { diff --git a/plugins/junit/src/com/intellij/execution/junit/codeInsight/JUnit5MalformedParameterizedInspection.kt b/plugins/junit/src/com/intellij/execution/junit/codeInsight/JUnit5MalformedParameterizedInspection.kt index 31d962c1dfdc..c09b3a102773 100644 --- a/plugins/junit/src/com/intellij/execution/junit/codeInsight/JUnit5MalformedParameterizedInspection.kt +++ b/plugins/junit/src/com/intellij/execution/junit/codeInsight/JUnit5MalformedParameterizedInspection.kt @@ -220,7 +220,7 @@ class JUnit5MalformedParameterizedInspection : AbstractBaseJavaLocalInspectionTo if (qualifiedName != null && qualifiedName.startsWith("java.time.")) return } } - if (AnnotationUtil.isAnnotated(parameters[0], JUnitCommonClassNames.ORG_JUNIT_JUPITER_PARAMS_CONVERTER_CONVERT_WITH, false)) return + if (AnnotationUtil.isAnnotated(parameters[0], JUnitCommonClassNames.ORG_JUNIT_JUPITER_PARAMS_CONVERTER_CONVERT_WITH, 0)) return holder.registerProblem(attributeValue, "No implicit conversion found to convert object of type " + componentType.presentableText + " to " + paramType.presentableText) } @@ -257,8 +257,7 @@ class JUnit5MalformedParameterizedInspection : AbstractBaseJavaLocalInspectionTo !InheritanceUtil.isInheritor(it.type, JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_TEST_INFO) && !InheritanceUtil.isInheritor(it.type, JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_TEST_REPORTER) } - .count() > 1 && !AnnotationUtil.isAnnotated(method, Collections.singleton( - JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_EXTENSION_EXTEND_WITH)) + .count() > 1 && !AnnotationUtil.isAnnotated(method, JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_EXTENSION_EXTEND_WITH, 0) } } diff --git a/plugins/junit/src/com/intellij/execution/junit2/inspection/JUnitEntryPoint.java b/plugins/junit/src/com/intellij/execution/junit2/inspection/JUnitEntryPoint.java index f1f83d4eae0f..ecbde9f464f3 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/inspection/JUnitEntryPoint.java +++ b/plugins/junit/src/com/intellij/execution/junit2/inspection/JUnitEntryPoint.java @@ -1,23 +1,8 @@ -/* - * 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.junit2.inspection; import com.intellij.codeInsight.AnnotationUtil; -import com.intellij.codeInspection.reference.EntryPoint; import com.intellij.codeInspection.reference.RefElement; import com.intellij.codeInspection.visibility.EntryPointWithVisibilityLevel; import com.intellij.execution.junit.JUnitUtil; @@ -75,7 +60,7 @@ public class JUnitEntryPoint extends EntryPointWithVisibilityLevel { if (JUnitUtil.isTestMethodOrConfig(method)) return true; } else if (psiElement instanceof PsiField) { - return AnnotationUtil.isAnnotated((PsiField)psiElement, JUnitUtil.PARAMETRIZED_PARAMETER_ANNOTATION_NAME, false); + return AnnotationUtil.isAnnotated((PsiField)psiElement, JUnitUtil.PARAMETRIZED_PARAMETER_ANNOTATION_NAME, 0); } return false; } diff --git a/plugins/junit/src/com/intellij/execution/junit2/inspection/JUnitImplicitUsageProvider.java b/plugins/junit/src/com/intellij/execution/junit2/inspection/JUnitImplicitUsageProvider.java index de1a115759c8..8670e9d9250c 100644 --- a/plugins/junit/src/com/intellij/execution/junit2/inspection/JUnitImplicitUsageProvider.java +++ b/plugins/junit/src/com/intellij/execution/junit2/inspection/JUnitImplicitUsageProvider.java @@ -1,18 +1,4 @@ -/* - * 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. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.junit2.inspection; import com.intellij.codeInsight.AnnotationUtil; @@ -46,10 +32,8 @@ public class JUnitImplicitUsageProvider implements ImplicitUsageProvider { @Override public boolean isImplicitWrite(PsiElement element) { - if (element instanceof PsiParameter) { - return AnnotationUtil.isAnnotated((PsiParameter)element, MOCK, false); - } - return element instanceof PsiField && AnnotationUtil.isAnnotated((PsiField) element, INJECTED_FIELD_ANNOTATIONS); + return element instanceof PsiParameter && AnnotationUtil.isAnnotated((PsiParameter)element, MOCK, 0) || + element instanceof PsiField && AnnotationUtil.isAnnotated((PsiField)element, INJECTED_FIELD_ANNOTATIONS, 0); } @Override