// Path: src/main/java/com/github/setial/intellijjavadocs/exception/FileNotValidException.java
// public class FileNotValidException extends RuntimeException {
// 
//     /**
//      * Instantiates a new File not valid exception.
//      *
//      * @param message the message
//      */
//     public FileNotValidException(String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/com/github/setial/intellijjavadocs/exception/NotFoundElementException.java
// public class NotFoundElementException extends RuntimeException {
// 
//     /**
//      * Instantiates a new Not found element exception.
//      *
//      * @param message the message
//      */
//     public NotFoundElementException(String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/com/github/setial/intellijjavadocs/operation/JavaDocWriter.java
// public interface JavaDocWriter {
// 
//     /**
//      * Write java doc.
//      *
//      * @param javaDoc       the Java doc
//      * @param beforeElement the element to place javadoc before it
//      */
//     void write(@NotNull PsiDocComment javaDoc, @NotNull PsiElement beforeElement);
// 
//     /**
//      * Remove void.
//      *
//      * @param beforeElement the before element
//      */
//     void remove(@NotNull PsiElement beforeElement);
// 
// }
// 
// Path: src/main/java/com/github/setial/intellijjavadocs/configuration/impl/JavaDocConfigurationImpl.java
// public static final String JAVADOCS_PLUGIN_TITLE_MSG = "Javadocs plugin";


import com.github.setial.intellijjavadocs.exception.FileNotValidException;
import com.github.setial.intellijjavadocs.exception.NotFoundElementException;
import com.github.setial.intellijjavadocs.operation.JavaDocWriter;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
import com.intellij.openapi.vfs.ReadonlyStatusHandler.OperationStatus;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.util.ThrowableRunnable;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import static com.github.setial.intellijjavadocs.configuration.impl.JavaDocConfigurationImpl.JAVADOCS_PLUGIN_TITLE_MSG;
        @Override
        public void run() throws RuntimeException {
            if (element.getFirstChild() instanceof PsiDocComment) {
                deleteJavaDoc(this.element);
            }
        }
    }

    private static void deleteJavaDoc(PsiElement theElement) {
        pushPostponedChanges(theElement);
        theElement.getFirstChild().delete();
    }

    private static void addJavaDoc(PsiElement theElement, PsiDocComment theJavaDoc) {
        pushPostponedChanges(theElement);
        theElement.getNode().addChild(theJavaDoc.getNode(), theElement.getFirstChild().getNode());
    }

    private static void replaceJavaDoc(PsiElement theElement, PsiDocComment theJavaDoc) {
        deleteJavaDoc(theElement);
        addJavaDoc(theElement, theJavaDoc);
    }

    private static void reformatJavaDoc(PsiElement theElement) {
        CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(theElement.getProject());
        pushPostponedChanges(theElement);
        try {
            int javadocTextOffset = findJavaDocTextOffset(theElement);
            int javaCodeTextOffset = findJavaCodeTextOffset(theElement);
            codeStyleManager.reformatText(theElement.getContainingFile(), javadocTextOffset, javaCodeTextOffset + 1);
// Path: src/main/java/com/github/setial/intellijjavadocs/exception/FileNotValidException.java
// public class FileNotValidException extends RuntimeException {
// 
//     /**
//      * Instantiates a new File not valid exception.
//      *
//      * @param message the message
//      */
//     public FileNotValidException(String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/com/github/setial/intellijjavadocs/exception/NotFoundElementException.java
// public class NotFoundElementException extends RuntimeException {
// 
//     /**
//      * Instantiates a new Not found element exception.
//      *
//      * @param message the message
//      */
//     public NotFoundElementException(String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/com/github/setial/intellijjavadocs/operation/JavaDocWriter.java
// public interface JavaDocWriter {
// 
//     /**
//      * Write java doc.
//      *
//      * @param javaDoc       the Java doc
//      * @param beforeElement the element to place javadoc before it
//      */
//     void write(@NotNull PsiDocComment javaDoc, @NotNull PsiElement beforeElement);
// 
//     /**
//      * Remove void.
//      *
//      * @param beforeElement the before element
//      */
//     void remove(@NotNull PsiElement beforeElement);
// 
// }
// 
// Path: src/main/java/com/github/setial/intellijjavadocs/configuration/impl/JavaDocConfigurationImpl.java
// public static final String JAVADOCS_PLUGIN_TITLE_MSG = "Javadocs plugin";


// Path: src/main/java/com/github/setial/intellijjavadocs/operation/impl/JavaDocWriterImpl.java
import com.github.setial.intellijjavadocs.exception.FileNotValidException;
import com.github.setial.intellijjavadocs.exception.NotFoundElementException;
import com.github.setial.intellijjavadocs.operation.JavaDocWriter;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
import com.intellij.openapi.vfs.ReadonlyStatusHandler.OperationStatus;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.codeStyle.CodeStyleManager;
import com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.util.ThrowableRunnable;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import static com.github.setial.intellijjavadocs.configuration.impl.JavaDocConfigurationImpl.JAVADOCS_PLUGIN_TITLE_MSG;

        @Override
        public void run() throws RuntimeException {
            if (element.getFirstChild() instanceof PsiDocComment) {
                deleteJavaDoc(this.element);
            }
        }
    }

    private static void deleteJavaDoc(PsiElement theElement) {
        pushPostponedChanges(theElement);
        theElement.getFirstChild().delete();
    }

    private static void addJavaDoc(PsiElement theElement, PsiDocComment theJavaDoc) {
        pushPostponedChanges(theElement);
        theElement.getNode().addChild(theJavaDoc.getNode(), theElement.getFirstChild().getNode());
    }

    private static void replaceJavaDoc(PsiElement theElement, PsiDocComment theJavaDoc) {
        deleteJavaDoc(theElement);
        addJavaDoc(theElement, theJavaDoc);
    }

    private static void reformatJavaDoc(PsiElement theElement) {
        CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(theElement.getProject());
        pushPostponedChanges(theElement);
        try {
            int javadocTextOffset = findJavaDocTextOffset(theElement);
            int javaCodeTextOffset = findJavaCodeTextOffset(theElement);
            codeStyleManager.reformatText(theElement.getContainingFile(), javadocTextOffset, javaCodeTextOffset + 1);
        } catch (NotFoundElementException e) {