// Path: src/main/java/com/kalessil/phpStorm/yii2inspections/utils/TranslationCallsProcessUtil.java
// final public class TranslationCallsProcessUtil {
// 
//     /* Returns null if category is not clean or empty string literal or no reasonable messages were found*/
//     @Nullable
//     static public ProcessingResult process(@NotNull MethodReference reference, boolean resolve) {
//         final String name         = reference.getName();
//         final PsiElement[] params = reference.getParameters();
//         if (null == name || params.length < 2 || (!name.equals("t") && !(name.equals("registerTranslations")))) {
//             return null;
//         }
// 
//         /* category needs to be resolved and without any injections */
//         final StringLiteralExpression categoryLiteral = StringLiteralExtractUtil.resolveAsStringLiteral(params[0], resolve);
//         if (null == categoryLiteral || null != categoryLiteral.getFirstPsiChild() || categoryLiteral.getTextLength() <= 2) {
//             return null;
//         }
// 
//         final Map<StringLiteralExpression, PsiElement> messages = new HashMap<>();
//         if (name.equals("t")) {
//             /* 2nd argument expected to be a string literal (possible with injections) */
//             final StringLiteralExpression messageLiteral = StringLiteralExtractUtil.resolveAsStringLiteral(params[1], resolve);
//             if (null != messageLiteral && messageLiteral.getTextLength() > 2) {
//                 messages.put(messageLiteral, params[1]);
//             }
//         }
// 
//         if (name.equals("registerTranslations") && params[1] instanceof ArrayCreationExpression) {
//             /* 2nd argument expected to be an inline array with string literal (possible with injections) */
//             for (PsiElement child : params[1].getChildren()) {
//                 final PsiElement literalCandidate            = child.getFirstChild();
//                 final StringLiteralExpression messageLiteral = StringLiteralExtractUtil.resolveAsStringLiteral(literalCandidate, resolve);
//                 if (null != messageLiteral && messageLiteral.getTextLength() > 2) {
//                     messages.put(messageLiteral, literalCandidate);
//                 }
//             }
//         }
// 
//         return 0 == messages.size() ? null : new ProcessingResult(categoryLiteral, messages);
//     }
// 
//     static public class ProcessingResult {
//         @Nullable
//         private StringLiteralExpression category;
//         @Nullable
//         private Map<StringLiteralExpression, PsiElement> messages;
// 
//         ProcessingResult(@NotNull StringLiteralExpression category, @NotNull Map<StringLiteralExpression, PsiElement> messages) {
//             this.category = category;
//             this.messages = messages;
//         }
// 
//         @NotNull
//         public StringLiteralExpression getCategory() {
//             if (null == this.category) {
//                 throw new RuntimeException("The object has been disposed already");
//             }
// 
//             return this.category;
//         }
// 
//         @NotNull
//         public Map<StringLiteralExpression, PsiElement> getMessages() {
//             if (null == this.messages) {
//                 throw new RuntimeException("The object has been disposed already");
//             }
// 
//             return this.messages;
//         }
// 
//         public void dispose() {
//             if (null != this.messages) {
//                 this.messages.clear();
//             }
// 
//             this.category = null;
//             this.messages = null;
//         }
//     }
// }


import com.intellij.openapi.project.Project;
import com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase;
import com.jetbrains.php.lang.psi.PhpPsiElementFactory;
import com.jetbrains.php.lang.psi.elements.MethodReference;
import com.kalessil.phpStorm.yii2inspections.utils.TranslationCallsProcessUtil;
import java.util.HashMap;
import java.util.Map;
package com.kalessil.phpStorm.yii2inspections.inspectors;



public class TranslationCallsProcessUtilTest extends CodeInsightFixtureTestCase {
    public void testSingleMessageExtraction() {
        Project project = myFixture.getProject();

        Map<String, Integer> patterns = new HashMap<>();
        patterns.put("Yii::t('yii', \"$x\")", 1);
        patterns.put("Yii::t('yii', 'message')", 1);
        patterns.put("Yii::t('yii', \"message\")", 1);
        patterns.put("$view->registerTranslations('craft', ['message', 'message']);", 2);

        for (String pattern : patterns.keySet()) {
            MethodReference call = PhpPsiElementFactory.createFromText(project, MethodReference.class, pattern);
            assertNotNull(pattern + ": incorrect pattern", call);

// Path: src/main/java/com/kalessil/phpStorm/yii2inspections/utils/TranslationCallsProcessUtil.java
// final public class TranslationCallsProcessUtil {
// 
//     /* Returns null if category is not clean or empty string literal or no reasonable messages were found*/
//     @Nullable
//     static public ProcessingResult process(@NotNull MethodReference reference, boolean resolve) {
//         final String name         = reference.getName();
//         final PsiElement[] params = reference.getParameters();
//         if (null == name || params.length < 2 || (!name.equals("t") && !(name.equals("registerTranslations")))) {
//             return null;
//         }
// 
//         /* category needs to be resolved and without any injections */
//         final StringLiteralExpression categoryLiteral = StringLiteralExtractUtil.resolveAsStringLiteral(params[0], resolve);
//         if (null == categoryLiteral || null != categoryLiteral.getFirstPsiChild() || categoryLiteral.getTextLength() <= 2) {
//             return null;
//         }
// 
//         final Map<StringLiteralExpression, PsiElement> messages = new HashMap<>();
//         if (name.equals("t")) {
//             /* 2nd argument expected to be a string literal (possible with injections) */
//             final StringLiteralExpression messageLiteral = StringLiteralExtractUtil.resolveAsStringLiteral(params[1], resolve);
//             if (null != messageLiteral && messageLiteral.getTextLength() > 2) {
//                 messages.put(messageLiteral, params[1]);
//             }
//         }
// 
//         if (name.equals("registerTranslations") && params[1] instanceof ArrayCreationExpression) {
//             /* 2nd argument expected to be an inline array with string literal (possible with injections) */
//             for (PsiElement child : params[1].getChildren()) {
//                 final PsiElement literalCandidate            = child.getFirstChild();
//                 final StringLiteralExpression messageLiteral = StringLiteralExtractUtil.resolveAsStringLiteral(literalCandidate, resolve);
//                 if (null != messageLiteral && messageLiteral.getTextLength() > 2) {
//                     messages.put(messageLiteral, literalCandidate);
//                 }
//             }
//         }
// 
//         return 0 == messages.size() ? null : new ProcessingResult(categoryLiteral, messages);
//     }
// 
//     static public class ProcessingResult {
//         @Nullable
//         private StringLiteralExpression category;
//         @Nullable
//         private Map<StringLiteralExpression, PsiElement> messages;
// 
//         ProcessingResult(@NotNull StringLiteralExpression category, @NotNull Map<StringLiteralExpression, PsiElement> messages) {
//             this.category = category;
//             this.messages = messages;
//         }
// 
//         @NotNull
//         public StringLiteralExpression getCategory() {
//             if (null == this.category) {
//                 throw new RuntimeException("The object has been disposed already");
//             }
// 
//             return this.category;
//         }
// 
//         @NotNull
//         public Map<StringLiteralExpression, PsiElement> getMessages() {
//             if (null == this.messages) {
//                 throw new RuntimeException("The object has been disposed already");
//             }
// 
//             return this.messages;
//         }
// 
//         public void dispose() {
//             if (null != this.messages) {
//                 this.messages.clear();
//             }
// 
//             this.category = null;
//             this.messages = null;
//         }
//     }
// }


// Path: src/test/java/com/kalessil/phpStorm/yii2inspections/inspectors/TranslationCallsProcessUtilTest.java
import com.intellij.openapi.project.Project;
import com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase;
import com.jetbrains.php.lang.psi.PhpPsiElementFactory;
import com.jetbrains.php.lang.psi.elements.MethodReference;
import com.kalessil.phpStorm.yii2inspections.utils.TranslationCallsProcessUtil;
import java.util.HashMap;
import java.util.Map;

package com.kalessil.phpStorm.yii2inspections.inspectors;



public class TranslationCallsProcessUtilTest extends CodeInsightFixtureTestCase {
    public void testSingleMessageExtraction() {
        Project project = myFixture.getProject();

        Map<String, Integer> patterns = new HashMap<>();
        patterns.put("Yii::t('yii', \"$x\")", 1);
        patterns.put("Yii::t('yii', 'message')", 1);
        patterns.put("Yii::t('yii', \"message\")", 1);
        patterns.put("$view->registerTranslations('craft', ['message', 'message']);", 2);

        for (String pattern : patterns.keySet()) {
            MethodReference call = PhpPsiElementFactory.createFromText(project, MethodReference.class, pattern);
            assertNotNull(pattern + ": incorrect pattern", call);

            TranslationCallsProcessUtil.ProcessingResult messages = TranslationCallsProcessUtil.process(call, false);