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

Camelcade / Perl5-IDEA / #525521824

24 Apr 2026 06:38PM UTC coverage: 76.187% (+0.2%) from 75.952%
#525521824

push

github

hurricup
Pass a disposable to Registry.get to revert it in the end

14757 of 22542 branches covered (65.46%)

Branch coverage included in aggregate %.

31096 of 37643 relevant lines covered (82.61%)

0.83 hits per line

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

84.62
/plugin/common/src/main/java/com/perl5/lang/perl/psi/impl/PerlPolyNamedElement.java
1
/*
2
 * Copyright 2015-2026 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.psi.impl;
18

19
import com.intellij.codeInsight.daemon.impl.Divider;
20
import com.intellij.lang.ASTNode;
21
import com.intellij.psi.PsiElement;
22
import com.intellij.psi.PsiElementVisitor;
23
import com.intellij.psi.ResolveState;
24
import com.intellij.psi.StubBasedPsiElement;
25
import com.intellij.psi.scope.PsiScopeProcessor;
26
import com.intellij.psi.stubs.StubBuildCachedValuesManager.StubBuildCachedValueProvider;
27
import com.intellij.psi.tree.IElementType;
28
import com.intellij.psi.util.CachedValueProvider;
29
import com.intellij.psi.util.PsiUtilCore;
30
import com.perl5.lang.perl.parser.elementTypes.PerlReparseableElementType;
31
import com.perl5.lang.perl.psi.PerlStubBasedPsiElementBase;
32
import com.perl5.lang.perl.psi.PerlVisitor;
33
import com.perl5.lang.perl.psi.light.PerlDelegatingLightNamedElement;
34
import com.perl5.lang.perl.psi.stubs.PerlPolyNamedElementStub;
35
import org.jetbrains.annotations.Contract;
36
import org.jetbrains.annotations.NotNull;
37
import org.jetbrains.annotations.Nullable;
38

39
import java.util.List;
40

41
import static com.intellij.psi.stubs.StubBuildCachedValuesManager.getCachedValueStubBuildOptimized;
42
import static com.perl5.lang.perl.parser.PerlElementTypesGenerated.*;
43

44
public abstract class PerlPolyNamedElement<Stub extends PerlPolyNamedElementStub<?>> extends PerlStubBasedPsiElementBase<Stub>
45
  implements StubBasedPsiElement<Stub> {
46
  private static final StubBuildCachedValueProvider<List<? extends PerlDelegatingLightNamedElement<?>>, PerlPolyNamedElement<?>> PROVIDER =
1✔
47
    new StubBuildCachedValueProvider<>(
48
      "perl.light.elements",
49
      polyNamedElement -> CachedValueProvider.Result.create(polyNamedElement.computeLightElements(), polyNamedElement)
1✔
50
    );
51

52
  public PerlPolyNamedElement(@NotNull Stub stub, @NotNull IElementType nodeType) {
53
    super(stub, nodeType);
1✔
54
  }
1✔
55

56
  public PerlPolyNamedElement(@NotNull ASTNode node) {
57
    super(node);
1✔
58
  }
1✔
59

60
  public final @NotNull List<? extends PerlDelegatingLightNamedElement<?>> getLightElements() {
61
    return getCachedValueStubBuildOptimized(this, PROVIDER);
1!
62
  }
63

64
  /**
65
   * Calculates light elements from stubs or psi
66
   */
67
  public final @NotNull List<? extends PerlDelegatingLightNamedElement<?>> computeLightElements() {
68
    Stub stub = getGreenStub();
1✔
69
    if (stub != null) {
1✔
70
      return computeLightElementsFromStubs(stub);
1!
71
    }
72
    return computeLightElementsFromPsi();
1!
73
  }
74

75
  /**
76
   * Internal sub for calculating light elements from psi
77
   */
78
  public abstract @NotNull List<? extends PerlDelegatingLightNamedElement<?>> computeLightElementsFromPsi();
79

80
  /**
81
   * Internal sub for calculating light elements from stubs
82
   */
83
  protected abstract @NotNull List<? extends PerlDelegatingLightNamedElement<?>> computeLightElementsFromStubs(@NotNull Stub stub);
84

85
  /**
86
   * @implNote we need to accept light elements here, because in non-recursive visitors case, platform collects elements by itself by
87
   * traversing the tree
88
   * @see LocalInspectionsPass#inspect(java.util.List, com.intellij.codeInspection.InspectionManager, boolean, com.intellij.openapi.progress.ProgressIndicator)
89
   * @see Divider#divideInsideAndOutsideInOneRoot(com.intellij.psi.PsiFile, com.intellij.openapi.util.TextRange, com.intellij.openapi.util.TextRange, java.util.List, java.util.List, java.util.List, java.util.List, java.util.List, java.util.List, boolean)
90
   */
91
  @Override
92
  public void accept(@NotNull PsiElementVisitor visitor) {
93
    if (visitor instanceof PerlVisitor perlVisitor) {
1!
94
      perlVisitor.visitPolyNamedElement(this);
×
95
    }
96
    else {
97
      super.accept(visitor);
1✔
98
    }
99
  }
1✔
100

101
  @Override
102
  public boolean processDeclarations(@NotNull PsiScopeProcessor processor,
103
                                     @NotNull ResolveState state,
104
                                     PsiElement lastParent,
105
                                     @NotNull PsiElement place) {
106
    for (PerlDelegatingLightNamedElement<?> namedElement : getLightElements()) {
1✔
107
      if (!processor.execute(namedElement, state)) {
1!
108
        return false;
×
109
      }
110
    }
1✔
111

112
    return super.processDeclarations(processor, state, lastParent, place);
1✔
113
  }
114

115
  /**
116
   * Checks if we can treat this element as text identifier. Atm: no interpolation, no XQ strings
117
   */
118
  @Contract("null->false")
119
  public boolean isAcceptableIdentifierElement(@Nullable PsiElement identifierElement) {
120
    if (identifierElement == null) {
1!
121
      return false;
×
122
    }
123
    IElementType elementType = PsiUtilCore.getElementType(identifierElement);
1✔
124
    if (elementType == STRING_BARE || elementType == STRING_SQ || elementType == STRING_CONTENT) {
1!
125
      return true;
1✔
126
    }
127
    else if (elementType == STRING_XQ) {
1✔
128
      return false;
1✔
129
    }
130
    else if (elementType == STRING_DQ) {
1✔
131
      PsiElement[] children = identifierElement.getChildren();
1✔
132
      if (children.length == 1 && PsiUtilCore.getElementType(children[0]) instanceof PerlReparseableElementType) {
1✔
133
        children = children[0].getChildren();
1✔
134
      }
135
      return children.length == 0;
1✔
136
    }
137
    return false;
1✔
138
  }
139
}
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