Generate light classes for Kotlin inner classes

#KT-6237 Fixed
This commit is contained in:
Alexey Sedunov
2014-11-12 21:22:34 +03:00
parent da915aee7e
commit b09684024b
16 changed files with 192 additions and 2 deletions
@@ -37,6 +37,9 @@ import com.intellij.psi.util.CachedValuesManager;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.IncorrectOperationException;
import jet.runtime.typeinfo.JetValueParameter;
import kotlin.Function1;
import kotlin.KotlinPackage;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -542,8 +545,18 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC
@NotNull
@Override
public List<PsiClass> getOwnInnerClasses() {
// TODO: Should return inner class wrapper
return Arrays.asList(getDelegate().getInnerClasses());
return KotlinPackage.filterNotNull(
KotlinPackage.map(
getDelegate().getInnerClasses(),
new Function1<PsiClass, PsiClass>() {
@Override
public PsiClass invoke(PsiClass aClass) {
JetClassOrObject declaration = (JetClassOrObject) ClsWrapperStubPsiFactory.getOriginalDeclaration(aClass);
return declaration != null ? KotlinLightClassForExplicitDeclaration.create(myManager, declaration) : null;
}
}
)
);
}
private static boolean checkSuperTypeByFQName(@NotNull ClassDescriptor classDescriptor, @NotNull String qualifiedName, Boolean deep) {
@@ -0,0 +1,23 @@
// PSI_ELEMENT: org.jetbrains.jet.lang.psi.JetClass
// OPTIONS: usages, constructorUsages
package a
public open class Outer {
public open class Inner {
public open class <caret>A {
public var bar: String = "bar";
public open fun foo() {
}
class object {
public var bar: String = "bar";
public open fun foo() {
}
}
}
}
}
@@ -0,0 +1,42 @@
package b
import a.Outer.Inner
public class X(bar: String? = Inner.A.bar): Inner.A() {
var next: Inner.A? = Inner.A()
val myBar: String? = Inner.A.bar
{
Inner.A.bar = ""
Inner.A.foo()
}
fun foo(a: Inner.A) {
val aa: Inner.A = a
aa.bar = ""
}
fun getNext(): Inner.A? {
return next
}
public override fun foo() {
super<Inner.A>.foo()
}
class object: Inner.A() {
}
}
object O: Inner.A() {
}
fun X.bar(a: Inner.A = Inner.A()) {
}
fun Any.toA(): Inner.A? {
return if (this is Inner.A) this as Inner.A else null
}
@@ -0,0 +1,7 @@
package b;
import a.Outer.Inner;
public class X extends Inner.A {
Inner.A next = new Inner.A();
}
@@ -0,0 +1,21 @@
Class/object property type (6: 21) var next: Inner.A? = Inner.A()
Field declaration (6: 11) Inner.A next = new Inner.A();
Function return types (19: 26) fun getNext(): Inner.A? {
Function return types (40: 22) fun Any.toA(): Inner.A? {
Local variable declaration (15: 23) val aa: Inner.A = a
Nested class/object (10: 15) Inner.A.bar = ""
Nested class/object (11: 15) Inner.A.foo()
Nested class/object (5: 37) public class X(bar: String? = Inner.A.bar): Inner.A() {
Nested class/object (7: 32) val myBar: String? = Inner.A.bar
New instance creation (36: 30) fun X.bar(a: Inner.A = Inner.A()) {
New instance creation (6: 30) Inner.A next = new Inner.A();
New instance creation (6: 32) var next: Inner.A? = Inner.A()
Parameter type (14: 22) fun foo(a: Inner.A) {
Parameter type (36: 20) fun X.bar(a: Inner.A = Inner.A()) {
Super type qualifier (24: 21) super<Inner.A>.foo()
Supertype (27: 25) class object: Inner.A() {
Supertype (32: 17) object O: Inner.A() {
Supertype (5: 51) public class X(bar: String? = Inner.A.bar): Inner.A() {
Target type of 'is' operation (41: 30) return if (this is Inner.A) this as Inner.A else null
Usage in cast target type (41: 47) return if (this is Inner.A) this as Inner.A else null
Usage in extends/implements clause (5: 30) public class X extends Inner.A {
@@ -0,0 +1,11 @@
package b;
import a.Outer;
public class X extends Outer {
class Y extends A {
}
A next = new A();
}
@@ -1,8 +1,10 @@
Class/object property type (7: 25) var next: Outer.A? = (this@KOuter : Outer).A()
Field declaration (10: 5) A next = new A();
Function return types (19: 30) fun getNext(): Outer.A? {
Function return types (33: 22) fun Any.toA(): Outer.A? {
Function return types (37: 27) fun Any.asServer(): Outer.A? {
Local variable declaration (15: 27) val aa: Outer.A = a
New instance creation (10: 18) A next = new A();
New instance creation (11: 35) (this@KOuter : Outer).A().bar = ""
New instance creation (29: 39) fun KOuter.X.bar(a: Outer.A = Outer().A()) {
New instance creation (6: 63) public inner class X(bar: String? = (this@KOuter : Outer).A().bar): Outer.A() {
@@ -16,3 +18,4 @@ Target type of 'is' operation (34: 30) return if (this is Outer.A) this as Outer
Target type of 'is' operation (38: 30) return if (this is Outer.A) this as Outer.A else null
Usage in cast target type (34: 47) return if (this is Outer.A) this as Outer.A else null
Usage in cast target type (38: 47) return if (this is Outer.A) this as Outer.A else null
Usage in extends/implements clause (6: 21) class Y extends A {
@@ -0,0 +1,7 @@
package b;
import a.Outer;
public class X extends Outer.A {
Outer.A next = new Outer.A();
}
@@ -1,4 +1,5 @@
Class/object property type (6: 21) var next: Outer.A? = Outer.A()
Field declaration (6: 11) Outer.A next = new Outer.A();
Function return types (19: 26) fun getNext(): Outer.A? {
Function return types (40: 22) fun Any.toA(): Outer.A? {
Local variable declaration (15: 23) val aa: Outer.A = a
@@ -7,6 +8,7 @@ Nested class/object (11: 15) Outer.A.foo()
Nested class/object (5: 37) public class X(bar: String? = Outer.A.bar): Outer.A() {
Nested class/object (7: 32) val myBar: String? = Outer.A.bar
New instance creation (36: 30) fun X.bar(a: Outer.A = Outer.A()) {
New instance creation (6: 30) Outer.A next = new Outer.A();
New instance creation (6: 32) var next: Outer.A? = Outer.A()
Parameter type (14: 22) fun foo(a: Outer.A) {
Parameter type (36: 20) fun X.bar(a: Outer.A = Outer.A()) {
@@ -16,3 +18,4 @@ Supertype (32: 17) object O: Outer.A() {
Supertype (5: 51) public class X(bar: String? = Outer.A.bar): Outer.A() {
Target type of 'is' operation (41: 30) return if (this is Outer.A) this as Outer.A else null
Usage in cast target type (41: 47) return if (this is Outer.A) this as Outer.A else null
Usage in extends/implements clause (5: 30) public class X extends Outer.A {
@@ -0,0 +1,11 @@
// PSI_ELEMENT: org.jetbrains.jet.lang.psi.JetNamedFunction
// OPTIONS: usages
package a
public open class Outer() {
open class Inner {
fun <caret>foo() {
}
}
}
@@ -0,0 +1,9 @@
package b;
import a.Outer;
class X extends Outer.Inner {
{
new Outer.Inner().foo();
}
}
@@ -0,0 +1 @@
Unclassified usage (7: 27) new Outer.Inner().foo();
@@ -0,0 +1,9 @@
// PSI_ELEMENT: org.jetbrains.jet.lang.psi.JetProperty
// OPTIONS: usages
package a
public open class Outer() {
open class Inner {
var <caret>foo: Int = 1
}
}
@@ -0,0 +1,10 @@
package b;
import a.Outer;
class X extends Outer.Inner {
{
int n = new Outer.Inner().getFoo();
new Outer.Inner().setFoo(2);
}
}
@@ -0,0 +1,2 @@
Unclassified usage (7: 35) int n = new Outer.Inner().getFoo();
Unclassified usage (8: 27) new Outer.Inner().setFoo(2);
@@ -321,6 +321,12 @@ public class JetFindUsagesTestGenerated extends AbstractJetFindUsagesTest {
doTest(fileName);
}
@TestMetadata("kotlinDeeplyNestedClassAllUsages.0.kt")
public void testKotlinDeeplyNestedClassAllUsages() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findClassUsages/kotlinDeeplyNestedClassAllUsages.0.kt");
doTest(fileName);
}
@TestMetadata("kotlinInnerClassAllUsages.0.kt")
public void testKotlinInnerClassAllUsages() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findClassUsages/kotlinInnerClassAllUsages.0.kt");
@@ -474,6 +480,12 @@ public class JetFindUsagesTestGenerated extends AbstractJetFindUsagesTest {
doTest(fileName);
}
@TestMetadata("kotlinNestedClassMethodUsages.0.kt")
public void testKotlinNestedClassMethodUsages() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findFunctionUsages/kotlinNestedClassMethodUsages.0.kt");
doTest(fileName);
}
@TestMetadata("kotlinOverloadAndExtensionUsages.0.kt")
public void testKotlinOverloadAndExtensionUsages() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findFunctionUsages/kotlinOverloadAndExtensionUsages.0.kt");
@@ -678,6 +690,12 @@ public class JetFindUsagesTestGenerated extends AbstractJetFindUsagesTest {
doTest(fileName);
}
@TestMetadata("kotlinNestedClassPropertyUsages.0.kt")
public void testKotlinNestedClassPropertyUsages() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findPropertyUsages/kotlinNestedClassPropertyUsages.0.kt");
doTest(fileName);
}
@TestMetadata("kotlinPrivatePropertyUsages.0.kt")
public void testKotlinPrivatePropertyUsages() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findPropertyUsages/kotlinPrivatePropertyUsages.0.kt");