IDE Internal Error occured.

Hi all,
I am trying to insert a code after a method. When I execute my code it gets inserted in the correct position but also at the end of my program it is getting added one more time.
This is my first project and I am stuck in clearing this bug for the past 3 days. Any solution for this will be helpful to me and Thanks in advance.

This is my code for adding:

//If matched I am adding it to the corresponding position:
private void generateNexpayHelper(PsiClass psiClass, PsiElement psiElement) {
StringBuilder builder = new StringBuilder("if (BILLING_STORE == \"NEXVA\") { \n");
builder.append("NexvaHelper = new NexvaXPayHelper (this, this);\n");
builder.append("NexvaHelper.startSetup();\n } \n");
PsiElement nexvaHelperElement = JavaPsiFacade.getElementFactory(psiClass.getProject()).createStatementFromText(builder.toString(), psiClass);
PsiElement method=psiClass.add(nexvaHelperElement);
psiClass.addAfter(nexvaHelperElement, psiElement.getParent().getParent().getContext());


//Inserting at correct position:

mHelper = new IabHelper (this,base64EncodedPublicKey);
NexvaHelper = new NexvaXPayHelper(this, this);

//Inserting at the end of program:

//End of program
NexvaHelper = new NexvaXPayHelper(this, this);

One Error:
Throwable: Assertion failed: anchorBefore == null || anchorBefore.getTreeParent() == parent

1 comment
Comment actions Permalink

What do you mean "insert code after method"? In Java there must be no code after a method, all the code should be inside them.


>PsiElement method=psiClass.add(nexvaHelperElement);

This means add nexvaHelperElement inside psiClass (it makes no sense - there must be no statements inside class, there can be methods,fields or initializers only)

>psiClass.addAfter(nexvaHelperElement, psiElement.getParent().getParent().getContext());

This means add nexvaHelperElement inside psiClass after the "psiElement.getParent().getParent().getContext()" (it makes no sense - psiElement.getParent().getParent().getContext() is not inside class)



Please sign in to leave a comment.