use of com.perl5.lang.perl.psi.PerlSubElement in project Perl5-IDEA by Camelcade.
the class PerlRenamePolyReferencedElementProcessor method suggestSuperMethod.
@NotNull
private PsiElement suggestSuperMethod(@NotNull PerlSubElement subBase) {
PerlSubElement topLevelSuperMethod = subBase.getTopmostSuperMethod();
String canonicalName = topLevelSuperMethod.getCanonicalName();
if (topLevelSuperMethod == subBase || canonicalName == null) {
return subBase;
}
int dialogResult = Messages.showOkCancelDialog("This method overrides SUPER method: " + canonicalName + ".", "Method Rename", "Rename SUPER method", "Rename this one", PerlIcons.PERL_LANGUAGE_ICON);
return dialogResult == Messages.OK ? topLevelSuperMethod : subBase;
}
use of com.perl5.lang.perl.psi.PerlSubElement in project Perl5-IDEA by Camelcade.
the class PerlSubNameElementCompletionProvider method addCompletions.
public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {
PsiElement element = parameters.getPosition();
if (element.getParent() instanceof PerlSubElement) {
PerlSubElement subDefinitionBase = (PerlSubElement) element.getParent();
PerlSubCompletionUtil.fillWithUnresolvedSubs(subDefinitionBase, resultSet);
PerlSubCompletionUtil.fillWithNotOverridedSubs(subDefinitionBase, resultSet);
}
}
use of com.perl5.lang.perl.psi.PerlSubElement in project Perl5-IDEA by Camelcade.
the class PodSubReference method resolveInner.
@NotNull
@Override
protected ResolveResult[] resolveInner(boolean incompleteCode) {
PsiElement element = getElement();
if (element != null) {
final Project project = element.getProject();
String subName = element.getText();
if (StringUtil.isNotEmpty(subName)) {
final PsiFile containingFile = element.getContainingFile();
String packageName = PodFileUtil.getPackageName(containingFile);
List<ResolveResult> results = new ArrayList<>();
if (StringUtil.isNotEmpty(packageName)) {
String canonicalName = packageName + PerlPackageUtil.PACKAGE_SEPARATOR + subName;
for (PerlSubDefinitionElement target : PerlSubUtil.getSubDefinitions(project, canonicalName)) {
results.add(new PsiElementResolveResult(target));
}
for (PerlSubDeclarationElement target : PerlSubUtil.getSubDeclarations(project, canonicalName)) {
results.add(new PsiElementResolveResult(target));
}
}
if (results.isEmpty()) {
final PsiFile perlFile = containingFile.getViewProvider().getStubBindingRoot();
for (PerlSubElement subBase : PsiTreeUtil.findChildrenOfType(perlFile, PerlSubElement.class)) {
String subBaseName = subBase.getName();
if (subBaseName != null && StringUtil.equals(subBaseName, subName)) {
results.add(new PsiElementResolveResult(subBase));
}
}
}
return results.toArray(new ResolveResult[results.size()]);
}
}
return ResolveResult.EMPTY_ARRAY;
}
use of com.perl5.lang.perl.psi.PerlSubElement in project Perl5-IDEA by Camelcade.
the class PerlPackageUtil method processNotOverridedMethods.
public static void processNotOverridedMethods(final PerlNamespaceDefinitionElement namespaceDefinition, Processor<PerlSubElement> processor) {
if (namespaceDefinition != null) {
PsiFile containingFile = namespaceDefinition.getContainingFile();
String packageName = namespaceDefinition.getPackageName();
if (packageName == null) {
return;
}
Set<String> namesSet = new THashSet<>();
// collecting overrided
for (PerlSubDefinitionElement subDefinitionBase : PsiTreeUtil.findChildrenOfType(containingFile, PerlSubDefinitionElement.class)) {
if (subDefinitionBase.isValid() && StringUtil.equals(packageName, subDefinitionBase.getPackageName())) {
namesSet.add(subDefinitionBase.getSubName());
}
}
processParentClassesSubs(namespaceDefinition, namesSet, new THashSet<>(), processor);
}
}
use of com.perl5.lang.perl.psi.PerlSubElement in project Perl5-IDEA by Camelcade.
the class PodTitleCompletionProvider method addCompletions.
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
final PsiElement element = parameters.getOriginalPosition();
if (element == null) {
return;
}
PsiElement prevElement = element.getPrevSibling();
if (prevElement == null || prevElement instanceof PodSectionTitle) {
if (HEADER1_ELEMENT.accepts(element)) {
for (String title : DEFAULT_POD_SECTIONS) {
result.addElement(LookupElementBuilder.create(title));
}
}
final PsiFile elementFile = element.getContainingFile();
final PsiFile perlFile = PodFileUtil.getTargetPerlFile(elementFile);
if (perlFile != null) {
final Collection<PerlSubElement> possibleTargets = PsiTreeUtil.findChildrenOfType(perlFile, PerlSubElement.class);
element.getContainingFile().accept(new PodRecursiveVisitor() {
@Override
public void visitTargetableSection(PodTitledSection o) {
PsiElement titleBlock = o.getTitleBlock();
if (titleBlock != null) {
PsiElement firstChild = titleBlock.getFirstChild();
if (firstChild != null) {
for (PsiReference reference : firstChild.getReferences()) {
if (reference instanceof PodSubReference) {
for (ResolveResult resolveResult : ((PodSubReference) reference).multiResolve(false)) {
PsiElement targetElement = resolveResult.getElement();
if (targetElement instanceof PerlSubElement) {
possibleTargets.remove(targetElement);
}
}
}
}
}
}
super.visitTargetableSection(o);
}
});
for (PerlSubElement untargetedSub : possibleTargets) {
result.addElement(LookupElementBuilder.create(StringUtil.notNullize(untargetedSub.getPresentableName())).withIcon(untargetedSub.getIcon(0)));
}
}
}
}
Aggregations