Search in sources :

Example 6 with PerlVariable

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

the class PerlDocUtil method getPerlVarDoc.

@Nullable
public static PsiElement getPerlVarDoc(PerlVariable variable) {
    final Project project = variable.getProject();
    PerlVariableType actualType = variable.getActualType();
    String variableName = variable.getName();
    if (actualType != null && StringUtil.isNotEmpty(variableName)) {
        String text = actualType.getSigil() + variableName;
        if (myVariablesRedirections.containsKey(text)) {
            return resolveDocLink(myVariablesRedirections.get(text), variable);
        }
        if (variable.isBuiltIn()) {
            PodDocumentPattern pattern = PodDocumentPattern.itemPattern(text);
            if (text.matches("\\$[123456789]")) {
                pattern.setItemPattern("$<digits>");
            }
            return searchPodElementInFile(project, PodSearchHelper.PERL_VAR_FILE_NAME, pattern);
        }
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) PerlVariableType(com.perl5.lang.perl.psi.utils.PerlVariableType) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with PerlVariable

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

the class PerlElementFactory method createDereference.

public static PsiElement createDereference(Project project) {
    PerlFileImpl file = createFile(project, "$a->{bla};");
    PerlVariable variable = PsiTreeUtil.findChildOfType(file, PerlVariable.class);
    assert variable != null : "While creating dereference";
    return variable.getNextSibling();
}
Also used : PerlFileImpl(com.perl5.lang.perl.psi.impl.PerlFileImpl)

Example 8 with PerlVariable

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

the class PerlVariableReference method resolveInner.

@NotNull
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode) {
    PsiElement elementParent = myElement.getParent();
    assert elementParent instanceof PerlVariable;
    PerlVariable perlVariable = (PerlVariable) elementParent;
    List<ResolveResult> result = new ArrayList<>();
    PerlVariableDeclarationElement lexicalDeclaration = PerlResolveUtil.getLexicalDeclaration(perlVariable);
    if (lexicalDeclaration == null || lexicalDeclaration.isGlobalDeclaration() && !(lexicalDeclaration instanceof PerlImplicitVariableDeclaration)) {
        // not found explicit lexically visible declarations
        // imports
        PerlVariableType actualType = perlVariable.getActualType();
        Project project = perlVariable.getProject();
        PerlNamespaceDefinitionElement namespaceContainer = PerlPackageUtil.getNamespaceContainerForElement(perlVariable);
        if (// not true if LPE in TemplateToolkit
        namespaceContainer != null) {
            String variableName = perlVariable.getName();
            if (actualType == PerlVariableType.SCALAR) {
                for (PerlExportDescriptor importEntry : namespaceContainer.getImportedScalarDescriptors()) {
                    if (importEntry.getImportedName().equals(variableName)) {
                        for (PerlVariableDeclarationElement targetVariable : PerlScalarUtil.getGlobalScalarDefinitions(project, importEntry.getTargetCanonicalName())) {
                            result.add(new PsiElementResolveResult(targetVariable));
                        }
                    }
                }
            } else if (actualType == PerlVariableType.ARRAY) {
                for (PerlExportDescriptor importEntry : namespaceContainer.getImportedArrayDescriptors()) {
                    if (importEntry.getImportedName().equals(variableName)) {
                        for (PerlVariableDeclarationElement targetVariable : PerlArrayUtil.getGlobalArrayDefinitions(project, importEntry.getTargetCanonicalName())) {
                            result.add(new PsiElementResolveResult(targetVariable));
                        }
                    }
                }
            } else if (actualType == PerlVariableType.HASH) {
                for (PerlExportDescriptor importEntry : namespaceContainer.getImportedHashDescriptors()) {
                    if (importEntry.getImportedName().equals(variableName)) {
                        for (PerlVariableDeclarationElement targetVariable : PerlHashUtil.getGlobalHashDefinitions(project, importEntry.getTargetCanonicalName())) {
                            result.add(new PsiElementResolveResult(targetVariable));
                        }
                    }
                }
            }
        }
        // our variable declaration
        for (PerlGlobVariable glob : perlVariable.getRelatedGlobs()) {
            result.add(new PsiElementResolveResult(glob));
        }
        // globs
        for (PerlVariableDeclarationElement globalDeclaration : perlVariable.getGlobalDeclarations()) {
            result.add(new PsiElementResolveResult(globalDeclaration));
        }
    } else {
        result.add(new PsiElementResolveResult(lexicalDeclaration));
    }
    return result.toArray(new ResolveResult[result.size()]);
}
Also used : PerlVariableDeclarationElement(com.perl5.lang.perl.psi.PerlVariableDeclarationElement) PerlVariableType(com.perl5.lang.perl.psi.utils.PerlVariableType) ArrayList(java.util.ArrayList) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) Project(com.intellij.openapi.project.Project) PerlExportDescriptor(com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor) PerlNamespaceDefinitionElement(com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement) PerlGlobVariable(com.perl5.lang.perl.psi.PerlGlobVariable) PerlVariable(com.perl5.lang.perl.psi.PerlVariable) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) ResolveResult(com.intellij.psi.ResolveResult) PerlImplicitVariableDeclaration(com.perl5.lang.perl.psi.impl.PerlImplicitVariableDeclaration) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with PerlVariable

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

the class PerlUnresolvedVariableInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    return new PerlVisitor() {

        @Override
        public void visitPerlVariable(@NotNull final PerlVariable variable) {
            PsiElement parent = variable.getParent();
            if (parent instanceof PerlVariableDeclarationElement || variable.isBuiltIn()) {
                return;
            }
            PerlVariableNameElement variableNameElement = variable.getVariableNameElement();
            if (variableNameElement != null) {
                for (PsiReference reference : variableNameElement.getReferences()) {
                    if (reference instanceof PsiPolyVariantReference && ((PsiPolyVariantReference) reference).multiResolve(false).length > 0 || reference.resolve() != null) {
                        return;
                    }
                }
                registerProblem(holder, variableNameElement, "Unable to find variable declaration.");
            }
        }
    };
}
Also used : PerlVariableDeclarationElement(com.perl5.lang.perl.psi.PerlVariableDeclarationElement) PerlVariableNameElement(com.perl5.lang.perl.psi.PerlVariableNameElement) PsiReference(com.intellij.psi.PsiReference) PerlVisitor(com.perl5.lang.perl.psi.PerlVisitor) PerlVariable(com.perl5.lang.perl.psi.PerlVariable) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) PsiPolyVariantReference(com.intellij.psi.PsiPolyVariantReference) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with PerlVariable

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

Aggregations

PsiElement (com.intellij.psi.PsiElement)13 PerlVariable (com.perl5.lang.perl.psi.PerlVariable)7 PerlVariableType (com.perl5.lang.perl.psi.utils.PerlVariableType)6 NotNull (org.jetbrains.annotations.NotNull)6 PerlVariableDeclarationElement (com.perl5.lang.perl.psi.PerlVariableDeclarationElement)5 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)4 Project (com.intellij.openapi.project.Project)4 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3 PsiReference (com.intellij.psi.PsiReference)3 PerlExportDescriptor (com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor)3 com.perl5.lang.perl.psi (com.perl5.lang.perl.psi)3 PerlLexicalScope (com.perl5.lang.perl.psi.properties.PerlLexicalScope)3 THashSet (gnu.trove.THashSet)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 PsiFile (com.intellij.psi.PsiFile)2 PsiScopeProcessor (com.intellij.psi.scope.PsiScopeProcessor)2 IElementType (com.intellij.psi.tree.IElementType)2 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)2 PerlIcons (com.perl5.PerlIcons)2