use of com.perl5.lang.perl.extensions.packageprocessor.PerlPackageProcessor 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.extensions.packageprocessor.PerlPackageProcessor in project Perl5-IDEA by Camelcade.
the class PerlUseStatementMixin method getPackageProcessor.
@NotNull
@Override
public PerlPackageProcessor getPackageProcessor() {
PerlPackageProcessor packageProcessor = null;
// package name processor
String packageName = getPackageName();
if (packageName != null) {
packageProcessor = PerlPackageProcessorEP.EP.findSingle(packageName);
} else if (getVersionElement() != null) {
packageProcessor = PerlVersionProcessor.getProcessor(PerlUseStatementMixin.this);
}
return packageProcessor == null ? PerlPackageProcessorDefault.INSTANCE : packageProcessor;
}
use of com.perl5.lang.perl.extensions.packageprocessor.PerlPackageProcessor in project Perl5-IDEA by Camelcade.
the class PerlParserUtil method parseUseParameters.
/**
* Parses use parameters with package processor if it's possible. If not, uses default parsing logic.
*/
public static boolean parseUseParameters(@NotNull PsiBuilder b, int l, @NotNull Parser defaultParser) {
if (b.getTokenType() == PACKAGE) {
String packageName = b.getTokenText();
if (StringUtil.isEmpty(packageName)) {
return false;
}
PerlPackageProcessor packageProcessor = PerlPackageProcessorEP.EP.findSingle(packageName);
if (packageProcessor != null) {
assert b instanceof PerlBuilder;
PsiBuilder.Marker m = b.mark();
if (packageProcessor.parseUseParameters((PerlBuilder) b, l)) {
m.drop();
return true;
}
m.rollbackTo();
}
}
return defaultParser.parse(b, l);
}
use of com.perl5.lang.perl.extensions.packageprocessor.PerlPackageProcessor in project Perl5-IDEA by Camelcade.
the class packageProcessorsTest method testModernPerl.
public void testModernPerl() {
initWithFileSmart("ModernPerl");
PerlNamespaceDefinitionElement namespaceDefinition = getElementAtCaret(PerlNamespaceDefinitionElement.class);
assertNotNull(namespaceDefinition);
assertEquals(PerlMroType.C3, namespaceDefinition.getMroType());
PerlUseStatement useStatement = getElementAtCaret(PerlUseStatement.class);
assertNotNull(useStatement);
PerlPackageProcessor packageProcessor = useStatement.getPackageProcessor();
assertNotNull(packageProcessor);
assertInstanceOf(packageProcessor, PerlStrictProvider.class);
assertInstanceOf(packageProcessor, PerlMroProvider.class);
assertInstanceOf(packageProcessor, PerlWarningsProvider.class);
assertInstanceOf(packageProcessor, PerlPackageLoader.class);
}
use of com.perl5.lang.perl.extensions.packageprocessor.PerlPackageProcessor in project Perl5-IDEA by Camelcade.
the class PerlPackageUtil method getIncDirsForPsiElement.
/**
* Returns List of lib directories including class roots, current directory and use lib ones
*
* @param psiElement to resolve for
* @return list of lib dirs
*/
@NotNull
public static List<VirtualFile> getIncDirsForPsiElement(@NotNull PsiElement psiElement) {
PsiFile psiFile = psiElement.getContainingFile().getOriginalFile();
List<VirtualFile> result = new ArrayList<>();
// libdirs providers fixme we need to use stubs or psi here
for (PerlUseStatement useStatement : PsiTreeUtil.findChildrenOfType(psiFile, PerlUseStatement.class)) {
PerlPackageProcessor packageProcessor = useStatement.getPackageProcessor();
if (packageProcessor instanceof PerlLibProvider) {
((PerlLibProvider) packageProcessor).addLibDirs(useStatement, result);
}
}
// classpath
result.addAll(PerlProjectManager.getInstance(psiElement.getProject()).getAllLibraryRoots());
// current dir
if (PerlSharedSettings.getInstance(psiFile.getProject()).getTargetPerlVersion().lesserThan(PerlVersion.V5_26)) {
VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile != null && virtualFile.getParent() != null) {
result.add(virtualFile.getParent());
}
}
return result;
}
Aggregations