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

Camelcade / Perl5-IDEA / #525521547

24 May 2025 10:39AM UTC coverage: 82.232% (-0.09%) from 82.324%
#525521547

push

github

hurricup
Got rid of ContainerUtil.immutableList usages

4 of 4 new or added lines in 3 files covered. (100.0%)

52 existing lines in 15 files now uncovered.

30870 of 37540 relevant lines covered (82.23%)

0.82 hits per line

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

82.98
/plugin/core/src/main/java/com/perl5/lang/perl/idea/ui/breadcrumbs/PerlBreadcrumbsProvider.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.perl.idea.ui.breadcrumbs;
18

19
import com.intellij.lang.Language;
20
import com.intellij.navigation.ItemPresentation;
21
import com.intellij.openapi.util.text.StringUtil;
22
import com.intellij.psi.PsiElement;
23
import com.intellij.psi.PsiFile;
24
import com.intellij.psi.util.PsiTreeUtil;
25
import com.intellij.ui.breadcrumbs.BreadcrumbsProvider;
26
import com.perl5.lang.perl.PerlLanguage;
27
import com.perl5.lang.perl.psi.*;
28
import com.perl5.lang.perl.psi.impl.PerlPolyNamedElement;
29
import com.perl5.lang.perl.psi.light.PerlDelegatingLightNamedElement;
30
import com.perl5.lang.perl.psi.properties.PerlBlockOwner;
31
import org.jetbrains.annotations.NotNull;
32
import org.jetbrains.annotations.Nullable;
33

34
import javax.swing.*;
35
import java.util.Objects;
36

37
public class PerlBreadcrumbsProvider implements BreadcrumbsProvider {
1✔
38

39
  @Override
40
  public Language[] getLanguages() {
41
    return PerlLanguage.ARRAY;
1✔
42
  }
43

44
  @Override
45
  public boolean acceptElement(@NotNull PsiElement element) {
46
    return element instanceof PerlFile ||
1✔
47
           element instanceof PerlMethodModifier ||
48
           element instanceof PerlSubDefinitionElement subDefinitionElement && subDefinitionElement.getSubName() != null ||
1✔
49
           element instanceof PerlSubExpr && (!(element.getParent() instanceof PerlBlockOwner)) ||
1✔
50
           element instanceof PerlNamespaceDefinitionElement namespaceDefinitionElement &&
1✔
51
           namespaceDefinitionElement.getNamespaceName() != null;
1✔
52
  }
53

54
  @Override
55
  public @Nullable PsiElement getParent(@NotNull PsiElement element) {
56
    PsiElement structuralParent = getStructuralParentElement(element);
1✔
57
    return structuralParent instanceof PsiFile ? null : structuralParent;
1✔
58
  }
59

60
  public static @Nullable PsiElement getStructuralParentElement(@NotNull PsiElement element) {
61
    switch (element) {
1✔
62
      case PerlFile ignored -> {
×
UNCOV
63
        return null;
×
64
      }
65
      case PerlNamespaceDefinitionElement namespaceDefinition -> {
1✔
66
        return namespaceDefinition.getContainingFile();
1✔
67
      }
68
      case PerlSubDefinitionElement subDefinition -> {
1✔
69
        return PsiTreeUtil.getParentOfType(subDefinition, PerlNamespaceDefinitionElement.class);
1✔
70
      }
71
      default -> {
72
      }
73
    }
74

75
    PsiElement nearestParent =
1✔
76
      PsiTreeUtil.getParentOfType(element,
1✔
77
                                  PerlSubDefinitionElement.class,
78
                                  PerlNamespaceDefinitionElement.class,
79
                                  PerlMethodModifier.class,
80
                                  PerlSubExpr.class);
81
    if (nearestParent == null ||
1✔
82
        nearestParent instanceof PerlMethodModifier ||
83
        nearestParent instanceof PerlSubDefinitionElement ||
84
        nearestParent instanceof PerlNamespaceDefinitionElement) {
85
      return nearestParent;
1✔
86
    }
87

88
    PsiPerlBlock exprBlock = ((PerlSubExpr)nearestParent).getBlock();
1✔
89
    if (exprBlock == null) {
1✔
UNCOV
90
      return getStructuralParentElement(nearestParent.getParent());
×
91
    }
92

93
    PerlPolyNamedElement<?> polyNamedElement = PsiTreeUtil.getParentOfType(nearestParent, PerlPolyNamedElement.class);
1✔
94
    if (polyNamedElement != null) {
1✔
95
      for (PerlDelegatingLightNamedElement<?> lightNamedElement : polyNamedElement.getLightElements()) {
1✔
96
        if (lightNamedElement instanceof PerlSubDefinitionElement subDefinitionElement &&
1✔
97
            exprBlock.equals(subDefinitionElement.getSubDefinitionBody())) {
1✔
98
          return lightNamedElement;
1✔
99
        }
UNCOV
100
      }
×
101
    }
102
    return nearestParent;
1✔
103
  }
104

105
  @Override
106
  public @Nullable Icon getElementIcon(@NotNull PsiElement element) {
107
    return element.getIcon(0);
1✔
108
  }
109

110
  @Override
111
  public @NotNull String getElementInfo(@NotNull PsiElement element) {
112
    switch (element) {
1✔
113
      case PerlFile file -> {
×
UNCOV
114
        return file.getName();
×
115
      }
116
      case PerlSubDefinitionElement subDefinition -> {
1✔
117
        return subDefinition.getSubName() + "()";
1✔
118
      }
119
      case PerlNamespaceDefinitionElement namespaceDefinition -> {
1✔
120
        return Objects.requireNonNull(namespaceDefinition.getNamespaceName());
1✔
121
      }
122
      case PerlMethodModifier methodModifier -> {
1✔
123
        ItemPresentation presentation = methodModifier.getPresentation();
1✔
124
        if (presentation != null) {
1✔
125
          return StringUtil.notNullize(presentation.getPresentableText());
1✔
126
        }
UNCOV
127
      }
×
128
      case PerlSubExpr ignored -> {
1✔
129
        return "sub()";
1✔
130
      }
131
      default -> {
132
      }
133
    }
UNCOV
134
    throw new RuntimeException("Can't happen: " + element);
×
135
  }
136
}
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