From b2f2d4391987b43f56ea7ce2bcc52f22b3f13c7b Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Wed, 7 Aug 2013 21:27:34 +0400 Subject: [PATCH] Stubs for JetClassBody --- .../src/org/jetbrains/jet/JetNodeTypes.java | 2 +- .../jetbrains/jet/lang/psi/JetClassBody.java | 9 ++- .../lang/psi/stubs/PsiJetClassBodyStub.java | 23 +++++++ .../elements/JetClassBodyElementType.java | 67 +++++++++++++++++++ .../stubs/elements/JetStubElementTypes.java | 1 + .../stubs/impl/PsiJetClassBodyStubImpl.java | 29 ++++++++ .../stubindex/StubIndexServiceImpl.java | 7 +- .../jet/plugin/stubs/JetStubsTest.java | 42 +++++++----- 8 files changed, 159 insertions(+), 21 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetClassBodyStub.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassBodyElementType.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetClassBodyStubImpl.java diff --git a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java index dfa53d07b08..3a814288344 100644 --- a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java +++ b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java @@ -50,7 +50,7 @@ public interface JetNodeTypes { IElementType VALUE_PARAMETER_LIST = JetStubElementTypes.VALUE_PARAMETER_LIST; IElementType VALUE_PARAMETER = JetStubElementTypes.VALUE_PARAMETER; - JetNodeType CLASS_BODY = new JetNodeType("CLASS_BODY", JetClassBody.class); + IElementType CLASS_BODY = JetStubElementTypes.CLASS_BODY; JetNodeType IMPORT_LIST = new JetNodeType("IMPORT_LIST", JetImportList.class); JetNodeType IMPORT_DIRECTIVE = new JetNodeType("IMPORT_DIRECTIVE", JetImportDirective.class); JetNodeType MODIFIER_LIST = new JetNodeType("MODIFIER_LIST", JetModifierList.class); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassBody.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassBody.java index c55a016fc4d..8070a7ac62f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassBody.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassBody.java @@ -18,20 +18,27 @@ package org.jetbrains.jet.lang.psi; import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; +import com.intellij.psi.stubs.IStubElementType; +import com.intellij.psi.stubs.StubElement; import com.intellij.psi.tree.TokenSet; import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.JetNodeTypes; +import org.jetbrains.jet.lang.psi.stubs.PsiJetClassBodyStub; import org.jetbrains.jet.lexer.JetTokens; import java.util.List; -public class JetClassBody extends JetElementImpl implements JetDeclarationContainer { +public class JetClassBody extends JetElementImplStub implements JetDeclarationContainer { public JetClassBody(@NotNull ASTNode node) { super(node); } + public JetClassBody(@NotNull PsiJetClassBodyStub stub, @NotNull IStubElementType nodeType) { + super(stub, nodeType); + } + @Override @NotNull public List getDeclarations() { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetClassBodyStub.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetClassBodyStub.java new file mode 100644 index 00000000000..43a81d4d0d5 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetClassBodyStub.java @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.lang.psi.stubs; + +import com.intellij.psi.stubs.StubElement; +import org.jetbrains.jet.lang.psi.JetClassBody; + +public interface PsiJetClassBodyStub extends StubElement { +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassBodyElementType.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassBodyElementType.java new file mode 100644 index 00000000000..69be5856085 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassBodyElementType.java @@ -0,0 +1,67 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.lang.psi.stubs.elements; + +import com.intellij.lang.ASTNode; +import com.intellij.psi.stubs.IndexSink; +import com.intellij.psi.stubs.StubElement; +import com.intellij.psi.stubs.StubInputStream; +import com.intellij.psi.stubs.StubOutputStream; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.psi.JetClassBody; +import org.jetbrains.jet.lang.psi.stubs.PsiJetClassBodyStub; +import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetClassBodyStubImpl; + +import java.io.IOException; + +public class JetClassBodyElementType extends JetStubElementType { + public JetClassBodyElementType(@NotNull @NonNls String debugName) { + super(debugName); + } + + @Override + public JetClassBody createPsiFromAst(@NotNull ASTNode node) { + return new JetClassBody(node); + } + + @Override + public JetClassBody createPsi(@NotNull PsiJetClassBodyStub stub) { + return new JetClassBody(stub, JetStubElementTypes.CLASS_BODY); + } + + @Override + public PsiJetClassBodyStub createStub(@NotNull JetClassBody psi, StubElement parentStub) { + return new PsiJetClassBodyStubImpl(parentStub, JetStubElementTypes.CLASS_BODY); + } + + @Override + public void serialize(@NotNull PsiJetClassBodyStub stub, @NotNull StubOutputStream dataStream) throws IOException { + //do nothing; + } + + @NotNull + @Override + public PsiJetClassBodyStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { + return new PsiJetClassBodyStubImpl(parentStub, JetStubElementTypes.CLASS_BODY); + } + + @Override + public void indexStub(@NotNull PsiJetClassBodyStub stub, @NotNull IndexSink sink) { + //do nothing + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetStubElementTypes.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetStubElementTypes.java index b93f35771ab..a0661701357 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetStubElementTypes.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetStubElementTypes.java @@ -31,4 +31,5 @@ public interface JetStubElementTypes { JetTypeParameterElementType TYPE_PARAMETER = new JetTypeParameterElementType("TYPE_PARAMETER"); JetTypeParameterListElementType TYPE_PARAMETER_LIST = new JetTypeParameterListElementType("TYPE_PARAMETER_LIST"); JetAnnotationElementType ANNOTATION_ENTRY = new JetAnnotationElementType("ANNOTATION_ENTRY"); + JetClassBodyElementType CLASS_BODY = new JetClassBodyElementType("CLASS_BODY"); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetClassBodyStubImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetClassBodyStubImpl.java new file mode 100644 index 00000000000..2ba662c7b1c --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetClassBodyStubImpl.java @@ -0,0 +1,29 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.lang.psi.stubs.impl; + +import com.intellij.psi.stubs.IStubElementType; +import com.intellij.psi.stubs.StubBase; +import com.intellij.psi.stubs.StubElement; +import org.jetbrains.jet.lang.psi.JetClassBody; +import org.jetbrains.jet.lang.psi.stubs.PsiJetClassBodyStub; + +public class PsiJetClassBodyStubImpl extends StubBase implements PsiJetClassBodyStub { + public PsiJetClassBodyStubImpl(StubElement parent, IStubElementType elementType) { + super(parent, elementType); + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java b/idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java index a8f121dfadd..b988cd0feba 100644 --- a/idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java +++ b/idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java @@ -63,12 +63,13 @@ public class StubIndexServiceImpl implements StubIndexService { FqName fqName = stub.getFqName(); if (stub.isClassObject()) { - StubElement parentStub = stub.getParentStub(); - assert parentStub instanceof PsiJetStubWithFqName : "Something but a class/object is a parent to class object stub: " + parentStub; + StubElement parentClassStub = stub.getParentStub().getParentStub(); + assert parentClassStub instanceof PsiJetStubWithFqName + : "Something but a class/object is a parent to class object stub: " + parentClassStub; name = JvmAbi.CLASS_OBJECT_CLASS_NAME; - FqName parentFqName = ((PsiJetStubWithFqName) parentStub).getFqName(); + FqName parentFqName = ((PsiJetStubWithFqName) parentClassStub).getFqName(); if (parentFqName != null) { fqName = parentFqName.child(Name.identifier(name)); } diff --git a/idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java b/idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java index 6ca8238bebc..86ad031b279 100644 --- a/idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java @@ -69,24 +69,28 @@ public class JetStubsTest extends LightCodeInsightFixtureTestCase { "PsiJetFileStubImpl[package=]\n" + " CLASS:PsiJetClassStubImpl[name=C fqn=C superNames=[]]\n" + " TYPE_PARAMETER_LIST:PsiJetTypeParameterListStubImpl\n" + - " TYPE_PARAMETER:PsiJetTypeParameterStubImpl[name=T extendText=null]\n"); + " TYPE_PARAMETER:PsiJetTypeParameterStubImpl[name=T extendText=null]\n" + + " CLASS_BODY:PsiJetClassBodyStubImpl\n"); } public void testClassObject() { doBuildTest("class C { class object { fun foo() {} }}", "PsiJetFileStubImpl[package=]\n" + " CLASS:PsiJetClassStubImpl[name=C fqn=C superNames=[]]\n" + - " OBJECT_DECLARATION:PsiJetObjectStubImpl[class-object name=null fqName=null superNames=[]]\n" + - " FUN:PsiJetFunctionStubImpl[name=foo]\n" + - " VALUE_PARAMETER_LIST:PsiJetParameterListStubImpl\n"); + " CLASS_BODY:PsiJetClassBodyStubImpl\n" + + " OBJECT_DECLARATION:PsiJetObjectStubImpl[class-object name=null fqName=null superNames=[]]\n" + + " CLASS_BODY:PsiJetClassBodyStubImpl\n" + + " FUN:PsiJetFunctionStubImpl[name=foo]\n" + + " VALUE_PARAMETER_LIST:PsiJetParameterListStubImpl\n"); } public void testFunctionInNotNamedObject() { doBuildTest("object { fun testing() = 12 }", "PsiJetFileStubImpl[package=]\n" + " OBJECT_DECLARATION:PsiJetObjectStubImpl[top name=null fqName=null superNames=[]]\n" + - " FUN:PsiJetFunctionStubImpl[name=testing]\n" + - " VALUE_PARAMETER_LIST:PsiJetParameterListStubImpl\n"); + " CLASS_BODY:PsiJetClassBodyStubImpl\n" + + " FUN:PsiJetFunctionStubImpl[name=testing]\n" + + " VALUE_PARAMETER_LIST:PsiJetParameterListStubImpl\n"); } public void testFunctionParameters() { @@ -111,7 +115,8 @@ public class JetStubsTest extends LightCodeInsightFixtureTestCase { "}", "PsiJetFileStubImpl[package=]\n" + " CLASS:PsiJetClassStubImpl[name=More fqn=More superNames=[]]\n" + - " PROPERTY:PsiJetPropertyStubImpl[val name=test typeText=Int bodyText=11]\n"); + " CLASS_BODY:PsiJetClassBodyStubImpl\n" + + " PROPERTY:PsiJetPropertyStubImpl[val name=test typeText=Int bodyText=11]\n"); } public void testNotStorePropertyFromInitializer() { @@ -140,18 +145,19 @@ public class JetStubsTest extends LightCodeInsightFixtureTestCase { "PsiJetFileStubImpl[package=]\n" + " CLASS:PsiJetClassStubImpl[name=Test fqn=Test superNames=[]]\n" + " VALUE_PARAMETER_LIST:PsiJetParameterListStubImpl\n" + - " PROPERTY:PsiJetPropertyStubImpl[val name=test typeText=null bodyText=12]\n" + - " FUN:PsiJetFunctionStubImpl[name=more]\n" + - " VALUE_PARAMETER_LIST:PsiJetParameterListStubImpl\n"); + " CLASS_BODY:PsiJetClassBodyStubImpl\n" + + " PROPERTY:PsiJetPropertyStubImpl[val name=test typeText=null bodyText=12]\n" + + " FUN:PsiJetFunctionStubImpl[name=more]\n" + + " VALUE_PARAMETER_LIST:PsiJetParameterListStubImpl\n"); } public void testSimpleEnumBuild() { doBuildTest("enum class Test { First\n Second\n }", "PsiJetFileStubImpl[package=]\n" + " CLASS:PsiJetClassStubImpl[enumClass name=Test fqn=Test superNames=[]]\n" + - " ENUM_ENTRY:PsiJetClassStubImpl[enumEntry name=First fqn=Test.First superNames=[]]\n" + - " ENUM_ENTRY:PsiJetClassStubImpl[enumEntry name=Second fqn=Test.Second superNames=[]]\n" - ); + " CLASS_BODY:PsiJetClassBodyStubImpl\n" + + " ENUM_ENTRY:PsiJetClassStubImpl[enumEntry name=First fqn=Test.First superNames=[]]\n" + + " ENUM_ENTRY:PsiJetClassStubImpl[enumEntry name=Second fqn=Test.Second superNames=[]]\n"); } public void testAnnotationClass() { @@ -164,7 +170,9 @@ public class JetStubsTest extends LightCodeInsightFixtureTestCase { doBuildTest("class A { inner class B { } }", "PsiJetFileStubImpl[package=]\n" + " CLASS:PsiJetClassStubImpl[name=A fqn=A superNames=[]]\n" + - " CLASS:PsiJetClassStubImpl[inner name=B fqn=A.B superNames=[]]\n"); + " CLASS_BODY:PsiJetClassBodyStubImpl\n" + + " CLASS:PsiJetClassStubImpl[inner name=B fqn=A.B superNames=[]]\n" + + " CLASS_BODY:PsiJetClassBodyStubImpl\n"); } public void testLocalClass() { @@ -192,7 +200,8 @@ public class JetStubsTest extends LightCodeInsightFixtureTestCase { "PsiJetFileStubImpl[package=]\n" + " CLASS:PsiJetClassStubImpl[name=A fqn=A superNames=[]]\n" + " CLASS:PsiJetClassStubImpl[trait name=T fqn=T superNames=[]]\n" + - " OBJECT_DECLARATION:PsiJetObjectStubImpl[top name=Test fqName=Test superNames=[AT]]\n"); + " OBJECT_DECLARATION:PsiJetObjectStubImpl[top name=Test fqName=Test superNames=[AT]]\n" + + " CLASS_BODY:PsiJetClassBodyStubImpl\n"); } public void testLocalNamedObject() { @@ -218,7 +227,8 @@ public class JetStubsTest extends LightCodeInsightFixtureTestCase { doBuildTest("Deprecated class Test {}", "PsiJetFileStubImpl[package=]\n" + " CLASS:PsiJetClassStubImpl[name=Test fqn=Test superNames=[]]\n" + - " ANNOTATION_ENTRY:PsiJetAnnotationStubImpl[shortName=Deprecated]\n"); + " ANNOTATION_ENTRY:PsiJetAnnotationStubImpl[shortName=Deprecated]\n" + + " CLASS_BODY:PsiJetClassBodyStubImpl\n"); } public void testAnnotationOnFunction() {