Skip to content

Commit 7a02d5c

Browse files
[kotlin] KTIJ-36028 Do not report package mismatch on the 1st declaration
GitOrigin-RevId: e901b4796921c7288d5766628ed7d4a83ff640cb
1 parent 65d8568 commit 7a02d5c

File tree

12 files changed

+62
-23
lines changed

12 files changed

+62
-23
lines changed

plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/PackageDirectoryMismatchInspection.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class PackageDirectoryMismatchInspection : AbstractKotlinInspection() {
6969
fixes += ChangePackageFix("'${fqNameWithImplicitPrefix.asString()}'", fqNameWithImplicitPrefix)
7070
}
7171

72-
val element = if (directive.textLength != 0) directive else (file.declarations.firstOrNull() ?: file)
72+
val element = if (directive.textLength != 0) directive else file
7373
holder.registerProblem(
7474
element,
7575
KotlinBundle.message("text.package.directive.dont.match.file.location"),

plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/k2/inspections/tests/K2MultiFileInspectionTestGenerated.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,4 @@ public void testKotlinSealedInJavaTest() throws Exception {
9494
runTest("../../../idea/tests/testData/multiFileInspections/kotlinSealedInJavaTest/kotlinSealedInJavaTest.test");
9595
}
9696
}
97-
98-
@RunWith(JUnit3RunnerWithInners.class)
99-
@TestMetadata("../../../idea/tests/testData/multiFileInspections/mismatchedProjectAndDirectoryRoot")
100-
public static class MismatchedProjectAndDirectoryRoot extends AbstractK2MultiFileInspectionTest {
101-
@java.lang.Override
102-
@org.jetbrains.annotations.NotNull
103-
public final KotlinPluginMode getPluginMode() {
104-
return KotlinPluginMode.K2;
105-
}
106-
107-
private void runTest(String testDataFilePath) throws Exception {
108-
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
109-
}
110-
111-
@TestMetadata("mismatchedProjectAndDirectoryRoot.test")
112-
public void testMismatchedProjectAndDirectoryRoot() throws Exception {
113-
runTest("../../../idea/tests/testData/multiFileInspections/mismatchedProjectAndDirectoryRoot/mismatchedProjectAndDirectoryRoot.test");
114-
}
115-
}
11697
}

plugins/kotlin/highlighting/highlighting-k2/test/org/jetbrains/kotlin/idea/k2/highlighting/K2HighlightingMetaInfoTestGenerated.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,11 @@ public void testMismatchPackageDirectoryFileLevelProblem() throws Exception {
615615
runTest("../../idea/tests/testData/highlighterMetaInfo/mismatchPackageDirectoryFileLevelProblem.kt");
616616
}
617617

618+
@TestMetadata("mismatchPackageDirectoryFileLevelProblemDeclarations.kt")
619+
public void testMismatchPackageDirectoryFileLevelProblemDeclarations() throws Exception {
620+
runTest("../../idea/tests/testData/highlighterMetaInfo/mismatchPackageDirectoryFileLevelProblemDeclarations.kt");
621+
}
622+
618623
@TestMetadata("NamedArguments.kt")
619624
public void testNamedArguments() throws Exception {
620625
runTest("../../idea/tests/testData/highlighterMetaInfo/NamedArguments.kt");

plugins/kotlin/highlighting/highlighting-k2/test/org/jetbrains/kotlin/idea/k2/highlighting/metaInfoKmp/CommonNativeJvmK2HighlightingMetaInfoTestGenerated.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ public void testMismatchPackageDirectoryFileLevelProblem() throws Exception {
336336
runTest("../../idea/tests/testData/highlighterMetaInfo/mismatchPackageDirectoryFileLevelProblem.kt");
337337
}
338338

339+
@TestMetadata("mismatchPackageDirectoryFileLevelProblemDeclarations.kt")
340+
public void testMismatchPackageDirectoryFileLevelProblemDeclarations() throws Exception {
341+
runTest("../../idea/tests/testData/highlighterMetaInfo/mismatchPackageDirectoryFileLevelProblemDeclarations.kt");
342+
}
343+
339344
@TestMetadata("NamedArguments.kt")
340345
public void testNamedArguments() throws Exception {
341346
runTest("../../idea/tests/testData/highlighterMetaInfo/NamedArguments.kt");

plugins/kotlin/highlighting/highlighting-k2/test/org/jetbrains/kotlin/idea/k2/highlighting/metaInfoKmp/JsK2HighlightingMetaInfoTestGenerated.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ public void testMismatchPackageDirectoryFileLevelProblem() throws Exception {
336336
runTest("../../idea/tests/testData/highlighterMetaInfo/mismatchPackageDirectoryFileLevelProblem.kt");
337337
}
338338

339+
@TestMetadata("mismatchPackageDirectoryFileLevelProblemDeclarations.kt")
340+
public void testMismatchPackageDirectoryFileLevelProblemDeclarations() throws Exception {
341+
runTest("../../idea/tests/testData/highlighterMetaInfo/mismatchPackageDirectoryFileLevelProblemDeclarations.kt");
342+
}
343+
339344
@TestMetadata("NamedArguments.kt")
340345
public void testNamedArguments() throws Exception {
341346
runTest("../../idea/tests/testData/highlighterMetaInfo/NamedArguments.kt");

plugins/kotlin/highlighting/highlighting-k2/test/org/jetbrains/kotlin/idea/k2/highlighting/metaInfoKmp/NativeLinuxK2HighlightingMetaInfoTestGenerated.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ public void testMismatchPackageDirectoryFileLevelProblem() throws Exception {
336336
runTest("../../idea/tests/testData/highlighterMetaInfo/mismatchPackageDirectoryFileLevelProblem.kt");
337337
}
338338

339+
@TestMetadata("mismatchPackageDirectoryFileLevelProblemDeclarations.kt")
340+
public void testMismatchPackageDirectoryFileLevelProblemDeclarations() throws Exception {
341+
runTest("../../idea/tests/testData/highlighterMetaInfo/mismatchPackageDirectoryFileLevelProblemDeclarations.kt");
342+
}
343+
339344
@TestMetadata("NamedArguments.kt")
340345
public void testNamedArguments() throws Exception {
341346
runTest("../../idea/tests/testData/highlighterMetaInfo/NamedArguments.kt");

plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/highlighter/K1HighlightingMetaInfoTestGenerated.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,11 @@ public void testMismatchPackageDirectoryFileLevelProblem() throws Exception {
620620
runTest("testData/highlighterMetaInfo/mismatchPackageDirectoryFileLevelProblem.kt");
621621
}
622622

623+
@TestMetadata("mismatchPackageDirectoryFileLevelProblemDeclarations.kt")
624+
public void testMismatchPackageDirectoryFileLevelProblemDeclarations() throws Exception {
625+
runTest("testData/highlighterMetaInfo/mismatchPackageDirectoryFileLevelProblemDeclarations.kt");
626+
}
627+
623628
@TestMetadata("NamedArguments.kt")
624629
public void testNamedArguments() throws Exception {
625630
runTest("testData/highlighterMetaInfo/NamedArguments.kt");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fun foo() {
2+
// TODO
3+
// TODO
4+
// TODO
5+
// TODO
6+
}
7+
// TOOL: org.jetbrains.kotlin.idea.k2.codeinsight.inspections.PackageDirectoryMismatchInspection
8+
// IGNORE_K1
9+
// IMPLICIT_PACKAGE_PREFIX: "foo"
10+
// HIGHLIGHT_WARNINGS
11+
// ALLOW_ERRORS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fun foo() {
2+
// TODO
3+
// TODO
4+
// TODO
5+
// TODO
6+
}
7+
// TOOL: org.jetbrains.kotlin.idea.k2.codeinsight.inspections.PackageDirectoryMismatchInspection
8+
// IGNORE_K1
9+
// IMPLICIT_PACKAGE_PREFIX: "foo"
10+
// HIGHLIGHT_WARNINGS
11+
// ALLOW_ERRORS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!FILE_LEVEL_HIGHLIGHTING!>fun foo() {
2+
// <!HIGHLIGHTING("descr='TODO'")!>TODO<!>
3+
// <!HIGHLIGHTING("descr='TODO'")!>TODO<!>
4+
// <!HIGHLIGHTING("descr='TODO'")!>TODO<!>
5+
// <!HIGHLIGHTING("descr='TODO'")!>TODO<!>
6+
}
7+
// TOOL: org.jetbrains.kotlin.idea.k2.codeinsight.inspections.PackageDirectoryMismatchInspection
8+
// IGNORE_K1
9+
// IMPLICIT_PACKAGE_PREFIX: "foo"
10+
// HIGHLIGHT_WARNINGS
11+
// ALLOW_ERRORS<!>

0 commit comments

Comments
 (0)