• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Camelcade / Perl5-IDEA / #525521553

27 May 2025 10:24AM UTC coverage: 82.286% (-0.03%) from 82.32%
#525521553

push

github

hurricup
Removed redundant implementations, moved up to the abstract class

1 of 1 new or added line in 1 file covered. (100.0%)

128 existing lines in 30 files now uncovered.

30886 of 37535 relevant lines covered (82.29%)

0.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/plugin/core/src/main/java/com/perl5/lang/pod/idea/completion/PodTitleCompletionProvider.java
1
/*
2
 * Copyright 2015-2025 Alexandr Evstigneev
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package com.perl5.lang.pod.idea.completion;
18

19
import com.intellij.codeInsight.completion.CompletionParameters;
20
import com.intellij.codeInsight.completion.CompletionProvider;
21
import com.intellij.codeInsight.completion.CompletionResultSet;
22
import com.intellij.codeInsight.lookup.LookupElementBuilder;
23
import com.intellij.openapi.util.text.StringUtil;
24
import com.intellij.psi.PsiElement;
25
import com.intellij.psi.PsiFile;
26
import com.intellij.psi.ResolveResult;
27
import com.intellij.psi.tree.IElementType;
28
import com.intellij.psi.util.PsiUtilCore;
29
import com.intellij.util.ProcessingContext;
30
import com.perl5.lang.perl.idea.completion.providers.processors.PerlSimpleCompletionProcessor;
31
import com.perl5.lang.perl.psi.PerlSubElement;
32
import com.perl5.lang.perl.psi.utils.PerlPsiUtil;
33
import com.perl5.lang.pod.parser.PodElementPatterns;
34
import com.perl5.lang.pod.parser.psi.PodRecursiveVisitor;
35
import com.perl5.lang.pod.parser.psi.PodSectionTitle;
36
import com.perl5.lang.pod.parser.psi.PodTitledSection;
37
import com.perl5.lang.pod.parser.psi.references.PodSubReference;
38
import com.perl5.lang.pod.parser.psi.util.PodFileUtil;
39
import org.jetbrains.annotations.NotNull;
40

41
import java.util.Arrays;
42
import java.util.HashSet;
43
import java.util.List;
44
import java.util.Set;
45

46
public class PodTitleCompletionProvider extends CompletionProvider<CompletionParameters> implements PodElementPatterns {
1✔
47
  public static final String COPYRIGHT_AND_LICENSE = "COPYRIGHT AND LICENSE";
48
  public static final List<String> DEFAULT_POD_SECTIONS =
1✔
49
    List.of("VERSION", "SYNOPSIS", "API", "DESCRIPTION", "INSTALLATION", "NAME", "AUTHORS", "CONTRIBUTORS", COPYRIGHT_AND_LICENSE,
1✔
50
            "METHODS", "ATTRIBUTES", "FUNCTIONS");
51

52
  @Override
53
  protected void addCompletions(@NotNull CompletionParameters parameters,
54
                                @NotNull ProcessingContext context,
55
                                @NotNull CompletionResultSet result) {
56
    PsiElement element = parameters.getPosition();
1✔
57

58
    PsiElement elementParent = element.getParent();
1✔
59
    if (PsiUtilCore.getElementType(element) != POD_IDENTIFIER ||
1✔
60
        element.getPrevSibling() != null ||
1✔
61
        !(elementParent instanceof PodSectionTitle)) {
UNCOV
62
      return;
×
63
    }
64

65
    IElementType grandparentElementType = PsiUtilCore.getElementType(elementParent.getParent());
1✔
66
    PerlSimpleCompletionProcessor completionProcessor = new PerlSimpleCompletionProcessor(parameters, result, element);
1✔
67

68
    if (grandparentElementType == HEAD_1_SECTION) {
1✔
69
      for (String sectionTitle : DEFAULT_POD_SECTIONS) {
1✔
70
        if (completionProcessor.matches(sectionTitle) && !completionProcessor.process(LookupElementBuilder.create(sectionTitle))) {
1✔
UNCOV
71
          break;
×
72
        }
73
      }
1✔
74
    }
75

76
    final PsiFile elementFile = element.getContainingFile().getOriginalFile();
1✔
77
    final PsiFile perlFile = PodFileUtil.getTargetPerlFile(elementFile);
1✔
78
    if (perlFile == null) {
1✔
79
      return;
1✔
80
    }
81

82
    Set<PerlSubElement> possibleTargets = new HashSet<>();
1✔
83
    PerlPsiUtil.processSubElements(perlFile, possibleTargets::add);
1✔
84
    elementFile.accept(new PodRecursiveVisitor() {
1✔
85
      @Override
86
      public void visitTargetableSection(PodTitledSection o) {
87
        processSection(o);
1✔
88
        super.visitTargetableSection(o);
1✔
89
      }
1✔
90

91
      private void processSection(@NotNull PodTitledSection o) {
92
        PsiElement titleBlock = o.getTitleElement();
1✔
93
        if (titleBlock == null) {
1✔
94
          return;
1✔
95
        }
96
        PsiElement firstChild = titleBlock.getFirstChild();
1✔
97
        if (firstChild == null) {
1✔
98
          return;
1✔
99
        }
100
        //noinspection SuspiciousMethodCalls
101
        Arrays.stream(firstChild.getReferences())
1✔
102
          .filter(it -> it instanceof PodSubReference)
1✔
103
          .flatMap(it -> Arrays.stream(((PodSubReference)it).multiResolve(false)))
1✔
104
          .map(ResolveResult::getElement)
1✔
105
          .forEach(possibleTargets::remove);
1✔
106
      }
1✔
107
    });
108

109
    for (PerlSubElement subElement : possibleTargets) {
1✔
110
      String lookupString = StringUtil.notNullize(subElement.getPresentableName());
1✔
111
      if (completionProcessor.matches(lookupString) &&
1✔
112
          !completionProcessor.process(LookupElementBuilder.create(subElement, lookupString).withIcon(subElement.getIcon(0)))) {
1✔
UNCOV
113
        break;
×
114
      }
115
    }
1✔
116
    completionProcessor.logStatus(getClass());
1✔
117
  }
1✔
118
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc