diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/VisitorWrappers.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/VisitorWrappers.kt index 5fb93c920f2..62f221c3bb6 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/VisitorWrappers.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/VisitorWrappers.kt @@ -335,6 +335,13 @@ fun referenceExpressionRecursiveVisitor(block: (KtReferenceExpression) -> Unit) } } +fun valueArgumentListVisitor(block: (KtValueArgumentList) -> Unit) = + object : KtVisitorVoid() { + override fun visitValueArgumentList(list: KtValueArgumentList) { + block(list) + } + } + fun valueArgumentVisitor(block: (KtValueArgument) -> Unit) = object : KtVisitorVoid() { override fun visitArgument(valueArgument: KtValueArgument) { diff --git a/idea/resources/inspectionDescriptions/RemoveEmptyParenthesesFromAnnotationEntry.html b/idea/resources/inspectionDescriptions/RemoveEmptyParenthesesFromAnnotationEntry.html new file mode 100644 index 00000000000..48f065a5a86 --- /dev/null +++ b/idea/resources/inspectionDescriptions/RemoveEmptyParenthesesFromAnnotationEntry.html @@ -0,0 +1,14 @@ + + +This inspection reports unnecessary parentheses in annotation entries. For example: +

+
+annotation class MyAnnotation
+
+@MyAnnotation() // There parentheses can be omitted
+fun test() {
+
+}
+
+ + \ No newline at end of file diff --git a/idea/src/META-INF/plugin-common.xml b/idea/src/META-INF/plugin-common.xml index 69ed76bfccf..95e814bf9ab 100644 --- a/idea/src/META-INF/plugin-common.xml +++ b/idea/src/META-INF/plugin-common.xml @@ -3030,6 +3030,15 @@ language="kotlin" /> + + ) +fun test() { + +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/allParameterHaveDefaults.kt.after b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/allParameterHaveDefaults.kt.after new file mode 100644 index 00000000000..cf5dae6b92a --- /dev/null +++ b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/allParameterHaveDefaults.kt.after @@ -0,0 +1,6 @@ +annotation class MyAnnotation(val x: Int = 10) + +@MyAnnotation +fun test() { + +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/annotatedExpr.kt b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/annotatedExpr.kt new file mode 100644 index 00000000000..707ebfc4f3f --- /dev/null +++ b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/annotatedExpr.kt @@ -0,0 +1,7 @@ +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class MyAnnotation + +fun test() { + val x = @MyAnnotation() 5 +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/annotatedExpr.kt.after b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/annotatedExpr.kt.after new file mode 100644 index 00000000000..a7b05a2a76d --- /dev/null +++ b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/annotatedExpr.kt.after @@ -0,0 +1,7 @@ +@Target(AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) +annotation class MyAnnotation + +fun test() { + val x = @MyAnnotation 5 +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/parenthesesWithWhitespace.kt b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/parenthesesWithWhitespace.kt new file mode 100644 index 00000000000..92dda394d47 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/parenthesesWithWhitespace.kt @@ -0,0 +1,8 @@ +annotation class MyAnnotation + +@MyAnnotation( + +) +fun test() { + +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/parenthesesWithWhitespace.kt.after b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/parenthesesWithWhitespace.kt.after new file mode 100644 index 00000000000..7825ad927db --- /dev/null +++ b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/parenthesesWithWhitespace.kt.after @@ -0,0 +1,6 @@ +annotation class MyAnnotation + +@MyAnnotation +fun test() { + +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/requiresArguments.kt b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/requiresArguments.kt new file mode 100644 index 00000000000..72eb95d1869 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/requiresArguments.kt @@ -0,0 +1,9 @@ +// PROBLEM: none +// ERROR: No value passed for parameter 'x' +annotation class MyAnnotation(val x: Int) + +// there is an error but the inspection is not triggered because parentheses are needed in the end +@MyAnnotation() +fun test() { + +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/simple.kt b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/simple.kt new file mode 100644 index 00000000000..d10e32ea35a --- /dev/null +++ b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/simple.kt @@ -0,0 +1,6 @@ +annotation class MyAnnotation + +@MyAnnotation() +fun test() { + +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/simple.kt.after b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/simple.kt.after new file mode 100644 index 00000000000..7825ad927db --- /dev/null +++ b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/simple.kt.after @@ -0,0 +1,6 @@ +annotation class MyAnnotation + +@MyAnnotation +fun test() { + +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/usingJavaAnnotation.1.java b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/usingJavaAnnotation.1.java new file mode 100644 index 00000000000..cefaa896e96 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/usingJavaAnnotation.1.java @@ -0,0 +1 @@ +public @interface MyJavaAnnotation {} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/usingJavaAnnotation.kt b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/usingJavaAnnotation.kt new file mode 100644 index 00000000000..62dffa965d9 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/usingJavaAnnotation.kt @@ -0,0 +1,4 @@ +@MyJavaAnnotation() +fun test() { + +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/usingJavaAnnotation.kt.after b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/usingJavaAnnotation.kt.after new file mode 100644 index 00000000000..52be332ad39 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/usingJavaAnnotation.kt.after @@ -0,0 +1,4 @@ +@MyJavaAnnotation +fun test() { + +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 13642ed658d..96ae1ea4e35 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -4944,6 +4944,49 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { } } + @TestMetadata("idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class RemoveEmptyParenthesesFromAnnotationEntry extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInRemoveEmptyParenthesesFromAnnotationEntry() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("allParameterHaveDefaults.kt") + public void testAllParameterHaveDefaults() throws Exception { + runTest("idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/allParameterHaveDefaults.kt"); + } + + @TestMetadata("annotatedExpr.kt") + public void testAnnotatedExpr() throws Exception { + runTest("idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/annotatedExpr.kt"); + } + + @TestMetadata("parenthesesWithWhitespace.kt") + public void testParenthesesWithWhitespace() throws Exception { + runTest("idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/parenthesesWithWhitespace.kt"); + } + + @TestMetadata("requiresArguments.kt") + public void testRequiresArguments() throws Exception { + runTest("idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/requiresArguments.kt"); + } + + @TestMetadata("simple.kt") + public void testSimple() throws Exception { + runTest("idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/simple.kt"); + } + + @TestMetadata("usingJavaAnnotation.kt") + public void testUsingJavaAnnotation() throws Exception { + runTest("idea/testData/inspectionsLocal/removeEmptyParenthesesFromAnnotationEntry/usingJavaAnnotation.kt"); + } + } + @TestMetadata("idea/testData/inspectionsLocal/removeRedundantBackticks") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)