Treat nested class of header class as header

Note that the quick fix to implement header class works incorrectly when
that class has nested classes at the moment; this should be fixed
separately

 #KT-15494 Fixed
 #KT-18573 Fixed
This commit is contained in:
Alexander Udalov
2017-07-21 18:22:32 +03:00
parent 56b507d141
commit d1cff41ce0
35 changed files with 348 additions and 119 deletions
@@ -29,11 +29,12 @@ import org.jetbrains.kotlin.idea.caches.resolve.findModuleDescriptor
import org.jetbrains.kotlin.idea.core.toDescriptor
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtPsiUtil
import org.jetbrains.kotlin.resolve.BindingTraceContext
import org.jetbrains.kotlin.resolve.TargetPlatform
import org.jetbrains.kotlin.resolve.checkers.HeaderImplDeclarationChecker
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
import org.jetbrains.kotlin.resolve.diagnostics.SimpleDiagnostics
val ModuleDescriptor.sourceKind: SourceKind
@@ -55,7 +56,7 @@ val ModuleDescriptor.allImplementingCompatibleModules
class PlatformHeaderAnnotator : Annotator {
override fun annotate(element: PsiElement, holder: AnnotationHolder) {
val declaration = element as? KtDeclaration ?: return
if (!declaration.hasModifier(KtTokens.HEADER_KEYWORD)) return
if (!isHeaderDeclaration(declaration)) return
if (TargetPlatformDetector.getPlatform(declaration.containingKtFile) !is TargetPlatform.Default) return
@@ -78,4 +79,9 @@ class PlatformHeaderAnnotator : Annotator {
KotlinPsiChecker().annotateElement(declaration, holder, SimpleDiagnostics(filteredList))
}
private fun isHeaderDeclaration(declaration: KtDeclaration): Boolean {
return declaration.hasModifier(KtTokens.HEADER_KEYWORD) ||
declaration is KtClassOrObject && KtPsiUtil.getOutermostClassOrObject(declaration)?.hasModifier(KtTokens.HEADER_KEYWORD) == true
}
}
@@ -0,0 +1,15 @@
package a
header class A {
class Nested
}
header class B {
class Nested {
fun foo(s: String)
}
}
header class C {
<error>header</error> inner class Inner
}
@@ -0,0 +1,11 @@
package a
impl class <error>A</error>
impl class B {
impl class <error>Nested</error>
}
impl class C {
impl inner class Inner
}
+1 -9
View File
@@ -6,12 +6,4 @@ header enum class <caret>MyEnum {
LAST;
val num: Int
companion object {
fun byNum(num: Int): MyEnum = when (num) {
1 -> FIRST
2 -> SECOND
else -> LAST
}
}
}
}
@@ -6,12 +6,4 @@ header enum class MyEnum {
LAST;
val num: Int
companion object {
fun byNum(num: Int): MyEnum = when (num) {
1 -> FIRST
2 -> SECOND
else -> LAST
}
}
}
}
+1 -8
View File
@@ -4,14 +4,7 @@ impl enum class MyEnum {
SECOND,
LAST;
companion object {
fun byNum(num: Int): MyEnum = when (num) {
1 -> FIRST
2 -> SECOND
else -> LAST
}
}
impl val num: Int
get() = TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
+3 -3
View File
@@ -4,10 +4,10 @@ header class <caret>WithNested {
fun foo(): Int
class Nested {
fun bar() = "Nested"
fun bar()
}
inner class Inner {
fun baz() = "Inner"
fun baz()
}
}
}
@@ -4,10 +4,10 @@ header class WithNested {
fun foo(): Int
class Nested {
fun bar() = "Nested"
fun bar()
}
inner class Inner {
fun baz() = "Inner"
fun baz()
}
}
}
@@ -2,11 +2,11 @@
impl class WithNested {
class Nested {
fun bar() = "Nested"
fun bar()
}
inner class Inner {
fun baz() = "Inner"
fun baz()
}
impl fun foo(): Int {
+2 -2
View File
@@ -1,7 +1,7 @@
// "Create header class implementation for platform JS" "true"
header sealed class <caret>Sealed {
object Obj : Sealed()
object Obj : Sealed
class Klass(val x: Int) : Sealed()
class Klass(x: Int) : Sealed
}
@@ -1,7 +1,7 @@
// "Create header class implementation for platform JS" "true"
header sealed class Sealed {
object Obj : Sealed()
object Obj : Sealed
class Klass(val x: Int) : Sealed()
class Klass(x: Int) : Sealed
}
@@ -1,6 +1,6 @@
// Sealed: to be implemented
impl sealed class Sealed {
object Obj : Sealed()
object Obj : Sealed
class Klass(val x: Int) : Sealed()
class Klass(x: Int) : Sealed
}
@@ -284,5 +284,9 @@ open class MultiModuleHighlightingTest : AbstractMultiModuleHighlightingTest() {
}
})
}
fun testNestedClassWithoutImpl() {
doMultiPlatformTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6])
}
}
}