// Path: src/com/github/letsdrink/intellijplugin/PsiUtils.java
// public class PsiUtils {
//     public static String getContent(PsiElement value) {
//         if (value instanceof StringLiteralExpression) {
//             return ((StringLiteralExpression) value).getContents();
//         }
//         if (value instanceof PhpExpressionImpl && ((PhpExpressionImpl) value).getType().equals(PhpType.INT)) {
//             return value.getText();
//         }
// 
//         if (value instanceof ConstantReference || value instanceof ClassConstantReference) {
//             return value.getText(); //we cannot resolve constant value when this method is called from index because indices are not accessible then.
//         }
//         return null;
//     }
// 
//     public static boolean isElementTheFirstParameterInFunctionCall(PsiElement psiElement, String functionName) {
//         if (!(psiElement.getContext() instanceof ParameterList)) {
//             return false;
//         }
// 
//         ParameterList parameterList = (ParameterList) psiElement.getContext();
// 
//         if (parameterList == null || !(parameterList.getContext() instanceof FunctionReference)) {
//             return false;
//         }
// 
//         FunctionReference function = (FunctionReference) parameterList.getContext();
// 
//         if (function.getName().equals(functionName) && function.getParameters()[0].equals(psiElement)) {
//             return true;
//         }
//         return false;
//     }
// 
//     public static boolean isElementTheFirstParameterInMethodCall(PsiElement psiElement, String methodFQN) {
//         if (!(psiElement.getContext() instanceof ParameterList)) {
//             return false;
//         }
// 
//         ParameterList parameterList = (ParameterList) psiElement.getContext();
// 
//         if (parameterList == null || !(parameterList.getContext() instanceof MethodReference)) {
//             return false;
//         }
// 
//         MethodReference methodReference = (MethodReference) parameterList.getContext();
//         if (!methodReference.getParameters()[0].equals(psiElement)) {
//             return false;
//         }
// 
//         return isMethodCallTo(methodReference, methodFQN);
//     }
// 
//     public static boolean isElementTheNthParameterInMethodCall(PsiElement psiElement, String methodFQN, int n) {
//         if (!(psiElement.getContext() instanceof ParameterList)) {
//             return false;
//         }
//         ParameterList parameterList = (ParameterList) psiElement.getContext();
//         MethodReference methodReference = (MethodReference) parameterList.getContext();
//         PsiElement[] parameters = methodReference.getParameters();
//         if (parameters.length > n && !parameters[n].equals(psiElement)) {
//             return false;
//         }
//         return isMethodCallTo(methodReference, methodFQN);
//     }
// 
//     public static Method resolveMethod(MethodReference methodReference) {
//         PsiReference psiReference = methodReference.getReference();
//         if (psiReference == null) {
//             return null;
//         }
// 
//         PsiElement resolvedReference = psiReference.resolve();
//         if (!(resolvedReference instanceof Method)) {
//             return null;
//         }
//         return (Method) resolvedReference;
//     }
// 
//     public static boolean isMethodCallTo(MethodReference methodReference, String name) {
//         Method currentMethod = resolveMethod(methodReference);
//         if (currentMethod == null) {
//             return false;
//         }
//         return currentMethod.getFQN().equals(name);
//     }
// 
//     public static PsiElement getCurrentElement(Editor editor, PsiFile psiFile) {
//         if (psiFile == null || editor == null)
//             return null;
//         int offset = editor.getCaretModel().getOffset();
//         PsiElement psiElement = psiFile.findElementAt(offset);
// 
//         return psiElement;
//     }
// 
//     public static String getContainingFilename(PsiElement psiElement) {
//         return psiElement.getContainingFile().getName();
//     }
// 
//     public static void deleteArrayElement(PsiElement element) {
//         IElementType type;
//         do {
//             PsiElement nextSibling = element.getNextSibling();
//             element.delete();
//             element = nextSibling;
//             type = element.getNode().getElementType();
//         } while (element.isValid() && (type == PhpElementTypes.WHITE_SPACE || type == PhpTokenTypes.opCOMMA));
//     }
// 
//     public static boolean isInstanceOf(PhpClass aClass, String baseClassFQN) {
//         PhpClass baseClass = aClass.getSuperClass();
//         while (baseClass != null) {
//             if (baseClassFQN.equals(baseClass.getFQN())) {
//                 return true;
//             }
//             baseClass = baseClass.getSuperClass();
//         }
//         return false;
//     }
// 
//     public static Set<String> getKeys(ArrayCreationExpression arrayCreation) {
//         Set<String> keys = newHashSet();
//         ArrayHashElement[] hashElements = PsiTreeUtil.getChildrenOfType(arrayCreation, ArrayHashElement.class);
//         if (hashElements == null) {
//             return keys;
//         }
//         for (ArrayHashElement hashElement : hashElements) {
//             keys.add(PsiUtils.getContent(hashElement.getKey()));
//         }
//         return keys;
//     }
// }


import com.github.letsdrink.intellijplugin.PsiUtils;
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import java.util.List;

    @Override
    public void invoke(@NotNull Project project, final Editor editor, @NotNull final PsiElement psiElement) throws IncorrectOperationException {
        final String key = TranslationHashElement.newInstance(psiElement).getFullKey();

        final List<PsiElement> elementsToRemove = TranslationRemoveUtils.getElementToRemove(project, key);

        PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
        new WriteCommandAction(project) {
            @Override
            protected void run(Result result) throws Throwable {
                for (PsiElement element : elementsToRemove) {
                    PsiUtils.deleteArrayElement(element);
                }
            }

            @Override
            public String getGroupID() {
                return "Remove Translation";
            }
        }.execute();
    }

    @NotNull
    @Override
    public String getText() {
        return "Remove translations";
    }

    @Override
// Path: src/com/github/letsdrink/intellijplugin/PsiUtils.java
// public class PsiUtils {
//     public static String getContent(PsiElement value) {
//         if (value instanceof StringLiteralExpression) {
//             return ((StringLiteralExpression) value).getContents();
//         }
//         if (value instanceof PhpExpressionImpl && ((PhpExpressionImpl) value).getType().equals(PhpType.INT)) {
//             return value.getText();
//         }
// 
//         if (value instanceof ConstantReference || value instanceof ClassConstantReference) {
//             return value.getText(); //we cannot resolve constant value when this method is called from index because indices are not accessible then.
//         }
//         return null;
//     }
// 
//     public static boolean isElementTheFirstParameterInFunctionCall(PsiElement psiElement, String functionName) {
//         if (!(psiElement.getContext() instanceof ParameterList)) {
//             return false;
//         }
// 
//         ParameterList parameterList = (ParameterList) psiElement.getContext();
// 
//         if (parameterList == null || !(parameterList.getContext() instanceof FunctionReference)) {
//             return false;
//         }
// 
//         FunctionReference function = (FunctionReference) parameterList.getContext();
// 
//         if (function.getName().equals(functionName) && function.getParameters()[0].equals(psiElement)) {
//             return true;
//         }
//         return false;
//     }
// 
//     public static boolean isElementTheFirstParameterInMethodCall(PsiElement psiElement, String methodFQN) {
//         if (!(psiElement.getContext() instanceof ParameterList)) {
//             return false;
//         }
// 
//         ParameterList parameterList = (ParameterList) psiElement.getContext();
// 
//         if (parameterList == null || !(parameterList.getContext() instanceof MethodReference)) {
//             return false;
//         }
// 
//         MethodReference methodReference = (MethodReference) parameterList.getContext();
//         if (!methodReference.getParameters()[0].equals(psiElement)) {
//             return false;
//         }
// 
//         return isMethodCallTo(methodReference, methodFQN);
//     }
// 
//     public static boolean isElementTheNthParameterInMethodCall(PsiElement psiElement, String methodFQN, int n) {
//         if (!(psiElement.getContext() instanceof ParameterList)) {
//             return false;
//         }
//         ParameterList parameterList = (ParameterList) psiElement.getContext();
//         MethodReference methodReference = (MethodReference) parameterList.getContext();
//         PsiElement[] parameters = methodReference.getParameters();
//         if (parameters.length > n && !parameters[n].equals(psiElement)) {
//             return false;
//         }
//         return isMethodCallTo(methodReference, methodFQN);
//     }
// 
//     public static Method resolveMethod(MethodReference methodReference) {
//         PsiReference psiReference = methodReference.getReference();
//         if (psiReference == null) {
//             return null;
//         }
// 
//         PsiElement resolvedReference = psiReference.resolve();
//         if (!(resolvedReference instanceof Method)) {
//             return null;
//         }
//         return (Method) resolvedReference;
//     }
// 
//     public static boolean isMethodCallTo(MethodReference methodReference, String name) {
//         Method currentMethod = resolveMethod(methodReference);
//         if (currentMethod == null) {
//             return false;
//         }
//         return currentMethod.getFQN().equals(name);
//     }
// 
//     public static PsiElement getCurrentElement(Editor editor, PsiFile psiFile) {
//         if (psiFile == null || editor == null)
//             return null;
//         int offset = editor.getCaretModel().getOffset();
//         PsiElement psiElement = psiFile.findElementAt(offset);
// 
//         return psiElement;
//     }
// 
//     public static String getContainingFilename(PsiElement psiElement) {
//         return psiElement.getContainingFile().getName();
//     }
// 
//     public static void deleteArrayElement(PsiElement element) {
//         IElementType type;
//         do {
//             PsiElement nextSibling = element.getNextSibling();
//             element.delete();
//             element = nextSibling;
//             type = element.getNode().getElementType();
//         } while (element.isValid() && (type == PhpElementTypes.WHITE_SPACE || type == PhpTokenTypes.opCOMMA));
//     }
// 
//     public static boolean isInstanceOf(PhpClass aClass, String baseClassFQN) {
//         PhpClass baseClass = aClass.getSuperClass();
//         while (baseClass != null) {
//             if (baseClassFQN.equals(baseClass.getFQN())) {
//                 return true;
//             }
//             baseClass = baseClass.getSuperClass();
//         }
//         return false;
//     }
// 
//     public static Set<String> getKeys(ArrayCreationExpression arrayCreation) {
//         Set<String> keys = newHashSet();
//         ArrayHashElement[] hashElements = PsiTreeUtil.getChildrenOfType(arrayCreation, ArrayHashElement.class);
//         if (hashElements == null) {
//             return keys;
//         }
//         for (ArrayHashElement hashElement : hashElements) {
//             keys.add(PsiUtils.getContent(hashElement.getKey()));
//         }
//         return keys;
//     }
// }


// Path: src/com/github/letsdrink/intellijplugin/translation/RemoveTranslationIntentionAction.java
import com.github.letsdrink.intellijplugin.PsiUtils;
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import java.util.List;


    @Override
    public void invoke(@NotNull Project project, final Editor editor, @NotNull final PsiElement psiElement) throws IncorrectOperationException {
        final String key = TranslationHashElement.newInstance(psiElement).getFullKey();

        final List<PsiElement> elementsToRemove = TranslationRemoveUtils.getElementToRemove(project, key);

        PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument());
        new WriteCommandAction(project) {
            @Override
            protected void run(Result result) throws Throwable {
                for (PsiElement element : elementsToRemove) {
                    PsiUtils.deleteArrayElement(element);
                }
            }

            @Override
            public String getGroupID() {
                return "Remove Translation";
            }
        }.execute();
    }

    @NotNull
    @Override
    public String getText() {
        return "Remove translations";
    }

    @Override
    public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {