Search in sources :

Example 1 with PsiPerlUseStatement

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

the class PerlStringCompletionUtil method fillWithUseParameters.

public static void fillWithUseParameters(@NotNull final PsiElement stringContentElement, @NotNull final CompletionResultSet resultSet) {
    @SuppressWarnings("unchecked") PsiPerlUseStatement useStatement = PsiTreeUtil.getParentOfType(stringContentElement, PsiPerlUseStatement.class, true, PsiPerlStatement.class);
    if (useStatement == null) {
        return;
    }
    List<String> typedParameters = useStatement.getImportParameters();
    Set<String> typedStringsSet = typedParameters == null ? Collections.emptySet() : new THashSet<>(typedParameters);
    PerlPackageProcessor packageProcessor = useStatement.getPackageProcessor();
    // fixme we should allow lookup elements customization by package processor
    if (packageProcessor instanceof PerlPackageOptionsProvider) {
        Map<String, String> options = ((PerlPackageOptionsProvider) packageProcessor).getOptions();
        for (Map.Entry<String, String> option : options.entrySet()) {
            if (!typedStringsSet.contains(option.getKey())) {
                resultSet.addElement(LookupElementBuilder.create(option.getKey()).withTypeText(option.getValue(), true).withIcon(PerlIcons.PERL_OPTION));
            }
        }
        options = ((PerlPackageOptionsProvider) packageProcessor).getOptionsBundles();
        for (Map.Entry<String, String> option : options.entrySet()) {
            if (!typedStringsSet.contains(option.getKey())) {
                resultSet.addElement(LookupElementBuilder.create(option.getKey()).withTypeText(option.getValue(), true).withIcon(PerlIcons.PERL_OPTIONS));
            }
        }
    }
    if (packageProcessor instanceof PerlPackageParentsProvider && ((PerlPackageParentsProvider) packageProcessor).hasPackageFilesOptions()) {
        PerlPackageUtil.processPackageFilesForPsiElement(stringContentElement, s -> {
            if (!typedStringsSet.contains(s)) {
                resultSet.addElement(PerlPackageCompletionUtil.getPackageLookupElement(s, null));
            }
            return true;
        });
    }
    Set<String> export = new HashSet<>();
    Set<String> exportOk = new HashSet<>();
    packageProcessor.addExports(useStatement, export, exportOk);
    exportOk.removeAll(export);
    for (String subName : export) {
        if (!typedStringsSet.contains(subName)) {
            resultSet.addElement(LookupElementBuilder.create(subName).withIcon(PerlIcons.SUB_GUTTER_ICON).withTypeText("default", true));
        }
    }
    for (String subName : exportOk) {
        if (!typedStringsSet.contains(subName)) {
            resultSet.addElement(LookupElementBuilder.create(subName).withIcon(PerlIcons.SUB_GUTTER_ICON).withTypeText("optional", true));
        }
    }
}
Also used : PerlPackageParentsProvider(com.perl5.lang.perl.extensions.packageprocessor.PerlPackageParentsProvider) PerlPackageOptionsProvider(com.perl5.lang.perl.extensions.packageprocessor.PerlPackageOptionsProvider) PerlPackageProcessor(com.perl5.lang.perl.extensions.packageprocessor.PerlPackageProcessor) THashSet(gnu.trove.THashSet)

Example 2 with PsiPerlUseStatement

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

the class PerlUseVarsInspection method buildVisitor.

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

        @Override
        public void visitUseStatement(@NotNull PsiPerlUseStatement o) {
            if (PACKAGE_VARS.equals(o.getPackageName())) {
                PerlUseVarsQuickFix quickFix = new PerlUseVarsQuickFix(o);
                holder.registerProblem(o, quickFix.isRemoval() ? PerlBundle.message("perl.redundant.code") : PerlBundle.message("perl.inspection.use.vars"), quickFix.isRemoval() ? ProblemHighlightType.LIKE_UNUSED_SYMBOL : ProblemHighlightType.GENERIC_ERROR_OR_WARNING, quickFix);
            }
        }
    };
}
Also used : PsiPerlUseStatement(com.perl5.lang.perl.psi.PsiPerlUseStatement) PerlUseVarsQuickFix(com.perl5.lang.perl.idea.quickfixes.PerlUseVarsQuickFix) PerlVisitor(com.perl5.lang.perl.psi.PerlVisitor) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PerlPackageOptionsProvider (com.perl5.lang.perl.extensions.packageprocessor.PerlPackageOptionsProvider)1 PerlPackageParentsProvider (com.perl5.lang.perl.extensions.packageprocessor.PerlPackageParentsProvider)1 PerlPackageProcessor (com.perl5.lang.perl.extensions.packageprocessor.PerlPackageProcessor)1 PerlUseVarsQuickFix (com.perl5.lang.perl.idea.quickfixes.PerlUseVarsQuickFix)1 PerlVisitor (com.perl5.lang.perl.psi.PerlVisitor)1 PsiPerlUseStatement (com.perl5.lang.perl.psi.PsiPerlUseStatement)1 THashSet (gnu.trove.THashSet)1 NotNull (org.jetbrains.annotations.NotNull)1