Skip to content

Commit 853854a

Browse files
committed
Error on local classes inside mixins. Closes #2369
1 parent 904a7b7 commit 853854a

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/main/kotlin/platform/mixin/inspection/MixinInnerClassInspection.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class MixinInnerClassInspection : MixinInspection() {
4141
private class Visitor(private val holder: ProblemsHolder) : JavaElementVisitor() {
4242

4343
override fun visitClass(psiClass: PsiClass) {
44-
if (PsiUtil.isLocalClass(psiClass)) {
44+
if (psiClass.containingClass == null && PsiUtil.isLocalClass(psiClass)) {
4545
holder.registerProblem(
4646
psiClass.nameIdentifier ?: psiClass,
4747
"Local classes are not allowed inside mixins"
@@ -73,7 +73,10 @@ class MixinInnerClassInspection : MixinInspection() {
7373
)
7474
}
7575
} else {
76-
holder.registerProblem(psiClass, "Inner classes are only allowed if they are also @Mixin classes")
76+
holder.registerProblem(
77+
psiClass.nameIdentifier ?: psiClass,
78+
"Inner classes are only allowed if they are also @Mixin classes"
79+
)
7780
}
7881
}
7982

src/test/kotlin/platform/mixin/InnerClassTest.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,19 @@ class InnerClassTest : BaseMixinTest() {
5353
private static void stuffInsideAnonymousClassBad() {
5454
new Object() {
5555
public void foo() {
56-
new <error descr="Double nested anonymous classes are not allowed in a @Mixin class">Object() {
57-
}</error>;
56+
new <error descr="Double nested anonymous classes are not allowed in a @Mixin class">Object</error>() {
57+
};
5858
}
5959
60-
<error descr="Inner class not allowed inside anonymous classes inside mixins">class ClassInsideAnonymousClass {
61-
}</error>
60+
class <error descr="Inner class not allowed inside anonymous classes inside mixins">ClassInsideAnonymousClass</error> {
61+
}
6262
};
6363
}
64+
65+
private static void localClassBad() {
66+
class <error descr="Local classes are not allowed inside mixins">Local</error> {
67+
}
68+
}
6469
6570
@Mixin
6671
static class GoodInnerMixin {
@@ -72,9 +77,9 @@ class InnerClassTest : BaseMixinTest() {
7277
7378
}
7479
75-
<error descr="Inner classes are only allowed if they are also @Mixin classes">class VeryBadInnerClass {
80+
class <error descr="Inner classes are only allowed if they are also @Mixin classes">VeryBadInnerClass</error> {
7681
77-
}</error>
82+
}
7883
7984
}
8085
""",

0 commit comments

Comments
 (0)