Search in sources :

Example 1 with PerlBuiltInVariablesService

use of com.perl5.lang.perl.psi.references.PerlBuiltInVariablesService in project Perl5-IDEA by Camelcade.

the class PerlVariableCompletionUtil method fillWithBuiltInVariables.

public static void fillWithBuiltInVariables(@NotNull PsiElement variableNameElement, @NotNull CompletionResultSet resultSet) {
    PsiElement perlVariable = variableNameElement.getParent();
    PerlBuiltInVariablesService perlBuiltInVariablesService = PerlBuiltInVariablesService.getInstance(variableNameElement.getProject());
    if (perlVariable instanceof PsiPerlScalarVariable) {
        perlBuiltInVariablesService.processScalars((element, state) -> {
            // noinspection ConstantConditions
            resultSet.addElement(getScalarLookupElement(((PerlVariableDeclarationElement) element).getName()).withBoldness(true));
            return true;
        });
        perlBuiltInVariablesService.processArrays((element, state) -> {
            // noinspection ConstantConditions
            resultSet.addElement(getArrayElementLookupElement(((PerlVariableDeclarationElement) element).getName()).withBoldness(true));
            return true;
        });
        perlBuiltInVariablesService.processHashes((element, state) -> {
            // noinspection ConstantConditions
            resultSet.addElement(getHashElementLookupElement(((PerlVariableDeclarationElement) element).getName()).withBoldness(true));
            return true;
        });
    } else if (perlVariable instanceof PsiPerlArrayVariable) {
        perlBuiltInVariablesService.processArrays((element, state) -> {
            // noinspection ConstantConditions
            resultSet.addElement(getArrayLookupElement(((PerlVariableDeclarationElement) element).getName()).withBoldness(true));
            // noinspection ConstantConditions
            resultSet.addElement(getArraySliceLookupElement(((PerlVariableDeclarationElement) element).getName()).withBoldness(true));
            return true;
        });
        perlBuiltInVariablesService.processHashes((element, state) -> {
            // noinspection ConstantConditions
            resultSet.addElement(getHashSliceLookupElement(((PerlVariableDeclarationElement) element).getName()).withBoldness(true));
            return true;
        });
    } else if (perlVariable instanceof PsiPerlArrayIndexVariable) {
        perlBuiltInVariablesService.processArrays((element, state) -> {
            // noinspection ConstantConditions
            resultSet.addElement(getArrayLookupElement(((PerlVariableDeclarationElement) element).getName()).withBoldness(true));
            return true;
        });
    } else if (perlVariable instanceof PsiPerlHashVariable) {
        perlBuiltInVariablesService.processHashes((element, state) -> {
            // noinspection ConstantConditions
            resultSet.addElement(getHashLookupElement(((PerlVariableDeclarationElement) element).getName()).withBoldness(true));
            return true;
        });
    } else if (perlVariable instanceof PsiPerlGlobVariable) {
        perlBuiltInVariablesService.processGlobs((element, state) -> {
            // noinspection ConstantConditions
            resultSet.addElement(getGlobLookupElement(((PerlVariableDeclarationElement) element).getName()).withBoldness(true));
            return true;
        });
    }
}
Also used : PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) PerlVariableType(com.perl5.lang.perl.psi.utils.PerlVariableType) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) LookupElement(com.intellij.codeInsight.lookup.LookupElement) StringUtil(com.intellij.openapi.util.text.StringUtil) Set(java.util.Set) THashSet(gnu.trove.THashSet) PerlInsertHandlers(com.perl5.lang.perl.idea.completion.PerlInsertHandlers) PerlLexicalScope(com.perl5.lang.perl.psi.properties.PerlLexicalScope) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) PerlCompletionWeighter(com.perl5.lang.perl.idea.PerlCompletionWeighter) PerlIcons(com.perl5.PerlIcons) PsiElement(com.intellij.psi.PsiElement) PerlResolveUtil(com.perl5.lang.perl.psi.utils.PerlResolveUtil) com.perl5.lang.perl.psi(com.perl5.lang.perl.psi) PerlBuiltInVariablesService(com.perl5.lang.perl.psi.references.PerlBuiltInVariablesService) NotNull(org.jetbrains.annotations.NotNull) PerlBuiltInVariablesService(com.perl5.lang.perl.psi.references.PerlBuiltInVariablesService) PsiElement(com.intellij.psi.PsiElement)

Aggregations

CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 PsiElement (com.intellij.psi.PsiElement)1 PsiScopeProcessor (com.intellij.psi.scope.PsiScopeProcessor)1 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)1 PerlIcons (com.perl5.PerlIcons)1 PerlCompletionWeighter (com.perl5.lang.perl.idea.PerlCompletionWeighter)1 PerlInsertHandlers (com.perl5.lang.perl.idea.completion.PerlInsertHandlers)1 com.perl5.lang.perl.psi (com.perl5.lang.perl.psi)1 PerlLexicalScope (com.perl5.lang.perl.psi.properties.PerlLexicalScope)1 PerlBuiltInVariablesService (com.perl5.lang.perl.psi.references.PerlBuiltInVariablesService)1 PerlResolveUtil (com.perl5.lang.perl.psi.utils.PerlResolveUtil)1 PerlVariableType (com.perl5.lang.perl.psi.utils.PerlVariableType)1 THashSet (gnu.trove.THashSet)1 Set (java.util.Set)1 NotNull (org.jetbrains.annotations.NotNull)1