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));
}
}
}
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);
}
}
};
}
Aggregations