Standalone parsing using PsiParser

I'm writing a test case for my PsiParser implementation:

MyLanguage language = new MyLanguage();
PsiBuilder builder = new PsiBuilderImpl(language, null, null, EXPR1);
PsiParser psiParser = language.getParserDefinition().createParser(null);
psiParser.parse(OgnlElementTypes.EXPRESSION, builder);
ASTNode tree = builder.getTreeBuilt();

Parse test passes, but the ParserDefinition.createElement() haven't called so the tree node type is com.intellij.psi.impl.source.tree.CompositeElement, not my custom nodes.

Can I test the PsiParser without plugin (passing null for project parameters)?
Can I use the null value for CharTable parameter in the PsiBuilderImpl constructor?
How to test the PsiParser without PsiBuilderImpl instance creation? Maybe, some shortcut like myLanguge.parse(expr) exists.

Additional details: the MyLanguage class overrrides the getParserDefinition() method, the ParserDefinition class creates lexer, parser and custom node types.

Please sign in to leave a comment.