From b4b24262a0463defca1905924fc8ee48cf1895a0 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Tue, 20 May 2014 17:50:35 +0400 Subject: [PATCH] Build stubs for insides of local objects and classes --- .../stubs/elements/JetClassElementType.java | 5 -- .../elements/JetFunctionElementType.java | 11 +---- .../stubs/elements/JetObjectElementType.java | 5 -- .../elements/JetParameterElementType.java | 9 ---- .../elements/JetPropertyElementType.java | 11 +---- .../stubs/elements/JetStubElementType.java | 47 +++++++++++++++---- idea/testData/stubs/AnonymousObject.expected | 11 +++++ idea/testData/stubs/LocalClass.expected | 10 ++++ .../stubs/LocalClassInLocalFunction.expected | 10 ++++ idea/testData/stubs/LocalNamedObject.expected | 10 ++++ .../stubs/MembersInLocalClass.expected | 12 +++++ idea/testData/stubs/MembersInLocalClass.kt | 8 ++++ .../stubs/MembersInLocalObject.expected | 12 +++++ idea/testData/stubs/MembersInLocalObject.kt | 10 ++++ .../stubs/ObjectInInitializer.expected | 11 +++++ idea/testData/stubs/ObjectInInitializer.kt | 4 ++ .../stubs/ObjectInPropertyDelegate.expected | 11 +++++ .../stubs/ObjectInPropertyDelegate.kt | 4 ++ .../plugin/stubs/AbstractStubBuilderTest.java | 3 +- .../stubs/StubBuilderTestGenerated.java | 20 ++++++++ 20 files changed, 175 insertions(+), 49 deletions(-) create mode 100644 idea/testData/stubs/MembersInLocalClass.expected create mode 100644 idea/testData/stubs/MembersInLocalClass.kt create mode 100644 idea/testData/stubs/MembersInLocalObject.expected create mode 100644 idea/testData/stubs/MembersInLocalObject.kt create mode 100644 idea/testData/stubs/ObjectInInitializer.expected create mode 100644 idea/testData/stubs/ObjectInInitializer.kt create mode 100644 idea/testData/stubs/ObjectInPropertyDelegate.expected create mode 100644 idea/testData/stubs/ObjectInPropertyDelegate.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassElementType.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassElementType.java index 0ed3897f41b..e051e7ae94b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassElementType.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassElementType.java @@ -53,11 +53,6 @@ public class JetClassElementType extends JetStubElementType> extends IStubElementType { + @SuppressWarnings("unchecked") + private static final Class[] ALWAYS_CREATE_STUB_FOR = new Class[] { JetClass.class, JetObjectDeclaration.class }; + @NotNull private final Constructor byNodeConstructor; @NotNull @@ -87,39 +93,64 @@ public abstract class JetStubElementType[] stopAt = ArrayUtil.append(ALWAYS_CREATE_STUB_FOR, JetBlockExpression.class); @SuppressWarnings("unchecked") JetWithExpressionInitializer withInitializer = - PsiTreeUtil.getParentOfType(psi, JetWithExpressionInitializer.class, true, JetBlockExpression.class); + PsiTreeUtil.getParentOfType(declaration, JetWithExpressionInitializer.class, true, stopAt); if (withInitializer != null) { JetExpression initializer = withInitializer.getInitializer(); - if (PsiTreeUtil.isAncestor(initializer, psi, true)) { + if (PsiTreeUtil.isAncestor(initializer, declaration, true)) { return false; } } // Don't create stubs if declaration is inside property delegate - @SuppressWarnings("unchecked") JetPropertyDelegate delegate = - PsiTreeUtil.getParentOfType(psi, JetPropertyDelegate.class, true, JetBlockExpression.class); + @SuppressWarnings("unchecked") JetPropertyDelegate delegate = PsiTreeUtil.getParentOfType(declaration, JetPropertyDelegate.class, true, stopAt); if (delegate != null) { JetExpression delegateExpression = delegate.getExpression(); - if (PsiTreeUtil.isAncestor(delegateExpression, psi, true)) { + if (PsiTreeUtil.isAncestor(delegateExpression, declaration, true)) { return false; } } - return super.shouldCreateStub(node); + return true; } @Override diff --git a/idea/testData/stubs/AnonymousObject.expected b/idea/testData/stubs/AnonymousObject.expected index 185c8798bc8..483c62c8972 100644 --- a/idea/testData/stubs/AnonymousObject.expected +++ b/idea/testData/stubs/AnonymousObject.expected @@ -4,3 +4,14 @@ PsiJetFileStubImpl[package=] CLASS:[fqName=T, isEnumEntry=false, isLocal=false, isTopLevel=true, isTrait=true, name=T, superNames=[]] PROPERTY:[fqName=obj, hasDelegate=false, hasDelegateExpression=false, hasInitializer=true, hasReceiverTypeRef=false, hasReturnTypeRef=false, isTopLevel=true, isVar=false, name=obj] OBJECT_DECLARATION:[fqName=null, isClassObject=false, isLocal=true, isObjectLiteral=true, isTopLevel=false, name=null, superNames=[A, T]] + DELEGATION_SPECIFIER_LIST: + DELEGATOR_SUPER_CALL: + CONSTRUCTOR_CALLEE: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=A] + DELEGATOR_SUPER_CLASS: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=T] + CLASS_BODY: diff --git a/idea/testData/stubs/LocalClass.expected b/idea/testData/stubs/LocalClass.expected index 733034f1e09..93914874ab9 100644 --- a/idea/testData/stubs/LocalClass.expected +++ b/idea/testData/stubs/LocalClass.expected @@ -5,3 +5,13 @@ PsiJetFileStubImpl[package=] FUN:[fqName=foo, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=true, name=foo] VALUE_PARAMETER_LIST: CLASS:[fqName=null, isEnumEntry=false, isLocal=true, isTopLevel=false, isTrait=false, name=Test, superNames=[A, T]] + DELEGATION_SPECIFIER_LIST: + DELEGATOR_SUPER_CALL: + CONSTRUCTOR_CALLEE: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=A] + DELEGATOR_SUPER_CLASS: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=T] diff --git a/idea/testData/stubs/LocalClassInLocalFunction.expected b/idea/testData/stubs/LocalClassInLocalFunction.expected index 733034f1e09..93914874ab9 100644 --- a/idea/testData/stubs/LocalClassInLocalFunction.expected +++ b/idea/testData/stubs/LocalClassInLocalFunction.expected @@ -5,3 +5,13 @@ PsiJetFileStubImpl[package=] FUN:[fqName=foo, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=true, name=foo] VALUE_PARAMETER_LIST: CLASS:[fqName=null, isEnumEntry=false, isLocal=true, isTopLevel=false, isTrait=false, name=Test, superNames=[A, T]] + DELEGATION_SPECIFIER_LIST: + DELEGATOR_SUPER_CALL: + CONSTRUCTOR_CALLEE: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=A] + DELEGATOR_SUPER_CLASS: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=T] diff --git a/idea/testData/stubs/LocalNamedObject.expected b/idea/testData/stubs/LocalNamedObject.expected index f46fb1494be..67f86b95475 100644 --- a/idea/testData/stubs/LocalNamedObject.expected +++ b/idea/testData/stubs/LocalNamedObject.expected @@ -5,3 +5,13 @@ PsiJetFileStubImpl[package=] FUN:[fqName=foo, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=true, name=foo] VALUE_PARAMETER_LIST: OBJECT_DECLARATION:[fqName=null, isClassObject=false, isLocal=true, isObjectLiteral=false, isTopLevel=false, name=O, superNames=[A, T]] + DELEGATION_SPECIFIER_LIST: + DELEGATOR_SUPER_CALL: + CONSTRUCTOR_CALLEE: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=A] + DELEGATOR_SUPER_CLASS: + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=T] diff --git a/idea/testData/stubs/MembersInLocalClass.expected b/idea/testData/stubs/MembersInLocalClass.expected new file mode 100644 index 00000000000..b070731b917 --- /dev/null +++ b/idea/testData/stubs/MembersInLocalClass.expected @@ -0,0 +1,12 @@ +PsiJetFileStubImpl[package=] + PACKAGE_DIRECTIVE: + FUN:[fqName=f, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=true, name=f] + MODIFIER_LIST:[public] + CLASS:[fqName=null, isEnumEntry=false, isLocal=true, isTopLevel=false, isTrait=false, name=C, superNames=[]] + CLASS_BODY: + FUN:[fqName=null, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=f] + VALUE_PARAMETER_LIST: + PROPERTY:[fqName=null, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReceiverTypeRef=false, hasReturnTypeRef=true, isTopLevel=false, isVar=false, name=c] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=Int] diff --git a/idea/testData/stubs/MembersInLocalClass.kt b/idea/testData/stubs/MembersInLocalClass.kt new file mode 100644 index 00000000000..22e9fa4c354 --- /dev/null +++ b/idea/testData/stubs/MembersInLocalClass.kt @@ -0,0 +1,8 @@ +public fun f { + class C { + fun f() { + } + + val c: Int + } +} \ No newline at end of file diff --git a/idea/testData/stubs/MembersInLocalObject.expected b/idea/testData/stubs/MembersInLocalObject.expected new file mode 100644 index 00000000000..1d0b267e4ba --- /dev/null +++ b/idea/testData/stubs/MembersInLocalObject.expected @@ -0,0 +1,12 @@ +PsiJetFileStubImpl[package=] + PACKAGE_DIRECTIVE: + FUN:[fqName=f, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=true, name=f] + VALUE_PARAMETER_LIST: + OBJECT_DECLARATION:[fqName=null, isClassObject=false, isLocal=true, isObjectLiteral=false, isTopLevel=false, name=foo, superNames=[]] + CLASS_BODY: + FUN:[fqName=null, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=foo] + VALUE_PARAMETER_LIST: + PROPERTY:[fqName=null, hasDelegate=false, hasDelegateExpression=false, hasInitializer=true, hasReceiverTypeRef=false, hasReturnTypeRef=true, isTopLevel=false, isVar=false, name=foo] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=Int] diff --git a/idea/testData/stubs/MembersInLocalObject.kt b/idea/testData/stubs/MembersInLocalObject.kt new file mode 100644 index 00000000000..49d8a3ba11e --- /dev/null +++ b/idea/testData/stubs/MembersInLocalObject.kt @@ -0,0 +1,10 @@ +fun f() { + object foo { + fun foo() { + for (a in listOf(1, 2, 3)) { + } + } + + val foo: Int = 3 + } +} \ No newline at end of file diff --git a/idea/testData/stubs/ObjectInInitializer.expected b/idea/testData/stubs/ObjectInInitializer.expected new file mode 100644 index 00000000000..9a2a985c17c --- /dev/null +++ b/idea/testData/stubs/ObjectInInitializer.expected @@ -0,0 +1,11 @@ +PsiJetFileStubImpl[package=] + PACKAGE_DIRECTIVE: + PROPERTY:[fqName=p, hasDelegate=false, hasDelegateExpression=false, hasInitializer=true, hasReceiverTypeRef=false, hasReturnTypeRef=false, isTopLevel=true, isVar=false, name=p] + OBJECT_DECLARATION:[fqName=null, isClassObject=false, isLocal=true, isObjectLiteral=true, isTopLevel=false, name=null, superNames=[]] + CLASS_BODY: + FUN:[fqName=null, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=f] + VALUE_PARAMETER_LIST: + PROPERTY:[fqName=null, hasDelegate=false, hasDelegateExpression=false, hasInitializer=true, hasReceiverTypeRef=false, hasReturnTypeRef=true, isTopLevel=false, isVar=false, name=p] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=Int] diff --git a/idea/testData/stubs/ObjectInInitializer.kt b/idea/testData/stubs/ObjectInInitializer.kt new file mode 100644 index 00000000000..368c4d45d23 --- /dev/null +++ b/idea/testData/stubs/ObjectInInitializer.kt @@ -0,0 +1,4 @@ +val p = object { + fun f() {} + val p: Int = 3 +} \ No newline at end of file diff --git a/idea/testData/stubs/ObjectInPropertyDelegate.expected b/idea/testData/stubs/ObjectInPropertyDelegate.expected new file mode 100644 index 00000000000..e5be065d64b --- /dev/null +++ b/idea/testData/stubs/ObjectInPropertyDelegate.expected @@ -0,0 +1,11 @@ +PsiJetFileStubImpl[package=] + PACKAGE_DIRECTIVE: + PROPERTY:[fqName=p, hasDelegate=true, hasDelegateExpression=true, hasInitializer=false, hasReceiverTypeRef=false, hasReturnTypeRef=false, isTopLevel=true, isVar=false, name=p] + OBJECT_DECLARATION:[fqName=null, isClassObject=false, isLocal=true, isObjectLiteral=true, isTopLevel=false, name=null, superNames=[]] + CLASS_BODY: + FUN:[fqName=null, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=f] + VALUE_PARAMETER_LIST: + PROPERTY:[fqName=null, hasDelegate=false, hasDelegateExpression=false, hasInitializer=true, hasReceiverTypeRef=false, hasReturnTypeRef=true, isTopLevel=false, isVar=false, name=p] + TYPE_REFERENCE: + USER_TYPE:[isAbsoluteInRootPackage=false] + REFERENCE_EXPRESSION:[referencedName=Int] diff --git a/idea/testData/stubs/ObjectInPropertyDelegate.kt b/idea/testData/stubs/ObjectInPropertyDelegate.kt new file mode 100644 index 00000000000..c2df805eb36 --- /dev/null +++ b/idea/testData/stubs/ObjectInPropertyDelegate.kt @@ -0,0 +1,4 @@ +val p by object { + fun f() {} + val p: Int = 1 +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/stubs/AbstractStubBuilderTest.java b/idea/tests/org/jetbrains/jet/plugin/stubs/AbstractStubBuilderTest.java index c647fbeb4d6..cacac91cb19 100644 --- a/idea/tests/org/jetbrains/jet/plugin/stubs/AbstractStubBuilderTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/stubs/AbstractStubBuilderTest.java @@ -37,8 +37,7 @@ public abstract class AbstractStubBuilderTest extends LightCodeInsightFixtureTes JetFileStubBuilder jetStubBuilder = new JetFileStubBuilder(); StubElement lighterTree = jetStubBuilder.buildStubTree(file); String stubTree = DebugUtil.stubTreeToString(lighterTree) - .replace(NO_NAME_FOR_LAZY_RESOLVE.asString(), "") - .replace(":" + PsiJetPlaceHolderStubImpl.class.getSimpleName(), ""); + .replace(NO_NAME_FOR_LAZY_RESOLVE.asString(), ""); String expectedFile = sourcePath.replace(".kt", ".expected"); JetTestUtils.assertEqualsToFile(new File(expectedFile), stubTree); } diff --git a/idea/tests/org/jetbrains/jet/plugin/stubs/StubBuilderTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/stubs/StubBuilderTestGenerated.java index 2b891eb4df2..b3bffbc31c6 100644 --- a/idea/tests/org/jetbrains/jet/plugin/stubs/StubBuilderTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/stubs/StubBuilderTestGenerated.java @@ -116,6 +116,16 @@ public class StubBuilderTestGenerated extends AbstractStubBuilderTest { doTest("idea/testData/stubs/ManyAnnotationsOnFunction.kt"); } + @TestMetadata("MembersInLocalClass.kt") + public void testMembersInLocalClass() throws Exception { + doTest("idea/testData/stubs/MembersInLocalClass.kt"); + } + + @TestMetadata("MembersInLocalObject.kt") + public void testMembersInLocalObject() throws Exception { + doTest("idea/testData/stubs/MembersInLocalObject.kt"); + } + @TestMetadata("NamedObject.kt") public void testNamedObject() throws Exception { doTest("idea/testData/stubs/NamedObject.kt"); @@ -136,6 +146,16 @@ public class StubBuilderTestGenerated extends AbstractStubBuilderTest { doTest("idea/testData/stubs/NotStorePropertyFromInitializer.kt"); } + @TestMetadata("ObjectInInitializer.kt") + public void testObjectInInitializer() throws Exception { + doTest("idea/testData/stubs/ObjectInInitializer.kt"); + } + + @TestMetadata("ObjectInPropertyDelegate.kt") + public void testObjectInPropertyDelegate() throws Exception { + doTest("idea/testData/stubs/ObjectInPropertyDelegate.kt"); + } + @TestMetadata("PackageProperty.kt") public void testPackageProperty() throws Exception { doTest("idea/testData/stubs/PackageProperty.kt");