Search in sources :

Example 16 with PerlVariableDeclarationElement

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

the class PerlBuiltinVariableRedeclarationInspection method checkDeclaration.

public void checkDeclaration(ProblemsHolder holder, PerlVariableDeclarationElement variableDeclarationWrapper) {
    PerlVariable variable = variableDeclarationWrapper.getVariable();
    PsiElement declarationContainer = variableDeclarationWrapper.getParent();
    if (variable != null && PerlBuiltInVariablesService.getInstance(variableDeclarationWrapper.getProject()).getVariableDeclaration(variable.getActualType(), variable.getName()) != null && !(declarationContainer instanceof PsiPerlVariableDeclarationLocal)) {
        registerProblem(holder, variable, PerlBundle.message("perl.inspection.builtin.shadowing"));
    }
}
Also used : PsiPerlVariableDeclarationLocal(com.perl5.lang.perl.psi.PsiPerlVariableDeclarationLocal) PerlVariable(com.perl5.lang.perl.psi.PerlVariable) PsiElement(com.intellij.psi.PsiElement)

Example 17 with PerlVariableDeclarationElement

use of com.perl5.lang.perl.psi.PerlVariableDeclarationElement 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)

Example 18 with PerlVariableDeclarationElement

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

the class PerlVariableCompletionUtil method fillWithLExicalVariables.

public static void fillWithLExicalVariables(@NotNull PsiElement variableNameElement, @NotNull final CompletionResultSet resultSet) {
    final PsiElement perlVariable = variableNameElement.getParent();
    PsiScopeProcessor processor = (element, state) -> {
        if (element instanceof PerlVariableDeclarationElement) {
            PerlVariableDeclarationElement variable = (PerlVariableDeclarationElement) element;
            PsiElement declarationStatement = PsiTreeUtil.getParentOfType(variable, PerlStatement.class);
            if (PsiTreeUtil.isAncestor(declarationStatement, perlVariable, false)) {
                return true;
            }
            if (perlVariable instanceof PsiPerlScalarVariable) {
                String variableName = variable.getName();
                if (variableName != null) {
                    if (variable.getActualType() == PerlVariableType.SCALAR) {
                        resultSet.addElement(setLexical(getScalarLookupElement(variableName)));
                    } else if (variable.getActualType() == PerlVariableType.ARRAY) {
                        resultSet.addElement(setLexical(getArrayElementLookupElement(variableName)));
                    } else if (variable.getActualType() == PerlVariableType.HASH) {
                        resultSet.addElement(setLexical(getHashElementLookupElement(variableName)));
                    }
                }
            } else if (perlVariable instanceof PsiPerlArrayVariable) {
                String variableName = variable.getName();
                if (variableName != null) {
                    if (variable.getActualType() == PerlVariableType.ARRAY) {
                        resultSet.addElement(setLexical(getArrayLookupElement(variableName)));
                        resultSet.addElement(setLexical(getArraySliceLookupElement(variableName)));
                    } else if (variable.getActualType() == PerlVariableType.HASH) {
                        resultSet.addElement(setLexical(getHashSliceLookupElement(variableName)));
                    }
                }
            } else if (perlVariable instanceof PsiPerlArrayIndexVariable) {
                String variableName = variable.getName();
                if (variableName != null) {
                    if (variable.getActualType() == PerlVariableType.ARRAY) {
                        resultSet.addElement(setLexical(getArrayLookupElement(variableName)));
                    }
                }
            } else if (perlVariable instanceof PsiPerlHashVariable) {
                String variableName = variable.getName();
                if (variableName != null) {
                    if (variable.getActualType() == PerlVariableType.HASH) {
                        resultSet.addElement(setLexical(getHashLookupElement(variableName)));
                    }
                }
            }
        }
        return true;
    };
    PerlResolveUtil.treeWalkUp(variableNameElement, processor);
    PerlBuiltInVariablesService.getInstance(variableNameElement.getProject()).processVariables(processor);
}
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) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) PsiElement(com.intellij.psi.PsiElement)

Example 19 with PerlVariableDeclarationElement

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

the class HTMLMasonFileImpl method getImplicitVariables.

@NotNull
@Override
public List<PerlVariableDeclarationElement> getImplicitVariables() {
    HTMLMasonSettings settings = HTMLMasonSettings.getInstance(getProject());
    if (myImplicitVariables == null || myMasonChangeCounter != settings.getChangeCounter()) {
        myImplicitVariables = buildImplicitVariables(settings);
        myMasonChangeCounter = settings.getChangeCounter();
    }
    return myImplicitVariables;
}
Also used : HTMLMasonSettings(com.perl5.lang.htmlmason.idea.configuration.HTMLMasonSettings) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with PerlVariableDeclarationElement

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

the class HTMLMasonArgsBlockImpl method getArgumentsListHeavy.

@NotNull
protected List<PerlSubArgument> getArgumentsListHeavy() {
    List<PerlSubArgument> result = new ArrayList<>();
    PsiElement run = getFirstChild();
    while (run != null) {
        if (run instanceof PerlVariableDeclarationElement) {
            PerlVariable variable = ((PerlVariableDeclarationElement) run).getVariable();
            if (variable != null) {
                PsiElement nextSibling = PerlPsiUtil.getNextSignificantSibling(run);
                result.add(PerlSubArgument.create(variable.getActualType(), variable.getName(), nextSibling != null && nextSibling.getNode().getElementType() == FAT_COMMA));
            }
        }
        run = run.getNextSibling();
    }
    return result;
}
Also used : PerlSubArgument(com.perl5.lang.perl.psi.utils.PerlSubArgument) PerlVariableDeclarationElement(com.perl5.lang.perl.psi.PerlVariableDeclarationElement) ArrayList(java.util.ArrayList) PerlVariable(com.perl5.lang.perl.psi.PerlVariable) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiElement (com.intellij.psi.PsiElement)12 PerlVariableDeclarationElement (com.perl5.lang.perl.psi.PerlVariableDeclarationElement)10 NotNull (org.jetbrains.annotations.NotNull)10 PerlVariable (com.perl5.lang.perl.psi.PerlVariable)6 PerlVariableType (com.perl5.lang.perl.psi.utils.PerlVariableType)6 PerlLexicalScope (com.perl5.lang.perl.psi.properties.PerlLexicalScope)5 Project (com.intellij.openapi.project.Project)4 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)3 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 PerlExportDescriptor (com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor)3 com.perl5.lang.perl.psi (com.perl5.lang.perl.psi)3 PerlImplicitVariableDeclaration (com.perl5.lang.perl.psi.impl.PerlImplicitVariableDeclaration)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 PsiFile (com.intellij.psi.PsiFile)2 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)2 PsiScopeProcessor (com.intellij.psi.scope.PsiScopeProcessor)2 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)2 PerlIcons (com.perl5.PerlIcons)2