From 4b77268b21b851a4c4a02fbe2da25d58b75f435e Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Wed, 20 Jun 2012 15:47:14 +0400 Subject: [PATCH] Stub for JetTypeParameterList element --- .../src/org/jetbrains/jet/JetNodeTypes.java | 2 +- .../jet/lang/psi/JetClassOrObject.java | 3 +- .../jet/lang/psi/JetDeclarationStub.java | 42 +--------- .../jet/lang/psi/JetElementImplStub.java | 84 +++++++++++++++++++ .../jet/lang/psi/JetTypeParameter.java | 10 +++ .../jet/lang/psi/JetTypeParameterList.java | 19 ++++- .../stubs/PsiJetTypeParameterListStub.java | 26 ++++++ .../stubs/elements/JetFileElementType.java | 2 +- .../stubs/elements/JetStubElementTypes.java | 1 + .../JetTypeParameterListElementType.java | 77 +++++++++++++++++ .../impl/PsiJetTypeParameterListStubImpl.java | 33 ++++++++ .../caches/JetGotoClassContributor.java | 2 +- 12 files changed, 252 insertions(+), 49 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetElementImplStub.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetTypeParameterListStub.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetTypeParameterListElementType.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetTypeParameterListStubImpl.java diff --git a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java index efdd67a211c..7bf0fd0534d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java +++ b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java @@ -42,7 +42,7 @@ public interface JetNodeTypes { JetNodeType ENUM_ENTRY = new JetNodeType("ENUM_ENTRY", JetEnumEntry.class); JetNodeType ANONYMOUS_INITIALIZER = new JetNodeType("ANONYMOUS_INITIALIZER", JetClassInitializer.class); - JetNodeType TYPE_PARAMETER_LIST = new JetNodeType("TYPE_PARAMETER_LIST", JetTypeParameterList.class); + IElementType TYPE_PARAMETER_LIST = JetStubElementTypes.TYPE_PARAMETER_LIST; IElementType TYPE_PARAMETER = JetStubElementTypes.TYPE_PARAMETER; JetNodeType DELEGATION_SPECIFIER_LIST = new JetNodeType("DELEGATION_SPECIFIER_LIST", JetDelegationSpecifierList.class); JetNodeType DELEGATOR_BY = new JetNodeType("DELEGATOR_BY", JetDelegatorByExpressionSpecifier.class); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassOrObject.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassOrObject.java index 660791c7148..ab95aca8e57 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassOrObject.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassOrObject.java @@ -16,7 +16,6 @@ package org.jetbrains.jet.lang.psi; -import com.intellij.psi.PsiElement; import com.intellij.psi.PsiNameIdentifierOwner; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,7 +26,7 @@ import java.util.List; /** * @author max */ -public interface JetClassOrObject extends PsiElement, PsiNameIdentifierOwner, JetDeclarationContainer { +public interface JetClassOrObject extends PsiNameIdentifierOwner, JetDeclarationContainer { @Nullable JetDelegationSpecifierList getDelegationSpecifierList(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationStub.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationStub.java index 3d47257e1b9..c73d670ff9d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationStub.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationStub.java @@ -16,11 +16,7 @@ package org.jetbrains.jet.lang.psi; -import com.intellij.extapi.psi.StubBasedPsiElementBase; import com.intellij.lang.ASTNode; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiElementVisitor; -import com.intellij.psi.StubBasedPsiElement; import com.intellij.psi.stubs.IStubElementType; import com.intellij.psi.stubs.StubElement; import org.jetbrains.annotations.NotNull; @@ -30,7 +26,7 @@ import org.jetbrains.jet.lexer.JetToken; /** * @author Nikolay Krasko */ -abstract class JetDeclarationStub extends StubBasedPsiElementBase implements JetDeclaration, StubBasedPsiElement { +abstract class JetDeclarationStub extends JetElementImplStub implements JetDeclaration { public JetDeclarationStub(@NotNull T stub, @NotNull IStubElementType nodeType) { super(stub, nodeType); } @@ -49,40 +45,4 @@ abstract class JetDeclarationStub extends StubBasedPsiEle JetModifierList modifierList = getModifierList(); return modifierList != null && modifierList.hasModifier(modifier); } - - @Override - public String toString() { - return getNode().getElementType().toString(); - } - - @Override - public final void accept(@NotNull PsiElementVisitor visitor) { - if (visitor instanceof JetVisitorVoid) { - accept((JetVisitorVoid) visitor); - } - else { - visitor.visitElement(this); - } - } - - @Override - public void acceptChildren(@NotNull JetTreeVisitor visitor, D data) { - PsiElement child = getFirstChild(); - while (child != null) { - if (child instanceof JetElement) { - ((JetElement) child).accept(visitor, data); - } - child = child.getNextSibling(); - } - } - - @Override - public void accept(@NotNull JetVisitorVoid visitor) { - visitor.visitJetElement(this); - } - - @Override - public R accept(@NotNull JetVisitor visitor, D data) { - return visitor.visitJetElement(this, data); - } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetElementImplStub.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetElementImplStub.java new file mode 100644 index 00000000000..1ddd0fd51a2 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetElementImplStub.java @@ -0,0 +1,84 @@ +/* + * Copyright 2010-2012 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; + +import com.intellij.extapi.psi.StubBasedPsiElementBase; +import com.intellij.lang.ASTNode; +import com.intellij.lang.Language; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiElementVisitor; +import com.intellij.psi.StubBasedPsiElement; +import com.intellij.psi.stubs.IStubElementType; +import com.intellij.psi.stubs.StubElement; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.plugin.JetLanguage; + +/** + * @author Nikolay Krasko + */ +public class JetElementImplStub extends StubBasedPsiElementBase + implements JetElement, StubBasedPsiElement { + public JetElementImplStub(@NotNull T stub, @NotNull IStubElementType nodeType) { + super(stub, nodeType); + } + + public JetElementImplStub(@NotNull ASTNode node) { + super(node); + } + + @NotNull + @Override + public Language getLanguage() { + return JetLanguage.INSTANCE; + } + + @Override + public String toString() { + return getNode().getElementType().toString(); + } + + @Override + public final void accept(@NotNull PsiElementVisitor visitor) { + if (visitor instanceof JetVisitorVoid) { + accept((JetVisitorVoid) visitor); + } + else { + visitor.visitElement(this); + } + } + + @Override + public void acceptChildren(@NotNull JetTreeVisitor visitor, D data) { + PsiElement child = getFirstChild(); + while (child != null) { + if (child instanceof JetElement) { + ((JetElement) child).accept(visitor, data); + } + child = child.getNextSibling(); + } + } + + @Override + public void accept(@NotNull JetVisitorVoid visitor) { + visitor.visitJetElement(this); + } + + @Override + public R accept(@NotNull JetVisitor visitor, D data) { + return visitor.visitJetElement(this, data); + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeParameter.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeParameter.java index 9315f2703db..20f265ccace 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeParameter.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeParameter.java @@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.psi; import com.intellij.lang.ASTNode; import com.intellij.psi.stubs.IStubElementType; +import com.intellij.util.ArrayFactory; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.JetNodeTypes; @@ -30,6 +31,15 @@ import org.jetbrains.jet.lexer.JetTokens; * @author max */ public class JetTypeParameter extends JetNamedDeclarationStub { + public static final JetTypeParameter[] EMPTY_ARRAY = new JetTypeParameter[0]; + + public static final ArrayFactory ARRAY_FACTORY = new ArrayFactory() { + @Override + public JetTypeParameter[] create(final int count) { + return count == 0 ? EMPTY_ARRAY : new JetTypeParameter[count]; + } + }; + public JetTypeParameter(@NotNull ASTNode node) { super(node); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeParameterList.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeParameterList.java index cc5e76869fc..b31bc1eb376 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeParameterList.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetTypeParameterList.java @@ -17,21 +17,34 @@ package org.jetbrains.jet.lang.psi; import com.intellij.lang.ASTNode; +import com.intellij.psi.stubs.IStubElementType; import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.JetNodeTypes; +import org.jetbrains.jet.lang.psi.stubs.PsiJetTypeParameterListStub; +import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes; +import java.util.Arrays; import java.util.List; /** * @author max */ -public class JetTypeParameterList extends JetElementImpl { +public class JetTypeParameterList extends JetElementImplStub { public JetTypeParameterList(@NotNull ASTNode node) { super(node); } + public JetTypeParameterList(@NotNull PsiJetTypeParameterListStub stub, @NotNull IStubElementType nodeType) { + super(stub, nodeType); + } + public List getParameters() { - return findChildrenByType(JetNodeTypes.TYPE_PARAMETER); + return Arrays.asList(getStubOrPsiChildren(JetStubElementTypes.TYPE_PARAMETER, JetTypeParameter.ARRAY_FACTORY)); + } + + @NotNull + @Override + public IStubElementType getElementType() { + return JetStubElementTypes.TYPE_PARAMETER_LIST; } @Override diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetTypeParameterListStub.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetTypeParameterListStub.java new file mode 100644 index 00000000000..8cbc0fb72b8 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetTypeParameterListStub.java @@ -0,0 +1,26 @@ +/* + * Copyright 2010-2012 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.JetTypeParameterList; + +/** + * @author Nikolay Krasko + */ +public interface PsiJetTypeParameterListStub extends StubElement { +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java index c2bca143382..fa97579497e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java @@ -38,7 +38,7 @@ import java.io.IOException; * @author Nikolay Krasko */ public class JetFileElementType extends IStubFileElementType { - public static final int STUB_VERSION = 6; + public static final int STUB_VERSION = 8; public JetFileElementType() { super("jet.FILE", JetLanguage.INSTANCE); 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 0cdf963e265..edf994cbc6f 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 @@ -26,4 +26,5 @@ public interface JetStubElementTypes { JetFunctionElementType FUNCTION = new JetFunctionElementType("FUN"); JetTypeParameterElementType TYPE_PARAMETER = new JetTypeParameterElementType("TYPE_PARAMETER"); + JetTypeParameterListElementType TYPE_PARAMETER_LIST = new JetTypeParameterListElementType("TYPE_PARAMETER_LIST"); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetTypeParameterListElementType.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetTypeParameterListElementType.java new file mode 100644 index 00000000000..5d0a49a79a0 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetTypeParameterListElementType.java @@ -0,0 +1,77 @@ +/* + * Copyright 2010-2012 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.lang.LighterAST; +import com.intellij.lang.LighterASTNode; +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.JetTypeParameterList; +import org.jetbrains.jet.lang.psi.stubs.PsiJetTypeParameterListStub; +import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetTypeParameterListStubImpl; + +import java.io.IOException; + +/** + * @author Nikolay Krasko + */ +public class JetTypeParameterListElementType extends JetStubElementType { + public JetTypeParameterListElementType(@NotNull @NonNls String debugName) { + super(debugName); + } + + @Override + public JetTypeParameterList createPsiFromAst(@NotNull ASTNode node) { + return new JetTypeParameterList(node); + } + + @Override + public PsiJetTypeParameterListStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) { + return null; + } + + @Override + public JetTypeParameterList createPsi(@NotNull PsiJetTypeParameterListStub stub) { + return new JetTypeParameterList(stub, JetStubElementTypes.TYPE_PARAMETER_LIST); + } + + @Override + public PsiJetTypeParameterListStub createStub(@NotNull JetTypeParameterList psi, StubElement parentStub) { + return new PsiJetTypeParameterListStubImpl(JetStubElementTypes.TYPE_PARAMETER_LIST, parentStub); + } + + @Override + public void serialize(PsiJetTypeParameterListStub stub, StubOutputStream dataStream) throws IOException { + // Do nothing + } + + @Override + public PsiJetTypeParameterListStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException { + return new PsiJetTypeParameterListStubImpl(JetStubElementTypes.TYPE_PARAMETER_LIST, parentStub); + } + + @Override + public void indexStub(PsiJetTypeParameterListStub stub, IndexSink sink) { + // No index + } +} + diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetTypeParameterListStubImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetTypeParameterListStubImpl.java new file mode 100644 index 00000000000..aaaf1795fd0 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetTypeParameterListStubImpl.java @@ -0,0 +1,33 @@ +/* + * Copyright 2010-2012 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.annotations.NotNull; +import org.jetbrains.jet.lang.psi.JetTypeParameterList; +import org.jetbrains.jet.lang.psi.stubs.PsiJetTypeParameterListStub; + +/** + * @author Nikolay Krasko + */ +public class PsiJetTypeParameterListStubImpl extends StubBase implements PsiJetTypeParameterListStub { + public PsiJetTypeParameterListStubImpl(@NotNull IStubElementType elementType, final StubElement parent) { + super(parent, elementType); + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/caches/JetGotoClassContributor.java b/idea/src/org/jetbrains/jet/plugin/caches/JetGotoClassContributor.java index f1e3489b772..a67b0c0c4f9 100644 --- a/idea/src/org/jetbrains/jet/plugin/caches/JetGotoClassContributor.java +++ b/idea/src/org/jetbrains/jet/plugin/caches/JetGotoClassContributor.java @@ -57,7 +57,7 @@ public class JetGotoClassContributor implements GotoClassContributor { final GlobalSearchScope scope = GlobalSearchScope.allScope(project); PsiClass[] classes = JetCacheManager.getInstance(project).getNamesCache().getClassesByName(name, scope); - HashSet javaQualifiedNames = new HashSet(); + Collection javaQualifiedNames = new HashSet(); for (PsiClass aClass : classes) { String qualifiedName = aClass.getQualifiedName();