Search in sources :

Example 1 with PerlVariableDeclarationElement

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

the class MasonNamespaceDefinitionImpl method getImplicitVariables.

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

Example 2 with PerlVariableDeclarationElement

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

the class PerlResolveUtil method processChildren.

public static boolean processChildren(@NotNull PsiElement element, @NotNull PsiScopeProcessor processor, @NotNull ResolveState resolveState, @Nullable PsiElement lastParent, @NotNull PsiElement place) {
    PsiElement run = lastParent == null ? element.getLastChild() : lastParent.getPrevSibling();
    while (run != null) {
        ProgressManager.checkCanceled();
        if (run instanceof PerlCompositeElement && // fixme this should be in composite
        !(run instanceof PerlLexicalScope) && !run.processDeclarations(processor, resolveState, null, place)) {
            return false;
        }
        run = run.getPrevSibling();
    }
    // checking implicit variables fixme: decide, move processchildren to here or move this one to processDeclarations?
    if (element instanceof PerlImplicitVariablesProvider) {
        for (PerlVariableDeclarationElement wrapper : ((PerlImplicitVariablesProvider) element).getImplicitVariables()) {
            ProgressManager.checkCanceled();
            if (!processor.execute(wrapper, resolveState)) {
                return false;
            }
        }
    }
    return true;
}
Also used : PerlCompositeElement(com.perl5.lang.perl.psi.PerlCompositeElement) PerlVariableDeclarationElement(com.perl5.lang.perl.psi.PerlVariableDeclarationElement) PerlImplicitVariablesProvider(com.perl5.lang.perl.extensions.PerlImplicitVariablesProvider) PerlLexicalScope(com.perl5.lang.perl.psi.properties.PerlLexicalScope)

Example 3 with PerlVariableDeclarationElement

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

the class PerlVariableShadowingInspection method checkDeclaration.

@Override
public void checkDeclaration(ProblemsHolder holder, PerlVariableDeclarationElement variableDeclarationWrapper) {
    PerlVariable variable = variableDeclarationWrapper.getVariable();
    PsiElement declarationContainer = variableDeclarationWrapper.getParent();
    if (variable != null && !(declarationContainer instanceof PsiPerlVariableDeclarationLocal)) {
        PerlVariableDeclarationElement lexicalDeclaration = PerlResolveUtil.getLexicalDeclaration(variable);
        if (lexicalDeclaration instanceof PerlBuiltInVariable) {
            registerProblem(holder, variable, PerlBundle.message("perl.inspection.shadows.builtin", lexicalDeclaration.getVariable().getLineNumber()));
        } else if (lexicalDeclaration instanceof PerlImplicitVariableDeclaration) {
            registerProblem(holder, variable, PerlBundle.message("perl.inspection.shadows.implicit", lexicalDeclaration.getVariable().getLineNumber()));
        } else if (lexicalDeclaration != null) {
            registerProblem(holder, variable, PerlBundle.message("perl.inspection.shadows.other", lexicalDeclaration.getVariable().getLineNumber()));
        }
    }
}
Also used : PsiPerlVariableDeclarationLocal(com.perl5.lang.perl.psi.PsiPerlVariableDeclarationLocal) PerlBuiltInVariable(com.perl5.lang.perl.psi.impl.PerlBuiltInVariable) PerlVariableDeclarationElement(com.perl5.lang.perl.psi.PerlVariableDeclarationElement) PerlVariable(com.perl5.lang.perl.psi.PerlVariable) PerlImplicitVariableDeclaration(com.perl5.lang.perl.psi.impl.PerlImplicitVariableDeclaration) PsiElement(com.intellij.psi.PsiElement)

Example 4 with PerlVariableDeclarationElement

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

the class HTMLMasonFileImpl method processDeclarations.

@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent, @NotNull PsiElement place) {
    boolean checkShared = false;
    boolean checkArgs = false;
    boolean checkInit = false;
    boolean checkCode = false;
    boolean checkCleanup = false;
    PsiElement onceAnchor = null;
    PsiElement sharedAnchor = null;
    PsiElement argsAnchor = null;
    PsiElement initAnchor = null;
    PsiElement cleanupAnchor = null;
    if (lastParent instanceof HTMLMasonSharedBlockImpl) {
        checkShared = true;
        sharedAnchor = lastParent;
    } else if (lastParent instanceof HTMLMasonArgsBlockImpl) {
        checkShared = true;
        checkArgs = true;
        argsAnchor = lastParent;
    } else if (lastParent instanceof HTMLMasonInitBlockImpl) {
        checkArgs = true;
        checkShared = true;
        checkInit = true;
        initAnchor = lastParent;
    } else if (lastParent instanceof HTMLMasonFilterBlockImpl) {
        checkArgs = true;
        checkShared = true;
    } else if (lastParent instanceof HTMLMasonOnceBlock) {
        onceAnchor = lastParent;
    } else if (!(lastParent instanceof HTMLMasonSubcomponentDefitnitionImpl || lastParent instanceof HTMLMasonMethodDefinitionImpl)) {
        checkArgs = true;
        checkShared = true;
        checkInit = true;
        checkCode = true;
        if (// change nature flow
        lastParent instanceof HTMLMasonCleanupBlockImpl) {
            checkCleanup = true;
            cleanupAnchor = lastParent;
            lastParent = null;
        }
    }
    if (checkCode) {
        if (!processChildren(this, processor, state, lastParent, place)) {
            return false;
        }
    }
    if (checkCleanup) {
        if (!checkSubblocks(processor, state, place, HTMLMasonCleanupBlock.class, cleanupAnchor)) {
            return false;
        }
    }
    if (checkInit) {
        if (!checkSubblocks(processor, state, place, HTMLMasonInitBlock.class, initAnchor)) {
            return false;
        }
    }
    if (checkArgs) {
        if (!checkSubblocks(processor, state, place, HTMLMasonArgsBlock.class, argsAnchor)) {
            return false;
        }
    }
    if (checkShared) {
        if (!checkSubblocks(processor, state, place, HTMLMasonSharedBlock.class, sharedAnchor)) {
            return false;
        }
    }
    if (!checkSubblocks(processor, state, place, HTMLMasonOnceBlock.class, onceAnchor)) {
        return false;
    }
    // implicit variables
    for (PerlVariableDeclarationElement wrapper : getImplicitVariables()) {
        if (!processor.execute(wrapper, state)) {
            return false;
        }
    }
    return false;
}
Also used : PerlVariableDeclarationElement(com.perl5.lang.perl.psi.PerlVariableDeclarationElement)

Example 5 with PerlVariableDeclarationElement

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

the class PerlVariableNameCompletionProvider method fillWithFullQualifiedVariables.

private void fillWithFullQualifiedVariables(@NotNull PsiElement variableNameElement, @NotNull CompletionResultSet resultSet) {
    PsiElement perlVariable = variableNameElement.getParent();
    Project project = variableNameElement.getProject();
    GlobalSearchScope resolveScope = variableNameElement.getResolveScope();
    String variableName = variableNameElement.getText();
    boolean forceShortMain = StringUtil.startsWith(variableName, PerlPackageUtil.PACKAGE_SEPARATOR);
    final CompletionResultSet finalResultSet = resultSet;
    Processor<PerlVariableDeclarationElement> scalarDefaultProcessor = wrapper -> {
        String fullQualifiedName = wrapper.getFullQualifiedName();
        if (fullQualifiedName != null) {
            finalResultSet.addElement(PerlVariableCompletionUtil.getScalarLookupElement(adjustName(fullQualifiedName, forceShortMain)));
        }
        return true;
    };
    Processor<PerlVariableDeclarationElement> arrayDefaultProcessor = wrapper -> {
        String fullQualifiedName = wrapper.getFullQualifiedName();
        if (fullQualifiedName != null) {
            finalResultSet.addElement(PerlVariableCompletionUtil.getArrayLookupElement(adjustName(fullQualifiedName, forceShortMain)));
        }
        return true;
    };
    Processor<PerlVariableDeclarationElement> hashDefaultProcessor = wrapper -> {
        String fullQualifiedName = wrapper.getFullQualifiedName();
        if (fullQualifiedName != null) {
            finalResultSet.addElement(PerlVariableCompletionUtil.getHashLookupElement(adjustName(fullQualifiedName, forceShortMain)));
        }
        return true;
    };
    if (perlVariable instanceof PsiPerlScalarVariable) {
        PerlScalarUtil.processDefinedGlobalScalars(project, resolveScope, scalarDefaultProcessor);
        PerlArrayUtil.processDefinedGlobalArrays(project, resolveScope, wrapper -> {
            String fullQualifiedName = wrapper.getFullQualifiedName();
            if (fullQualifiedName != null) {
                finalResultSet.addElement(PerlVariableCompletionUtil.getArrayElementLookupElement(adjustName(fullQualifiedName, forceShortMain)));
            }
            return true;
        });
        PerlHashUtil.processDefinedGlobalHashes(project, resolveScope, wrapper -> {
            String fullQualifiedName = wrapper.getFullQualifiedName();
            if (fullQualifiedName != null) {
                finalResultSet.addElement(PerlVariableCompletionUtil.getHashElementLookupElement(adjustName(fullQualifiedName, forceShortMain)));
            }
            return true;
        });
    } else if (perlVariable instanceof PerlGlobVariable) {
        PerlScalarUtil.processDefinedGlobalScalars(project, resolveScope, scalarDefaultProcessor);
        PerlArrayUtil.processDefinedGlobalArrays(project, resolveScope, arrayDefaultProcessor);
        PerlHashUtil.processDefinedGlobalHashes(project, resolveScope, hashDefaultProcessor);
        // globs
        PerlGlobUtil.processDefinedGlobsNames(project, resolveScope, typeglob -> {
            String adjustedName = adjustName(typeglob.getCanonicalName(), forceShortMain);
            if (adjustedName != null) {
                finalResultSet.addElement(PerlVariableCompletionUtil.getGlobLookupElement(adjustedName));
            }
            return true;
        });
    } else if (perlVariable instanceof PsiPerlArrayVariable) {
        PerlArrayUtil.processDefinedGlobalArrays(project, resolveScope, arrayDefaultProcessor);
        PerlHashUtil.processDefinedGlobalHashes(project, resolveScope, wrapper -> {
            String fullQualifiedName = wrapper.getFullQualifiedName();
            if (fullQualifiedName != null) {
                finalResultSet.addElement(PerlVariableCompletionUtil.getHashSliceLookupElement(adjustName(fullQualifiedName, forceShortMain)));
            }
            return true;
        });
    } else if (perlVariable instanceof PsiPerlArrayIndexVariable) {
        // global arrays
        PerlArrayUtil.processDefinedGlobalArrays(project, resolveScope, arrayDefaultProcessor);
    } else if (perlVariable instanceof PsiPerlHashVariable) {
        // global hashes
        PerlHashUtil.processDefinedGlobalHashes(project, resolveScope, hashDefaultProcessor);
    }
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) PlainPrefixMatcher(com.intellij.codeInsight.completion.PlainPrefixMatcher) LookupElementBuilder(com.intellij.codeInsight.lookup.LookupElementBuilder) StringUtil(com.intellij.openapi.util.text.StringUtil) CompletionParameters(com.intellij.codeInsight.completion.CompletionParameters) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) PerlExportDescriptor(com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor) CompletionProvider(com.intellij.codeInsight.completion.CompletionProvider) Processor(com.intellij.util.Processor) PsiElement(com.intellij.psi.PsiElement) PerlVariableCompletionUtil(com.perl5.lang.perl.idea.completion.util.PerlVariableCompletionUtil) Project(com.intellij.openapi.project.Project) com.perl5.lang.perl.psi(com.perl5.lang.perl.psi) PerlElementPatterns(com.perl5.lang.perl.idea.PerlElementPatterns) PerlInternalIndexKeysProcessor.adjustName(com.perl5.lang.perl.util.processors.PerlInternalIndexKeysProcessor.adjustName) NotNull(org.jetbrains.annotations.NotNull) PerlNamespaceEntityProcessor(com.perl5.lang.perl.util.processors.PerlNamespaceEntityProcessor) com.perl5.lang.perl.util(com.perl5.lang.perl.util) CompletionResultSet(com.intellij.codeInsight.completion.CompletionResultSet) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiElement(com.intellij.psi.PsiElement)

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