- Value parameters stubs
- ToString methods for stubs - Some test fro stub tree construction
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<PsiJetParameterStub> {
|
||||
public static final JetParameter[] EMPTY_ARRAY = new JetParameter[0];
|
||||
|
||||
public static final ArrayFactory<JetParameter> ARRAY_FACTORY = new ArrayFactory<JetParameter>() {
|
||||
@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;
|
||||
}
|
||||
|
||||
@@ -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<PsiJetParameterListStub> {
|
||||
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<JetParameter> getParameters() {
|
||||
return findChildrenByType(JetNodeTypes.VALUE_PARAMETER);
|
||||
return Arrays.asList(getStubOrPsiChildren(JetStubElementTypes.VALUE_PARAMETER, JetParameter.ARRAY_FACTORY));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<JetParameterList> {
|
||||
}
|
||||
@@ -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<JetParameter> {
|
||||
boolean isMutable();
|
||||
boolean isVarArg();
|
||||
|
||||
@Nullable
|
||||
String getTypeText();
|
||||
|
||||
@Nullable
|
||||
String getDefaultValueText();
|
||||
}
|
||||
+1
-1
@@ -38,7 +38,7 @@ import java.io.IOException;
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public class JetFileElementType extends IStubFileElementType<PsiJetFileStub> {
|
||||
public static final int STUB_VERSION = 9;
|
||||
public static final int STUB_VERSION = 10;
|
||||
|
||||
public JetFileElementType() {
|
||||
super("jet.FILE", JetLanguage.INSTANCE);
|
||||
|
||||
+7
-21
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ public class JetFunctionElementType extends JetStubElementType<PsiJetFunctionStu
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiJetFunctionStub createStub(@NotNull JetNamedFunction psi, StubElement parentStub) {
|
||||
public PsiJetFunctionStub createStub(@NotNull JetNamedFunction psi, @NotNull StubElement parentStub) {
|
||||
final boolean isTopLevel = parentStub instanceof PsiJetFileStub;
|
||||
final boolean isExtension = psi.getReceiverTypeRef() != null;
|
||||
|
||||
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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 com.intellij.util.io.StringRef;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetParameterStub;
|
||||
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetParameterStubImpl;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public class JetParameterElementType extends JetStubElementType<PsiJetParameterStub, JetParameter> {
|
||||
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
|
||||
}
|
||||
}
|
||||
+77
@@ -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<PsiJetParameterListStub, JetParameterList> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -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");
|
||||
}
|
||||
|
||||
@@ -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<JetClass> 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();
|
||||
}
|
||||
}
|
||||
|
||||
+15
-1
@@ -33,10 +33,13 @@ public class PsiJetFileStubImpl extends PsiFileStubImpl<JetFile> 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<JetFile> 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();
|
||||
}
|
||||
}
|
||||
|
||||
+22
-1
@@ -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<JetNamedFunction> 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();
|
||||
}
|
||||
}
|
||||
|
||||
+37
@@ -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<JetParameterList> implements PsiJetParameterListStub {
|
||||
public PsiJetParameterListStubImpl(IStubElementType elementType, StubElement parent) {
|
||||
super(parent, elementType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PsiJetParameterListStubImpl";
|
||||
}
|
||||
}
|
||||
+104
@@ -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<JetParameter> 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();
|
||||
}
|
||||
}
|
||||
+5
@@ -30,4 +30,9 @@ public class PsiJetTypeParameterListStubImpl extends StubBase<JetTypeParameterLi
|
||||
public PsiJetTypeParameterListStubImpl(@NotNull IStubElementType elementType, final StubElement parent) {
|
||||
super(parent, elementType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PsiJetTypeParameterListStubImpl";
|
||||
}
|
||||
}
|
||||
|
||||
+22
@@ -35,6 +35,7 @@ public class PsiJetTypeParameterStubImpl extends StubBase<JetTypeParameter> 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<JetTypeParameter> 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<T> { }",
|
||||
"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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user