Jet stubs (beginning)
This commit is contained in:
@@ -3,16 +3,20 @@
|
|||||||
*/
|
*/
|
||||||
package org.jetbrains.jet;
|
package org.jetbrains.jet;
|
||||||
|
|
||||||
|
import com.intellij.psi.tree.IElementType;
|
||||||
import com.intellij.psi.tree.IFileElementType;
|
import com.intellij.psi.tree.IFileElementType;
|
||||||
import org.jetbrains.jet.plugin.JetLanguage;
|
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
|
||||||
|
import org.jetbrains.jet.plugin.JetLanguage;
|
||||||
|
|
||||||
public interface JetNodeTypes {
|
public interface JetNodeTypes {
|
||||||
IFileElementType JET_FILE = new IFileElementType(JetLanguage.INSTANCE);
|
IFileElementType JET_FILE = new IFileElementType(JetLanguage.INSTANCE);
|
||||||
|
|
||||||
JetNodeType CLASS = new JetNodeType("CLASS", JetClass.class);
|
IElementType CLASS = JetStubElementTypes.CLASS;
|
||||||
|
IElementType FUN = JetStubElementTypes.FUNCTION;
|
||||||
|
|
||||||
JetNodeType PROPERTY = new JetNodeType("PROPERTY", JetProperty.class);
|
JetNodeType PROPERTY = new JetNodeType("PROPERTY", JetProperty.class);
|
||||||
JetNodeType FUN = new JetNodeType("FUN", JetNamedFunction.class);
|
|
||||||
JetNodeType TYPEDEF = new JetNodeType("TYPEDEF", JetTypedef.class);
|
JetNodeType TYPEDEF = new JetNodeType("TYPEDEF", JetTypedef.class);
|
||||||
JetNodeType OBJECT_DECLARATION = new JetNodeType("OBJECT_DECLARATION", JetObjectDeclaration.class);
|
JetNodeType OBJECT_DECLARATION = new JetNodeType("OBJECT_DECLARATION", JetObjectDeclaration.class);
|
||||||
JetNodeType OBJECT_DECLARATION_NAME = new JetNodeType("OBJECT_DECLARATION_NAME", JetObjectDeclarationName.class);
|
JetNodeType OBJECT_DECLARATION_NAME = new JetNodeType("OBJECT_DECLARATION_NAME", JetObjectDeclarationName.class);
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
|||||||
|
|
||||||
usedSet.removeAll(opSet);
|
usedSet.removeAll(opSet);
|
||||||
|
|
||||||
assert usedSet.isEmpty() : "" + usedSet;
|
assert usedSet.isEmpty() : usedSet.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -239,9 +239,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
|||||||
Precedence precedence = Precedence.ELVIS;
|
Precedence precedence = Precedence.ELVIS;
|
||||||
while (precedence != null) {
|
while (precedence != null) {
|
||||||
IElementType[] types = precedence.getOperations().getTypes();
|
IElementType[] types = precedence.getOperations().getTypes();
|
||||||
for (IElementType type : types) {
|
Collections.addAll(elvisFollow, types);
|
||||||
elvisFollow.add(type);
|
|
||||||
}
|
|
||||||
precedence = precedence.higher;
|
precedence = precedence.higher;
|
||||||
}
|
}
|
||||||
decomposerExpressionFollow = TokenSet.orSet(EXPRESSION_FOLLOW, TokenSet.create(elvisFollow.toArray(new IElementType[elvisFollow.size()])));
|
decomposerExpressionFollow = TokenSet.orSet(EXPRESSION_FOLLOW, TokenSet.create(elvisFollow.toArray(new IElementType[elvisFollow.size()])));
|
||||||
@@ -1052,7 +1050,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
|||||||
JetParsing.TokenDetector enumDetector = new JetParsing.TokenDetector(ENUM_KEYWORD);
|
JetParsing.TokenDetector enumDetector = new JetParsing.TokenDetector(ENUM_KEYWORD);
|
||||||
myJetParsing.parseModifierList(MODIFIER_LIST, enumDetector, false);
|
myJetParsing.parseModifierList(MODIFIER_LIST, enumDetector, false);
|
||||||
|
|
||||||
JetNodeType declType = parseLocalDeclarationRest(enumDetector.isDetected());
|
IElementType declType = parseLocalDeclarationRest(enumDetector.isDetected());
|
||||||
|
|
||||||
if (declType != null) {
|
if (declType != null) {
|
||||||
decl.done(declType);
|
decl.done(declType);
|
||||||
@@ -1369,9 +1367,9 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
|||||||
* : object
|
* : object
|
||||||
* ;
|
* ;
|
||||||
*/
|
*/
|
||||||
private JetNodeType parseLocalDeclarationRest(boolean isEnum) {
|
private IElementType parseLocalDeclarationRest(boolean isEnum) {
|
||||||
IElementType keywordToken = tt();
|
IElementType keywordToken = tt();
|
||||||
JetNodeType declType = null;
|
IElementType declType = null;
|
||||||
if (keywordToken == CLASS_KEYWORD || keywordToken == TRAIT_KEYWORD) {
|
if (keywordToken == CLASS_KEYWORD || keywordToken == TRAIT_KEYWORD) {
|
||||||
declType = myJetParsing.parseClass(isEnum);
|
declType = myJetParsing.parseClass(isEnum);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.jetbrains.jet.lang.parsing;
|
package org.jetbrains.jet.lang.parsing;
|
||||||
|
|
||||||
import com.intellij.extapi.psi.ASTWrapperPsiElement;
|
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
import com.intellij.lang.ParserDefinition;
|
import com.intellij.lang.ParserDefinition;
|
||||||
import com.intellij.lang.PsiParser;
|
import com.intellij.lang.PsiParser;
|
||||||
import com.intellij.lexer.Lexer;
|
import com.intellij.lexer.Lexer;
|
||||||
|
import com.intellij.openapi.application.ApplicationManager;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.psi.FileViewProvider;
|
import com.intellij.psi.FileViewProvider;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
@@ -18,10 +18,30 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.jet.JetNodeType;
|
import org.jetbrains.jet.JetNodeType;
|
||||||
import org.jetbrains.jet.JetNodeTypes;
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.elements.JetFakeStubElementFactory;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementFactory;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementType;
|
||||||
import org.jetbrains.jet.lexer.JetLexer;
|
import org.jetbrains.jet.lexer.JetLexer;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
public class JetParserDefinition implements ParserDefinition {
|
public class JetParserDefinition implements ParserDefinition {
|
||||||
|
|
||||||
|
// TODO (stubs):
|
||||||
|
private static JetStubElementFactory stubElementFactory = new JetFakeStubElementFactory();
|
||||||
|
|
||||||
|
public static void setStubFactory(JetStubElementFactory factory) {
|
||||||
|
stubElementFactory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JetStubElementFactory getStubElementTypeFactory() {
|
||||||
|
return stubElementFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JetParserDefinition() {
|
||||||
|
if (!ApplicationManager.getApplication().isCommandLine()) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Lexer createLexer(Project project) {
|
public Lexer createLexer(Project project) {
|
||||||
return new JetLexer();
|
return new JetLexer();
|
||||||
@@ -32,7 +52,9 @@ public class JetParserDefinition implements ParserDefinition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IFileElementType getFileNodeType() {
|
public IFileElementType getFileNodeType() {
|
||||||
|
// TODO (stubs)
|
||||||
return JetNodeTypes.JET_FILE;
|
return JetNodeTypes.JET_FILE;
|
||||||
|
// return JetStubElementTypes.FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -52,6 +74,10 @@ public class JetParserDefinition implements ParserDefinition {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public PsiElement createElement(ASTNode astNode) {
|
public PsiElement createElement(ASTNode astNode) {
|
||||||
|
if (astNode.getElementType() instanceof JetStubElementType) {
|
||||||
|
return ((JetStubElementType) astNode.getElementType()).createPsiFromAst(astNode);
|
||||||
|
}
|
||||||
|
|
||||||
return ((JetNodeType) astNode.getElementType()).createPsi(astNode);
|
return ((JetNodeType) astNode.getElementType()).createPsi(astNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
parseModifierList(MODIFIER_LIST, detector, true);
|
parseModifierList(MODIFIER_LIST, detector, true);
|
||||||
|
|
||||||
IElementType keywordToken = tt();
|
IElementType keywordToken = tt();
|
||||||
JetNodeType declType = null;
|
IElementType declType = null;
|
||||||
// if (keywordToken == PACKAGE_KEYWORD) {
|
// if (keywordToken == PACKAGE_KEYWORD) {
|
||||||
// declType = parseNamespaceBlock();
|
// declType = parseNamespaceBlock();
|
||||||
// }
|
// }
|
||||||
@@ -385,7 +385,7 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
* (classBody? | enumClassBody)
|
* (classBody? | enumClassBody)
|
||||||
* ;
|
* ;
|
||||||
*/
|
*/
|
||||||
public JetNodeType parseClass(boolean enumClass) {
|
public IElementType parseClass(boolean enumClass) {
|
||||||
assert _atSet(CLASS_KEYWORD, TRAIT_KEYWORD);
|
assert _atSet(CLASS_KEYWORD, TRAIT_KEYWORD);
|
||||||
advance(); // CLASS_KEYWORD or TRAIT_KEYWORD
|
advance(); // CLASS_KEYWORD or TRAIT_KEYWORD
|
||||||
|
|
||||||
@@ -558,7 +558,7 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
TokenDetector enumDetector = new TokenDetector(ENUM_KEYWORD);
|
TokenDetector enumDetector = new TokenDetector(ENUM_KEYWORD);
|
||||||
parseModifierList(MODIFIER_LIST, enumDetector, true);
|
parseModifierList(MODIFIER_LIST, enumDetector, true);
|
||||||
|
|
||||||
JetNodeType declType = parseMemberDeclarationRest(enumDetector.isDetected());
|
IElementType declType = parseMemberDeclarationRest(enumDetector.isDetected());
|
||||||
|
|
||||||
if (declType == null) {
|
if (declType == null) {
|
||||||
errorAndAdvance("Expecting member declaration");
|
errorAndAdvance("Expecting member declaration");
|
||||||
@@ -569,9 +569,9 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private JetNodeType parseMemberDeclarationRest(boolean isEnum) {
|
private IElementType parseMemberDeclarationRest(boolean isEnum) {
|
||||||
IElementType keywordToken = tt();
|
IElementType keywordToken = tt();
|
||||||
JetNodeType declType = null;
|
IElementType declType = null;
|
||||||
if (keywordToken == CLASS_KEYWORD) {
|
if (keywordToken == CLASS_KEYWORD) {
|
||||||
if (lookahead(1) == OBJECT_KEYWORD) {
|
if (lookahead(1) == OBJECT_KEYWORD) {
|
||||||
declType = parseClassObject();
|
declType = parseClassObject();
|
||||||
@@ -925,7 +925,7 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
* functionBody?
|
* functionBody?
|
||||||
* ;
|
* ;
|
||||||
*/
|
*/
|
||||||
public JetNodeType parseFunction() {
|
public IElementType parseFunction() {
|
||||||
assert _at(FUN_KEYWORD);
|
assert _at(FUN_KEYWORD);
|
||||||
|
|
||||||
advance(); // FUN_KEYWORD
|
advance(); // FUN_KEYWORD
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
package org.jetbrains.jet.lang.psi;
|
package org.jetbrains.jet.lang.psi;
|
||||||
|
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
|
import com.intellij.psi.StubBasedPsiElement;
|
||||||
|
import com.intellij.psi.stubs.IStubElementType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.JetNodeTypes;
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -12,11 +16,20 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @author max
|
* @author max
|
||||||
*/
|
*/
|
||||||
public class JetClass extends JetTypeParameterListOwner implements JetClassOrObject, JetModifierListOwner {
|
public class JetClass extends JetTypeParameterListOwner
|
||||||
|
implements JetClassOrObject, JetModifierListOwner, StubBasedPsiElement<PsiJetClassStub<?>> {
|
||||||
|
|
||||||
|
private PsiJetClassStub stub;
|
||||||
|
|
||||||
public JetClass(@NotNull ASTNode node) {
|
public JetClass(@NotNull ASTNode node) {
|
||||||
super(node);
|
super(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO (stubs)
|
||||||
|
// public JetClass(final PsiJetClassStub stub) {
|
||||||
|
// this.stub = stub;
|
||||||
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<JetDeclaration> getDeclarations() {
|
public List<JetDeclaration> getDeclarations() {
|
||||||
JetClassBody body = (JetClassBody) findChildByType(JetNodeTypes.CLASS_BODY);
|
JetClassBody body = (JetClassBody) findChildByType(JetNodeTypes.CLASS_BODY);
|
||||||
@@ -112,4 +125,16 @@ public class JetClass extends JetTypeParameterListOwner implements JetClassOrObj
|
|||||||
public boolean isTrait() {
|
public boolean isTrait() {
|
||||||
return findChildByType(JetTokens.TRAIT_KEYWORD) != null;
|
return findChildByType(JetTokens.TRAIT_KEYWORD) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IStubElementType getElementType() {
|
||||||
|
// TODO (stubs)
|
||||||
|
return JetStubElementTypes.CLASS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PsiJetClassStub<?> getStub() {
|
||||||
|
// TODO (stubs)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
abstract public class JetFunction extends JetTypeParameterListOwner implements JetDeclarationWithBody, JetModifierListOwner {
|
abstract public class JetFunction extends JetTypeParameterListOwner
|
||||||
|
implements JetDeclarationWithBody, JetModifierListOwner {
|
||||||
|
|
||||||
public JetFunction(@NotNull ASTNode node) {
|
public JetFunction(@NotNull ASTNode node) {
|
||||||
super(node);
|
super(node);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,17 @@ package org.jetbrains.jet.lang.psi;
|
|||||||
|
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
|
import com.intellij.psi.StubBasedPsiElement;
|
||||||
|
import com.intellij.psi.stubs.IStubElementType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author max
|
* @author max
|
||||||
*/
|
*/
|
||||||
public class JetNamedFunction extends JetFunction {
|
public class JetNamedFunction extends JetFunction implements StubBasedPsiElement<PsiJetFunctionStub<?>> {
|
||||||
public JetNamedFunction(@NotNull ASTNode node) {
|
public JetNamedFunction(@NotNull ASTNode node) {
|
||||||
super(node);
|
super(node);
|
||||||
}
|
}
|
||||||
@@ -62,4 +66,14 @@ public class JetNamedFunction extends JetFunction {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IStubElementType getElementType() {
|
||||||
|
return JetStubElementTypes.FUNCTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PsiJetFunctionStub<?> getStub() {
|
||||||
|
// TODO (stubs)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package org.jetbrains.jet.lang.psi.stubs;
|
||||||
|
|
||||||
|
import com.intellij.psi.stubs.StubElement;
|
||||||
|
import org.jetbrains.annotations.NonNls;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public interface PsiJetClassStub<T extends JetClass> extends StubElement<T> {
|
||||||
|
@NonNls
|
||||||
|
@Nullable
|
||||||
|
String getQualifiedName();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
boolean isDeprecated();
|
||||||
|
boolean hasDeprecatedAnnotation();
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.jetbrains.jet.lang.psi.stubs;
|
||||||
|
|
||||||
|
import com.intellij.psi.impl.java.stubs.StubPsiFactory;
|
||||||
|
import com.intellij.psi.stubs.PsiClassHolderFileStub;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public interface PsiJetFileStub extends PsiClassHolderFileStub<JetFile> {
|
||||||
|
String getPackageName();
|
||||||
|
|
||||||
|
StubPsiFactory getPsiFactory();
|
||||||
|
void setPsiFactory(StubPsiFactory factory);
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.jetbrains.jet.lang.psi.stubs;
|
||||||
|
|
||||||
|
import com.intellij.psi.stubs.StubElement;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFunction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public interface PsiJetFunctionStub <T extends JetFunction> extends StubElement<T> {
|
||||||
|
@Nullable
|
||||||
|
String getName();
|
||||||
|
|
||||||
|
boolean isDeclaration();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
String[] getAnnotations();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
String getReturnTypeText();
|
||||||
|
}
|
||||||
+70
@@ -0,0 +1,70 @@
|
|||||||
|
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.JetClass;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetClassStubImpl;
|
||||||
|
import org.jetbrains.jet.plugin.JetLanguage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public abstract class JetClassElementType extends JetStubElementType<PsiJetClassStub, JetClass> {
|
||||||
|
|
||||||
|
public JetClassElementType(@NotNull @NonNls String debugName) {
|
||||||
|
super(debugName, JetLanguage.INSTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PsiJetClassStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) {
|
||||||
|
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JetClass createPsi(@NotNull PsiJetClassStub stub) {
|
||||||
|
// TODO: Don't work for kotlin classes
|
||||||
|
// return getPsiFactory(stub).createClass(stub);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JetClass createPsiFromAst(@NotNull ASTNode node) {
|
||||||
|
return new JetClass(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PsiJetClassStub createStub(@NotNull JetClass psi, StubElement parentStub) {
|
||||||
|
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(PsiJetClassStub stub, StubOutputStream dataStream) throws IOException {
|
||||||
|
dataStream.writeName(stub.getName());
|
||||||
|
dataStream.writeName(stub.getQualifiedName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PsiJetClassStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
|
||||||
|
final StringRef name = dataStream.readName();
|
||||||
|
final StringRef qualifiedName = dataStream.readName();
|
||||||
|
|
||||||
|
final JetClassElementType type = JetStubElementTypes.CLASS;
|
||||||
|
final PsiJetClassStubImpl classStub = new PsiJetClassStubImpl(type, parentStub, qualifiedName, name);
|
||||||
|
|
||||||
|
return classStub;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract void indexStub(PsiJetClassStub stub, IndexSink sink);
|
||||||
|
}
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
package org.jetbrains.jet.lang.psi.stubs.elements;
|
||||||
|
|
||||||
|
import com.intellij.psi.stubs.IndexSink;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public class JetFakeStubElementFactory implements JetStubElementFactory {
|
||||||
|
@Override
|
||||||
|
public JetClassElementType getClassElementType() {
|
||||||
|
return new JetClassElementType("CLASS") {
|
||||||
|
@Override
|
||||||
|
public void indexStub(PsiJetClassStub stub, IndexSink sink) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JetFunctionElementType getFunctionElementType() {
|
||||||
|
return new JetFunctionElementType("FUN") {
|
||||||
|
@Override
|
||||||
|
public void indexStub(PsiJetFunctionStub stub, IndexSink sink) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
package org.jetbrains.jet.lang.psi.stubs.elements;
|
||||||
|
|
||||||
|
import com.intellij.lang.ASTNode;
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
import com.intellij.psi.StubBuilder;
|
||||||
|
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.psi.tree.IStubFileElementType;
|
||||||
|
import com.intellij.util.io.StringRef;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetFileStub;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetFileStubImpl;
|
||||||
|
import org.jetbrains.jet.plugin.JetLanguage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public class JetFileElementType extends IStubFileElementType<PsiJetFileStub> {
|
||||||
|
public static final int STUB_VERSION = 1;
|
||||||
|
|
||||||
|
public JetFileElementType() {
|
||||||
|
super("jet.FILE", JetLanguage.INSTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StubBuilder getBuilder() {
|
||||||
|
return new JetFileStubBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getStubVersion() {
|
||||||
|
return STUB_VERSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldBuildStubFor(final VirtualFile file) {
|
||||||
|
// TODO:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// final VirtualFile dir = file.getParent();
|
||||||
|
// return dir == null || dir.getUserData(LanguageLevel.KEY) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ASTNode createNode(final CharSequence text) {
|
||||||
|
// TODO (stub):
|
||||||
|
return super.createNode(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getExternalId() {
|
||||||
|
return "jet.FILE";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(final PsiJetFileStub stub, final StubOutputStream dataStream)
|
||||||
|
throws IOException {
|
||||||
|
dataStream.writeName(stub.getPackageName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PsiJetFileStub deserialize(final StubInputStream dataStream, final StubElement parentStub) throws IOException {
|
||||||
|
StringRef packName = dataStream.readName();
|
||||||
|
return new PsiJetFileStubImpl(null, packName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void indexStub(final PsiJetFileStub stub, final IndexSink sink) {
|
||||||
|
// Don't index file
|
||||||
|
}
|
||||||
|
}
|
||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
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.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.impl.PsiJetFileStubImpl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public class JetFileStubBuilder extends DefaultStubBuilder {
|
||||||
|
@Override
|
||||||
|
protected StubElement createStubForFile(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));
|
||||||
|
}
|
||||||
|
}
|
||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
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.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.JetFunction;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
|
||||||
|
import org.jetbrains.jet.plugin.JetLanguage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public abstract class JetFunctionElementType extends JetStubElementType<PsiJetFunctionStub, JetFunction> {
|
||||||
|
|
||||||
|
public JetFunctionElementType(@NotNull @NonNls String debugName) {
|
||||||
|
super(debugName, JetLanguage.INSTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JetFunction createPsiFromAst(@NotNull ASTNode node) {
|
||||||
|
return new JetNamedFunction(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PsiJetFunctionStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) {
|
||||||
|
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JetFunction createPsi(@NotNull PsiJetFunctionStub stub) {
|
||||||
|
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PsiJetFunctionStub createStub(@NotNull JetFunction psi, StubElement parentStub) {
|
||||||
|
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(PsiJetFunctionStub stub, StubOutputStream dataStream) throws IOException {
|
||||||
|
//To change body of implemented methods use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PsiJetFunctionStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
|
||||||
|
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package org.jetbrains.jet.lang.psi.stubs.elements;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public interface JetStubElementFactory {
|
||||||
|
JetClassElementType getClassElementType();
|
||||||
|
JetFunctionElementType getFunctionElementType();
|
||||||
|
}
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
package org.jetbrains.jet.lang.psi.stubs.elements;
|
||||||
|
|
||||||
|
import com.intellij.lang.ASTNode;
|
||||||
|
import com.intellij.lang.Language;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import com.intellij.psi.impl.java.stubs.PsiJavaFileStub;
|
||||||
|
import com.intellij.psi.impl.java.stubs.StubPsiFactory;
|
||||||
|
import com.intellij.psi.stubs.ILightStubElementType;
|
||||||
|
import com.intellij.psi.stubs.PsiFileStub;
|
||||||
|
import com.intellij.psi.stubs.StubElement;
|
||||||
|
import org.jetbrains.annotations.NonNls;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public abstract class JetStubElementType<StubT extends StubElement, PsiT extends PsiElement>
|
||||||
|
extends ILightStubElementType<StubT, PsiT> {
|
||||||
|
|
||||||
|
public JetStubElementType(@NotNull @NonNls String debugName, @Nullable Language language) {
|
||||||
|
super(debugName, language);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public abstract PsiT createPsiFromAst(@NotNull ASTNode node);
|
||||||
|
|
||||||
|
protected StubPsiFactory getPsiFactory(StubT stub) {
|
||||||
|
return getFileStub(stub).getPsiFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
private PsiJavaFileStub getFileStub(StubT stub) {
|
||||||
|
StubElement parent = stub;
|
||||||
|
while (!(parent instanceof PsiFileStub)) {
|
||||||
|
parent = parent.getParentStub();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (PsiJavaFileStub)parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getExternalId() {
|
||||||
|
return "jet." + toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package org.jetbrains.jet.lang.psi.stubs.elements;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public interface JetStubElementTypes {
|
||||||
|
JetFileElementType FILE = new JetFileElementType();
|
||||||
|
|
||||||
|
JetClassElementType CLASS = JetParserDefinition.getStubElementTypeFactory().getClassElementType();
|
||||||
|
JetFunctionElementType FUNCTION = JetParserDefinition.getStubElementTypeFactory().getFunctionElementType();
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package org.jetbrains.jet.lang.psi.stubs.impl;
|
||||||
|
|
||||||
|
import com.intellij.psi.stubs.StubBase;
|
||||||
|
import com.intellij.psi.stubs.StubElement;
|
||||||
|
import com.intellij.util.io.StringRef;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetClass;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.elements.JetClassElementType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public class PsiJetClassStubImpl extends StubBase<JetClass> implements PsiJetClassStub<JetClass> {
|
||||||
|
|
||||||
|
private final StringRef qualifiedName;
|
||||||
|
private final StringRef name;
|
||||||
|
|
||||||
|
public PsiJetClassStubImpl(
|
||||||
|
JetClassElementType type,
|
||||||
|
final StubElement parent,
|
||||||
|
final String qualifiedName,
|
||||||
|
final String name) {
|
||||||
|
|
||||||
|
this(type, parent, StringRef.fromString(qualifiedName), StringRef.fromString(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public PsiJetClassStubImpl(
|
||||||
|
JetClassElementType type,
|
||||||
|
final StubElement parent,
|
||||||
|
final StringRef qualifiedName,
|
||||||
|
final StringRef name) {
|
||||||
|
|
||||||
|
super(parent, type);
|
||||||
|
this.qualifiedName = qualifiedName;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getQualifiedName() {
|
||||||
|
return StringRef.toString(qualifiedName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDeprecated() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasDeprecatedAnnotation() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return StringRef.toString(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package org.jetbrains.jet.lang.psi.stubs.impl;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiClass;
|
||||||
|
import com.intellij.psi.impl.java.stubs.StubPsiFactory;
|
||||||
|
import com.intellij.psi.stubs.PsiFileStubImpl;
|
||||||
|
import com.intellij.util.io.StringRef;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetFileStub;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public class PsiJetFileStubImpl extends PsiFileStubImpl<JetFile> implements PsiJetFileStub {
|
||||||
|
|
||||||
|
private final StringRef packageName;
|
||||||
|
private StubPsiFactory psiFactory;
|
||||||
|
|
||||||
|
public PsiJetFileStubImpl(JetFile jetFile, StringRef packageName) {
|
||||||
|
super(jetFile);
|
||||||
|
|
||||||
|
this.packageName = packageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPackageName() {
|
||||||
|
return StringRef.toString(packageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StubPsiFactory getPsiFactory() {
|
||||||
|
return psiFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPsiFactory(StubPsiFactory factory) {
|
||||||
|
psiFactory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PsiClass[] getClasses() {
|
||||||
|
return new PsiClass[0]; //To change body of implemented methods use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
}
|
||||||
+59
@@ -0,0 +1,59 @@
|
|||||||
|
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.JetFunction;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public class PsiJetFunctionStubImpl extends StubBase<JetFunction> implements PsiJetFunctionStub<JetFunction> {
|
||||||
|
protected PsiJetFunctionStubImpl(StubElement parent, IStubElementType elementType) {
|
||||||
|
super(parent, elementType);
|
||||||
|
}
|
||||||
|
|
||||||
|
// public PsiJetFunctionStubImpl(
|
||||||
|
// Jet type,
|
||||||
|
// final StubElement parent,
|
||||||
|
// final String qualifiedName,
|
||||||
|
// final String name) {
|
||||||
|
//
|
||||||
|
// this(type, parent, StringRef.fromString(qualifiedName), StringRef.fromString(name));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public PsiJetFunctionStubImpl(
|
||||||
|
// JetClassElementType type,
|
||||||
|
// final StubElement parent,
|
||||||
|
// final StringRef qualifiedName,
|
||||||
|
// final StringRef name) {
|
||||||
|
//
|
||||||
|
// super(parent, type);
|
||||||
|
// this.qualifiedName = qualifiedName;
|
||||||
|
// this.name = name;
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDeclaration() {
|
||||||
|
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String[] getAnnotations() {
|
||||||
|
return new String[0]; //To change body of implemented methods use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getReturnTypeText() {
|
||||||
|
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.jetbrains.jet.plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures jet parser for using indexed stubs instead of default set.
|
||||||
|
* So if parser is used from IDEA it creates indexed stubs, if not direct psi elements are used.
|
||||||
|
*
|
||||||
|
* IMPORTANT: Should be called before loading parser.
|
||||||
|
*
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public class ParserConfigurator {
|
||||||
|
// static {
|
||||||
|
// JetParserDefinition.setStubFactory(new JetIndexedStubElementFactory());
|
||||||
|
// }
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package org.jetbrains.jet.plugin.stubindex;
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
|
import com.intellij.psi.stubs.StringStubIndexExtension;
|
||||||
|
import com.intellij.psi.stubs.StubIndexKey;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public class JetFullClassNameIndex extends StringStubIndexExtension<JetClassOrObject> {
|
||||||
|
|
||||||
|
private static final JetFullClassNameIndex ourInstance = new JetFullClassNameIndex();
|
||||||
|
public static JetFullClassNameIndex getInstance() {
|
||||||
|
return ourInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StubIndexKey<String, JetClassOrObject> getKey() {
|
||||||
|
return JetIndexKeys.FQN_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<JetClassOrObject> get(final String integer, final Project project, @NotNull final GlobalSearchScope scope) {
|
||||||
|
return super.get(integer, project, new JetSourceFilterScope(scope));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package org.jetbrains.jet.plugin.stubindex;
|
||||||
|
|
||||||
|
import com.intellij.psi.stubs.StubIndexKey;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFunction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public interface JetIndexKeys {
|
||||||
|
StubIndexKey<String, JetClassOrObject> SHORT_NAME_KEY = StubIndexKey.createIndexKey("jet.class.shortName");
|
||||||
|
StubIndexKey<String, JetClassOrObject> FQN_KEY = StubIndexKey.createIndexKey("jet.fqn");
|
||||||
|
|
||||||
|
StubIndexKey<String, JetFunction> TOP_LEVEL_FUNCTION_SHORT_NAME_KEY = StubIndexKey.createIndexKey("jet.top.level.function.short.name");
|
||||||
|
// StubIndexKey<String, JetFunction> TOP_LEVEL_FUNCTION_FQN_KEY = StubIndexKey.createIndexKey("jet.top.level.function.short.name");
|
||||||
|
|
||||||
|
// StubIndexKey<String, JetObjectDeclaration> PACKAGE_OBJECT_KEY = StubIndexKey.createIndexKey("jet.package.object.fqn");
|
||||||
|
// StubIndexKey<String, JetFunction> EXTENSION_FUNCTION_TO_TYPE_FQN = StubIndexKey.createIndexKey("jet.extension.function.to.type.fqn");
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package org.jetbrains.jet.plugin.stubindex;
|
||||||
|
|
||||||
|
import com.intellij.psi.stubs.IndexSink;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.PsiJetFunctionStub;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.elements.JetClassElementType;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.elements.JetFunctionElementType;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public class JetIndexedStubElementFactory implements JetStubElementFactory {
|
||||||
|
@Override
|
||||||
|
public JetClassElementType getClassElementType() {
|
||||||
|
return new JetClassElementType("CLASS") {
|
||||||
|
@Override
|
||||||
|
public void indexStub(PsiJetClassStub stub, IndexSink sink) {
|
||||||
|
String name = stub.getName();
|
||||||
|
if (name != null) {
|
||||||
|
sink.occurrence(JetIndexKeys.SHORT_NAME_KEY, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JetFunctionElementType getFunctionElementType() {
|
||||||
|
return new JetFunctionElementType("FUN") {
|
||||||
|
@Override
|
||||||
|
public void indexStub(PsiJetFunctionStub stub, IndexSink sink) {
|
||||||
|
String name = stub.getName();
|
||||||
|
// TODO: Check that function defined in top level
|
||||||
|
if (name != null) {
|
||||||
|
sink.occurrence(JetIndexKeys.TOP_LEVEL_FUNCTION_SHORT_NAME_KEY, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package org.jetbrains.jet.plugin.stubindex;
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
|
import com.intellij.psi.stubs.StringStubIndexExtension;
|
||||||
|
import com.intellij.psi.stubs.StubIndexKey;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public class JetShortClassNameIndex extends StringStubIndexExtension<JetClassOrObject> {
|
||||||
|
private static final JetShortClassNameIndex ourInstance = new JetShortClassNameIndex();
|
||||||
|
public static JetShortClassNameIndex getInstance() {
|
||||||
|
return ourInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StubIndexKey<String, JetClassOrObject> getKey() {
|
||||||
|
return JetIndexKeys.SHORT_NAME_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<JetClassOrObject> get(final String s, final Project project, @NotNull final GlobalSearchScope scope) {
|
||||||
|
return super.get(s, project, new JetSourceFilterScope(scope));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package org.jetbrains.jet.plugin.stubindex;
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
|
import com.intellij.psi.stubs.StringStubIndexExtension;
|
||||||
|
import com.intellij.psi.stubs.StubIndexKey;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFunction;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public class JetShortFunctionNameIndex extends StringStubIndexExtension<JetFunction> {
|
||||||
|
private static final JetShortClassNameIndex ourInstance = new JetShortClassNameIndex();
|
||||||
|
|
||||||
|
public static JetShortClassNameIndex getInstance() {
|
||||||
|
return ourInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StubIndexKey<String, JetFunction> getKey() {
|
||||||
|
return JetIndexKeys.TOP_LEVEL_FUNCTION_SHORT_NAME_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<JetFunction> get(final String s, final Project project, @NotNull final GlobalSearchScope scope) {
|
||||||
|
return super.get(s, project, new JetSourceFilterScope(scope));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package org.jetbrains.jet.plugin.stubindex;
|
||||||
|
|
||||||
|
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||||
|
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||||
|
import com.intellij.openapi.roots.ProjectRootManager;
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
import com.intellij.psi.search.DelegatingGlobalSearchScope;
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Nikolay Krasko
|
||||||
|
*/
|
||||||
|
public class JetSourceFilterScope extends DelegatingGlobalSearchScope {
|
||||||
|
private final ProjectFileIndex myIndex;
|
||||||
|
|
||||||
|
public JetSourceFilterScope(@NotNull final GlobalSearchScope delegate) {
|
||||||
|
super(delegate);
|
||||||
|
myIndex = ProjectRootManager.getInstance(getProject()).getFileIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean contains(final VirtualFile file) {
|
||||||
|
if (!super.contains(file)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StdFileTypes.CLASS == file.getFileType()) {
|
||||||
|
return myIndex.isInLibraryClasses(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
return myIndex.isInSourceContent(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user