Change PSI Element in standalone YAML parser

Hello,

I am trying to  add one additional element to YAMLPsiFile using yaml plugin and light-psi-all.jar generated from grammar-kit from standalone java application:

private static void lightParsing() throws IOException
{
ExtensionsArea extensionsArea = Extensions.getRootArea();
CoreApplicationEnvironment.registerExtensionPoint(extensionsArea,TreeCopyHandler.EP_NAME,TreeCopyHandler.class);
YAMLParserDefinition yamlParserDefinition = new YAMLParserDefinition();
File file = new File(sourceFile);
YAMLFile psiFile = (YAMLFile)LightPsi.parseFile(file, yamlParserDefinition);
psiFile.getFirstChild().add(psiFile.getFirstChild().copy());
System.out.println(psiFile.getText());
}

It's parsed OK, but on the add method I get this:

Exception in thread "main" java.lang.IllegalStateException: @NotNull method com/intellij/pom/PomManager.getModel must not return null
    at com.intellij.pom.PomManager.getModel(PomManager.java:32)
    at com.intellij.psi.impl.source.tree.ChangeUtil.prepareAndRunChangeAction(ChangeUtil.java:165)
    at com.intellij.psi.impl.source.tree.CompositeElement.removeChildrenInner(CompositeElement.java:911)
    at com.intellij.psi.impl.source.tree.CompositeElement.addChild(CompositeElement.java:644)
    at com.intellij.psi.impl.source.tree.CompositeElement.addChildren(CompositeElement.java:753)
    at com.intellij.psi.impl.source.codeStyle.CodeEditUtil.addChildren(CodeEditUtil.java:71)
    at com.intellij.extapi.psi.ASTDelegatePsiElement.addInternal(ASTDelegatePsiElement.java:309)
    at com.intellij.extapi.psi.ASTDelegatePsiElement.addInnerBefore(ASTDelegatePsiElement.java:282)
    at com.intellij.extapi.psi.ASTDelegatePsiElement.add(ASTDelegatePsiElement.java:271)
    at com.netcracker.tosca.parser.yaml.Main.lightParsing(Main.java:49)
    at com.netcracker.tosca.parser.yaml.Main.main(Main.java:38)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:143)

Process finished with exit code 1

What's wrong?

Please sign in to leave a comment.