package com.cedricziel.idea.typo3.tca.codeInsight;

import com.cedricziel.idea.typo3.psi.PhpElementsUtil;
import com.cedricziel.idea.typo3.util.TableUtil;
import com.intellij.codeInsight.completion.*;
import com.intellij.psi.PsiElement;
import com.intellij.util.ProcessingContext;
import com.jetbrains.php.lang.psi.elements.ArrayHashElement;
import com.jetbrains.php.lang.psi.elements.PhpPsiElement;
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;

import static com.cedricziel.idea.typo3.util.TableUtil.TCA_TABLE_FIELDS;

public class TCACompletionContributor extends CompletionContributor {

    public TCACompletionContributor() {
        /*
         * Complete table names in array values.
         */
        extend(
                CompletionType.BASIC,
                PhpElementsUtil.isStringArrayValue(),
                new CompletionProvider<CompletionParameters>() {
                    @Override
                    protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
                        PsiElement position = parameters.getPosition();

                        // ArrayHashElement
                        PsiElement arrayElement = position.getParent().getParent().getParent();
                        if (arrayElement instanceof ArrayHashElement) {
                            ArrayHashElement arrayHashElement = (ArrayHashElement) arrayElement;
                            PhpPsiElement keyPsiElement = arrayHashElement.getKey();
                            if (keyPsiElement instanceof StringLiteralExpression) {
                                String key = ((StringLiteralExpression) keyPsiElement).getContents();

                                if (Arrays.asList(TCA_TABLE_FIELDS).contains(key)) {
                                    TableUtil.completeAvailableTableNames(position.getProject(), result);
                                }
                            }
                        }
                    }
                }
        );
    }
}

@@ -1183,24 +1183,23 @@
 Element 
-position
+element
  = param
@@ -1314,24 +1314,23 @@
 ement = 
-position
+element
 .getPare
@@ -1963,16 +1963,15 @@
 mes(
-position
+element
 .get

Rename local PsiElement variable