From da31a9696c8ea78e53e590189257835fed0993a5 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Thu, 21 Jun 2012 14:44:50 +0400 Subject: [PATCH] - Value parameters stubs - ToString methods for stubs - Some test fro stub tree construction --- .../src/org/jetbrains/jet/JetNodeTypes.java | 4 +- .../jet/lang/parsing/JetParserDefinition.java | 9 ++ .../org/jetbrains/jet/lang/psi/JetFile.java | 29 ++--- .../jetbrains/jet/lang/psi/JetParameter.java | 35 +++++- .../jet/lang/psi/JetParameterList.java | 19 +++- .../psi/stubs/PsiJetParameterListStub.java | 26 +++++ .../lang/psi/stubs/PsiJetParameterStub.java | 35 ++++++ .../stubs/elements/JetFileElementType.java | 2 +- .../stubs/elements/JetFileStubBuilder.java | 28 ++--- .../elements/JetFunctionElementType.java | 2 +- .../elements/JetParameterElementType.java | 96 ++++++++++++++++ .../elements/JetParameterListElementType.java | 77 +++++++++++++ .../stubs/elements/JetStubElementTypes.java | 3 + .../psi/stubs/impl/PsiJetClassStubImpl.java | 20 ++++ .../psi/stubs/impl/PsiJetFileStubImpl.java | 16 ++- .../stubs/impl/PsiJetFunctionStubImpl.java | 23 +++- .../impl/PsiJetParameterListStubImpl.java | 37 +++++++ .../stubs/impl/PsiJetParameterStubImpl.java | 104 ++++++++++++++++++ .../impl/PsiJetTypeParameterListStubImpl.java | 5 + .../impl/PsiJetTypeParameterStubImpl.java | 22 ++++ .../jet/plugin/stubs/JetStubsTest.java | 44 ++++++++ 21 files changed, 588 insertions(+), 48 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetParameterListStub.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetParameterStub.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetParameterElementType.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetParameterListElementType.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetParameterListStubImpl.java create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetParameterStubImpl.java diff --git a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java index 850aef38ad4..060c9d20b1e 100644 --- a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java +++ b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java @@ -48,8 +48,8 @@ public interface JetNodeTypes { JetNodeType DELEGATOR_SUPER_CALL = new JetNodeType("DELEGATOR_SUPER_CALL", JetDelegatorToSuperCall.class); JetNodeType DELEGATOR_SUPER_CLASS = new JetNodeType("DELEGATOR_SUPER_CLASS", JetDelegatorToSuperClass.class); JetNodeType CONSTRUCTOR_CALLEE = new JetNodeType("CONSTRUCTOR_CALLEE", JetConstructorCalleeExpression.class); - JetNodeType VALUE_PARAMETER_LIST = new JetNodeType("VALUE_PARAMETER_LIST", JetParameterList.class); - JetNodeType VALUE_PARAMETER = new JetNodeType("VALUE_PARAMETER", JetParameter.class); + IElementType VALUE_PARAMETER_LIST = JetStubElementTypes.VALUE_PARAMETER_LIST; + IElementType VALUE_PARAMETER = JetStubElementTypes.VALUE_PARAMETER; JetNodeType CLASS_BODY = new JetNodeType("CLASS_BODY", JetClassBody.class); JetNodeType IMPORT_DIRECTIVE = new JetNodeType("IMPORT_DIRECTIVE", JetImportDirective.class); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParserDefinition.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParserDefinition.java index 3f109feac74..7929d9e221f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParserDefinition.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParserDefinition.java @@ -46,34 +46,41 @@ public class JetParserDefinition implements ParserDefinition { }*/ } + @Override @NotNull public Lexer createLexer(Project project) { return new JetLexer(); } + @Override public PsiParser createParser(Project project) { return new JetParser(); } + @Override public IFileElementType getFileNodeType() { return JetStubElementTypes.FILE; } + @Override @NotNull public TokenSet getWhitespaceTokens() { return JetTokens.WHITESPACES; } + @Override @NotNull public TokenSet getCommentTokens() { return JetTokens.COMMENTS; } + @Override @NotNull public TokenSet getStringLiteralElements() { return JetTokens.STRINGS; } + @Override @NotNull public PsiElement createElement(ASTNode astNode) { if (astNode.getElementType() instanceof JetStubElementType) { @@ -83,10 +90,12 @@ public class JetParserDefinition implements ParserDefinition { return ((JetNodeType) astNode.getElementType()).createPsi(astNode); } + @Override public PsiFile createFile(FileViewProvider fileViewProvider) { return new JetFile(fileViewProvider); } + @Override public SpaceRequirements spaceExistanceTypeBetweenTokens(ASTNode astNode, ASTNode astNode1) { return SpaceRequirements.MAY; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java index c6daf28781c..11f26878528 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java @@ -24,12 +24,11 @@ import com.intellij.lang.ASTNode; import com.intellij.openapi.fileTypes.FileType; import com.intellij.psi.FileViewProvider; import com.intellij.psi.PsiElementVisitor; -import com.intellij.psi.stubs.StubElement; -import com.intellij.psi.stubs.StubTree; 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.PsiJetFileStub; import org.jetbrains.jet.plugin.JetFileType; import org.jetbrains.jet.plugin.JetLanguage; @@ -78,6 +77,17 @@ public class JetFile extends PsiFileBase implements JetDeclarationContainer { return ast != null ? (JetNamespaceHeader) ast.getPsi() : null; } + @Nullable + public String getPackageName() { + PsiJetFileStub stub = (PsiJetFileStub)getStub(); + if (stub != null) { + return stub.getPackageName(); + } + + JetNamespaceHeader statement = getNamespaceHeader(); + return statement != null ? statement.getQualifiedName() : null; + } + @Nullable public JetScript getScript() { return PsiTreeUtil.getChildOfType(this, JetScript.class); @@ -102,19 +112,4 @@ public class JetFile extends PsiFileBase implements JetDeclarationContainer { visitor.visitFile(this); } } - - @Override - public StubElement getStub() { - return super.getStub(); //To change body of overridden methods use File | Settings | File Templates. - } - - @Override - public StubTree calcStubTree() { - return super.calcStubTree(); //To change body of overridden methods use File | Settings | File Templates. - } - - @Override - public StubTree getStubTree() { - return super.getStubTree(); //To change body of overridden methods use File | Settings | File Templates. - } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetParameter.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetParameter.java index 21020e1c25c..011a6dae0f8 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetParameter.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetParameter.java @@ -17,19 +17,42 @@ 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; +import org.jetbrains.jet.lang.psi.stubs.PsiJetParameterStub; +import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes; import org.jetbrains.jet.lexer.JetTokens; /** * @author max */ -public class JetParameter extends JetNamedDeclarationNotStubbed { +public class JetParameter extends JetNamedDeclarationStub { + public static final JetParameter[] EMPTY_ARRAY = new JetParameter[0]; + + public static final ArrayFactory ARRAY_FACTORY = new ArrayFactory() { + @Override + public JetParameter[] create(final int count) { + return count == 0 ? EMPTY_ARRAY : new JetParameter[count]; + } + }; + public JetParameter(@NotNull ASTNode node) { super(node); } + public JetParameter(@NotNull PsiJetParameterStub stub, @NotNull IStubElementType nodeType) { + super(stub, nodeType); + } + + @NotNull + @Override + public IStubElementType getElementType() { + return JetStubElementTypes.VALUE_PARAMETER; + } + @Override public void accept(@NotNull JetVisitorVoid visitor) { visitor.visitParameter(this); @@ -61,10 +84,20 @@ public class JetParameter extends JetNamedDeclarationNotStubbed { } public boolean isMutable() { + PsiJetParameterStub stub = getStub(); + if (stub != null) { + return stub.isMutable(); + } + return findChildByType(JetTokens.VAR_KEYWORD) != null; } public boolean isVarArg() { + PsiJetParameterStub stub = getStub(); + if (stub != null) { + return stub.isVarArg(); + } + JetModifierList modifierList = getModifierList(); return modifierList != null && modifierList.getModifierNode(JetTokens.VARARG_KEYWORD) != null; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetParameterList.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetParameterList.java index 4a83ccbb846..619814ece80 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetParameterList.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetParameterList.java @@ -17,19 +17,32 @@ 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.PsiJetParameterListStub; +import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes; +import java.util.Arrays; import java.util.List; /** * @author max */ -public class JetParameterList extends JetElementImpl { +public class JetParameterList extends JetElementImplStub { public JetParameterList(@NotNull ASTNode node) { super(node); } + public JetParameterList(@NotNull PsiJetParameterListStub stub, @NotNull IStubElementType nodeType) { + super(stub, nodeType); + } + + @NotNull + @Override + public IStubElementType getElementType() { + return JetStubElementTypes.VALUE_PARAMETER_LIST; + } + @Override public void accept(@NotNull JetVisitorVoid visitor) { visitor.visitParameterList(this); @@ -41,6 +54,6 @@ public class JetParameterList extends JetElementImpl { } public List getParameters() { - return findChildrenByType(JetNodeTypes.VALUE_PARAMETER); + return Arrays.asList(getStubOrPsiChildren(JetStubElementTypes.VALUE_PARAMETER, JetParameter.ARRAY_FACTORY)); } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetParameterListStub.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetParameterListStub.java new file mode 100644 index 00000000000..8526417d3bb --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetParameterListStub.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.JetParameterList; + +/** + * @author Nikolay Krasko + */ +public interface PsiJetParameterListStub extends StubElement { +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetParameterStub.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetParameterStub.java new file mode 100644 index 00000000000..afdfd92ffdb --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetParameterStub.java @@ -0,0 +1,35 @@ +/* + * 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.NamedStub; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lang.psi.JetParameter; + +/** + * @author Nikolay Krasko + */ +public interface PsiJetParameterStub extends NamedStub { + boolean isMutable(); + boolean isVarArg(); + + @Nullable + String getTypeText(); + + @Nullable + String getDefaultValueText(); +} 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 5be6bb2b270..d324cda19c7 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 = 9; + public static final int STUB_VERSION = 10; public JetFileElementType() { super("jet.FILE", JetLanguage.INSTANCE); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileStubBuilder.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileStubBuilder.java index b8d513f060e..cbc870bf152 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileStubBuilder.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileStubBuilder.java @@ -19,35 +19,21 @@ package org.jetbrains.jet.lang.psi.stubs.elements; import com.intellij.psi.PsiFile; import com.intellij.psi.stubs.DefaultStubBuilder; import com.intellij.psi.stubs.StubElement; -import com.intellij.util.io.StringRef; +import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetFileStubImpl; /** * @author Nikolay Krasko */ -public class JetFileStubBuilder extends DefaultStubBuilder { +public class JetFileStubBuilder extends DefaultStubBuilder { @Override - protected StubElement createStubForFile(PsiFile file) { - - if (!(file instanceof JetFile)) return super.createStubForFile(file); + protected StubElement createStubForFile(@NotNull PsiFile file) { + if (!(file instanceof JetFile)) { + return super.createStubForFile(file); + } JetFile jetFile = (JetFile) file; - - // TODO (stubs): - String packageName = "default"; - -// String refText = ""; -// -// final LighterASTNode pkg = LightTreeUtil.firstChildOfType(tree, tree.getRoot(), JavaElementType.PACKAGE_STATEMENT); -// if (pkg != null) { -// final LighterASTNode ref = LightTreeUtil.firstChildOfType(tree, pkg, JavaElementType.JAVA_CODE_REFERENCE); -// if (ref != null) { -// refText = SourceUtil.getTextSkipWhiteSpaceAndComments(tree, ref); -// -// } -// } - - return new PsiJetFileStubImpl(jetFile, StringRef.fromString(packageName)); + return new PsiJetFileStubImpl(jetFile, jetFile.getPackageName()); } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFunctionElementType.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFunctionElementType.java index 479ec26e0f1..88721f682fe 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFunctionElementType.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFunctionElementType.java @@ -58,7 +58,7 @@ public class JetFunctionElementType extends JetStubElementType { + public JetParameterElementType(@NotNull @NonNls String debugName) { + super(debugName); + } + + @Override + public JetParameter createPsiFromAst(@NotNull ASTNode node) { + return new JetParameter(node); + } + + @Override + public PsiJetParameterStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) { + return null; + } + + @Override + public JetParameter createPsi(@NotNull PsiJetParameterStub stub) { + return new JetParameter(stub, JetStubElementTypes.VALUE_PARAMETER); + } + + @Override + public PsiJetParameterStub createStub(@NotNull JetParameter psi, StubElement parentStub) { + JetTypeReference typeReference = psi.getTypeReference(); + JetExpression defaultValue = psi.getDefaultValue(); + + return new PsiJetParameterStubImpl(JetStubElementTypes.VALUE_PARAMETER, parentStub, + psi.getName(), psi.isMutable(), psi.isVarArg(), + typeReference != null ? typeReference.getText() : null, + defaultValue != null ? defaultValue.getText() : null); + } + + @Override + public void serialize(PsiJetParameterStub stub, StubOutputStream dataStream) throws IOException { + dataStream.writeName(stub.getName()); + dataStream.writeBoolean(stub.isMutable()); + dataStream.writeBoolean(stub.isVarArg()); + dataStream.writeName(stub.getTypeText()); + dataStream.writeName(stub.getDefaultValueText()); + } + + @Override + public PsiJetParameterStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException { + StringRef name = dataStream.readName(); + boolean isMutable = dataStream.readBoolean(); + boolean isVarArg = dataStream.readBoolean(); + StringRef typeText = dataStream.readName(); + StringRef defaultValueText = dataStream.readName(); + + return new PsiJetParameterStubImpl(JetStubElementTypes.VALUE_PARAMETER, parentStub, name, isMutable, isVarArg, + typeText, defaultValueText); + } + + @Override + public void indexStub(PsiJetParameterStub stub, IndexSink sink) { + // No index + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetParameterListElementType.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetParameterListElementType.java new file mode 100644 index 00000000000..a506895260f --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetParameterListElementType.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.JetParameterList; +import org.jetbrains.jet.lang.psi.stubs.PsiJetParameterListStub; +import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetParameterListStubImpl; + +import java.io.IOException; + +/** + * @author Nikolay Krasko + */ +public class JetParameterListElementType extends JetStubElementType { + public JetParameterListElementType(@NotNull @NonNls String debugName) { + super(debugName); + } + + @Override + public JetParameterList createPsiFromAst(@NotNull ASTNode node) { + return new JetParameterList(node); + } + + @Override + public PsiJetParameterListStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) { + return null; + } + + @Override + public JetParameterList createPsi(@NotNull PsiJetParameterListStub stub) { + return new JetParameterList(stub, JetStubElementTypes.VALUE_PARAMETER_LIST); + } + + @Override + public PsiJetParameterListStub createStub(@NotNull JetParameterList psi, StubElement parentStub) { + return new PsiJetParameterListStubImpl(JetStubElementTypes.VALUE_PARAMETER_LIST, parentStub); + } + + @Override + public void serialize(PsiJetParameterListStub stub, StubOutputStream dataStream) throws IOException { + // Nothing to serialize + } + + @Override + public PsiJetParameterListStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException { + return new PsiJetParameterListStubImpl(JetStubElementTypes.VALUE_PARAMETER_LIST, parentStub); + } + + @Override + public void indexStub(PsiJetParameterListStub stub, IndexSink sink) { + // No index + } +} + 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 8298393510f..849f5a0ac3b 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,6 +26,9 @@ public interface JetStubElementTypes { JetFunctionElementType FUNCTION = new JetFunctionElementType("FUN"); JetPropertyElementType PROPERTY = new JetPropertyElementType("PROPERTY"); + JetParameterElementType VALUE_PARAMETER = new JetParameterElementType("VALUE_PARAMETER"); + JetParameterListElementType VALUE_PARAMETER_LIST = new JetParameterListElementType("VALUE_PARAMETER_LIST"); + 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/impl/PsiJetClassStubImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetClassStubImpl.java index 8a6db9da76d..d4109d87438 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetClassStubImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetClassStubImpl.java @@ -16,8 +16,10 @@ package org.jetbrains.jet.lang.psi.stubs.impl; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.stubs.StubBase; import com.intellij.psi.stubs.StubElement; +import com.intellij.util.ArrayUtil; import com.intellij.util.io.StringRef; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -95,4 +97,22 @@ public class PsiJetClassStubImpl extends StubBase implements PsiJetCla } return result; } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("PsiJetClassStubImpl["); + + if (isTrait()) { + builder.append("trait "); + } + + builder.append("name=").append(getName()); + builder.append(" fqn=").append(getQualifiedName()); + builder.append(" superNames=").append("[").append(StringUtil.join(ArrayUtil.toStringArray(getSuperNames()))).append("]"); + + builder.append("]"); + + return builder.toString(); + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetFileStubImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetFileStubImpl.java index 6eb022db2b0..ec1518ebb38 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetFileStubImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetFileStubImpl.java @@ -33,10 +33,13 @@ public class PsiJetFileStubImpl extends PsiFileStubImpl implements PsiJ public PsiJetFileStubImpl(JetFile jetFile, StringRef packageName) { super(jetFile); - this.packageName = packageName; } + public PsiJetFileStubImpl(JetFile jetFile, String packageName) { + this(jetFile, StringRef.fromString(packageName)); + } + @Override public String getPackageName() { return StringRef.toString(packageName); @@ -56,4 +59,15 @@ public class PsiJetFileStubImpl extends PsiFileStubImpl implements PsiJ public PsiClass[] getClasses() { return new PsiClass[0]; } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + + builder.append("PsiJetFileStubImpl["); + builder.append("package=").append(getPackageName()); + builder.append("]"); + + return builder.toString(); + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetFunctionStubImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetFunctionStubImpl.java index 742d13c41d3..bf5e0429e58 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetFunctionStubImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetFunctionStubImpl.java @@ -19,6 +19,7 @@ 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 com.intellij.util.ArrayUtil; import com.intellij.util.io.StringRef; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -67,6 +68,26 @@ public class PsiJetFunctionStubImpl extends StubBase implement @Override public String[] getAnnotations() { // TODO (stubs) - return new String[0]; + return ArrayUtil.EMPTY_STRING_ARRAY; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("PsiJetFunctionStubImpl["); + + if (isTopLevel()) { + builder.append("top "); + } + + if (isExtension()) { + builder.append("ext "); + } + + builder.append("name=").append(getName()); + + builder.append("]"); + + return builder.toString(); } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetParameterListStubImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetParameterListStubImpl.java new file mode 100644 index 00000000000..9be535cf99a --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetParameterListStubImpl.java @@ -0,0 +1,37 @@ +/* + * 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.jet.lang.psi.JetParameterList; +import org.jetbrains.jet.lang.psi.stubs.PsiJetParameterListStub; + +/** + * @author Nikolay Krasko + */ +public class PsiJetParameterListStubImpl extends StubBase implements PsiJetParameterListStub { + public PsiJetParameterListStubImpl(IStubElementType elementType, StubElement parent) { + super(parent, elementType); + } + + @Override + public String toString() { + return "PsiJetParameterListStubImpl"; + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetParameterStubImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetParameterStubImpl.java new file mode 100644 index 00000000000..09bae3d8fb2 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetParameterStubImpl.java @@ -0,0 +1,104 @@ +/* + * 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 com.intellij.util.io.StringRef; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lang.psi.JetParameter; +import org.jetbrains.jet.lang.psi.stubs.PsiJetParameterStub; + +/** + * @author Nikolay Krasko + */ +public class PsiJetParameterStubImpl extends StubBase implements PsiJetParameterStub { + private final StringRef name; + private final boolean isMutable; + private final boolean isVarArg; + private final StringRef typeText; + private final StringRef defaultValueText; + + public PsiJetParameterStubImpl(IStubElementType elementType, StubElement parent, + StringRef name, + boolean isMutable, + boolean isVarArg, + StringRef typeText, StringRef defaultValueText) { + super(parent, elementType); + this.name = name; + this.isMutable = isMutable; + this.isVarArg = isVarArg; + this.typeText = typeText; + this.defaultValueText = defaultValueText; + } + + public PsiJetParameterStubImpl(IStubElementType elementType, StubElement parent, + String name, + boolean isMutable, + boolean isVarArg, + String typeText, String defaultValueText) { + this(elementType, parent, StringRef.fromString(name), isMutable, isVarArg, + StringRef.fromString(typeText), StringRef.fromString(defaultValueText)); + } + + @Override + public String getName() { + return StringRef.toString(name); + } + + @Override + public boolean isMutable() { + return isMutable; + } + + @Override + public boolean isVarArg() { + return isVarArg; + } + + @Nullable + @Override + public String getTypeText() { + return StringRef.toString(typeText); + } + + @Override + public String getDefaultValueText() { + return StringRef.toString(defaultValueText); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("PsiJetParameterStubImpl["); + + builder.append(isMutable() ? "var " : "val "); + + if (isVarArg()) { + builder.append("vararg "); + } + + builder.append("name=").append(getName()); + builder.append(" typeText=").append(getTypeText()); + builder.append(" defaultValue=").append(getDefaultValueText()); + + builder.append("]"); + + return builder.toString(); + } +} 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 index aaaf1795fd0..452379bc2b9 100644 --- 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 @@ -30,4 +30,9 @@ public class PsiJetTypeParameterListStubImpl extends StubBase impl public PsiJetTypeParameterStubImpl(JetTypeParameterElementType type, final StubElement parent, StringRef name, StringRef extendBoundTypeText, boolean isInVariance, boolean isOutVariance) { super(parent, type); + this.name = name; this.extendBoundTypeText = extendBoundTypeText; this.isInVariance = isInVariance; @@ -65,4 +66,25 @@ public class PsiJetTypeParameterStubImpl extends StubBase impl public String getName() { return StringRef.toString(name); } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("PsiJetTypeParameterStubImpl["); + + if (isInVariance()) { + builder.append("in "); + } + + if (isOutVariance()) { + builder.append("out "); + } + + builder.append("name=").append(getName()); + builder.append(" extendText=").append(getExtendBoundTypeText()); + + builder.append("]"); + + return builder.toString(); + } } diff --git a/idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java b/idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java index 64c331f67cb..74f30ae0770 100644 --- a/idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java @@ -16,15 +16,21 @@ package org.jetbrains.jet.plugin.stubs; +import com.intellij.lang.FileASTNode; import com.intellij.psi.PsiFile; +import com.intellij.psi.impl.DebugUtil; +import com.intellij.psi.stubs.StubElement; import com.intellij.testFramework.LightProjectDescriptor; import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.psi.JetClass; import org.jetbrains.jet.lang.psi.JetDeclaration; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub; +import org.jetbrains.jet.lang.psi.stubs.elements.JetFileStubBuilder; import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes; +import org.jetbrains.jet.plugin.JetFileType; import org.jetbrains.jet.plugin.JetLightProjectDescriptor; import java.util.List; @@ -55,4 +61,42 @@ public class JetStubsTest extends LightCodeInsightFixtureTestCase { final PsiJetClassStub stub = JetStubElementTypes.CLASS.createStub(jetClass, null); assertEquals(true, stub.isTrait()); } + + public void testFilePackage() { + doBuildTest("package some.test", + "PsiJetFileStubImpl[package=some.test]\n"); + } + + public void testClassTypeParameters() { + doBuildTest("class C { }", + "PsiJetFileStubImpl[package=]\n" + + " CLASS:PsiJetClassStubImpl[name=C fqn=C superNames=[]]\n" + + " TYPE_PARAMETER_LIST:PsiJetTypeParameterListStubImpl\n" + + " TYPE_PARAMETER:PsiJetTypeParameterStubImpl[name=T extendText=null]\n"); + } + + public void testFunctionParameters() { + doBuildTest("fun some(t: Int, other: String = \"hello\") { }", + "PsiJetFileStubImpl[package=]\n" + + " FUN:PsiJetFunctionStubImpl[top name=some]\n" + + " VALUE_PARAMETER_LIST:PsiJetParameterListStubImpl\n" + + " VALUE_PARAMETER:PsiJetParameterStubImpl[val name=t typeText=Int defaultValue=null]\n" + + " VALUE_PARAMETER:PsiJetParameterStubImpl[val name=other typeText=String defaultValue=\"hello\"]\n"); + } + + private void doBuildTest(@NonNls final String source, @NonNls @NotNull final String tree) { + final JetFile file = (JetFile) createLightFile(JetFileType.INSTANCE, source); + final FileASTNode fileNode = file.getNode(); + assertNotNull(fileNode); + // assertFalse(fileNode.isParsed()); // TODO + + JetFileStubBuilder jetStubBuilder = new JetFileStubBuilder(); + + final StubElement lighterTree = jetStubBuilder.buildStubTree(file); + // assertFalse(fileNode.isParsed()); // TODO + + final String lightStr = DebugUtil.stubTreeToString(lighterTree); + + assertEquals("light tree differs", tree, lightStr); + } }