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

Camelcade / Perl5-IDEA / #525521623

10 Jul 2025 02:30PM UTC coverage: 82.367% (-0.01%) from 82.377%
#525521623

push

github

hurricup
[Qodana] Fixed some offenses, disabled implicit this inspection

14 of 16 new or added lines in 9 files covered. (87.5%)

12 existing lines in 6 files now uncovered.

30924 of 37544 relevant lines covered (82.37%)

0.82 hits per line

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

90.32
/plugin/backend/src/main/java/com/perl5/lang/perl/psi/impl/PerlPolyNamedElement.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.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.tree.IElementType;
27
import com.intellij.psi.util.CachedValueProvider;
28
import com.intellij.psi.util.CachedValuesManager;
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.perl5.lang.perl.parser.PerlElementTypesGenerated.*;
42

43
public abstract class PerlPolyNamedElement<Stub extends PerlPolyNamedElementStub<?>> extends PerlStubBasedPsiElementBase<Stub>
44
  implements StubBasedPsiElement<Stub> {
45
  public PerlPolyNamedElement(@NotNull Stub stub, @NotNull IElementType nodeType) {
46
    super(stub, nodeType);
1✔
47
  }
1✔
48

49
  public PerlPolyNamedElement(@NotNull ASTNode node) {
50
    super(node);
1✔
51
  }
1✔
52

53
  public final @NotNull List<? extends PerlDelegatingLightNamedElement<?>> getLightElements() {
54
    return CachedValuesManager.getCachedValue(this, () -> CachedValueProvider.Result.create(computeLightElements(), this)
1✔
55
    );
56
  }
57

58
  /**
59
   * Calculates light elements from stubs or psi
60
   */
61
  public final @NotNull List<? extends PerlDelegatingLightNamedElement<?>> computeLightElements() {
62
    Stub stub = getGreenStub();
1✔
63
    if (stub != null) {
1✔
64
      return computeLightElementsFromStubs(stub);
1✔
65
    }
66
    return computeLightElementsFromPsi();
1✔
67
  }
68

69
  /**
70
   * Internal sub for calculating light elements from psi
71
   */
72
  public abstract @NotNull List<? extends PerlDelegatingLightNamedElement<?>> computeLightElementsFromPsi();
73

74
  /**
75
   * Internal sub for calculating light elements from stubs
76
   */
77
  protected abstract @NotNull List<? extends PerlDelegatingLightNamedElement<?>> computeLightElementsFromStubs(@NotNull Stub stub);
78

79
  /**
80
   * @implNote we need to accept light elements here, because in non-recursive visitors case, platform collects elements by itself by
81
   * traversing the tree
82
   * @see LocalInspectionsPass#inspect(java.util.List, com.intellij.codeInspection.InspectionManager, boolean, com.intellij.openapi.progress.ProgressIndicator)
83
   * @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)
84
   */
85
  @Override
86
  public void accept(@NotNull PsiElementVisitor visitor) {
87
    if (visitor instanceof PerlVisitor perlVisitor) {
1✔
UNCOV
88
      perlVisitor.visitPolyNamedElement(this);
×
89
    }
90
    else {
91
      super.accept(visitor);
1✔
92
    }
93
  }
1✔
94

95
  @Override
96
  public boolean processDeclarations(@NotNull PsiScopeProcessor processor,
97
                                     @NotNull ResolveState state,
98
                                     PsiElement lastParent,
99
                                     @NotNull PsiElement place) {
100
    for (PerlDelegatingLightNamedElement<?> namedElement : getLightElements()) {
1✔
101
      if (!processor.execute(namedElement, state)) {
1✔
UNCOV
102
        return false;
×
103
      }
104
    }
1✔
105

106
    return super.processDeclarations(processor, state, lastParent, place);
1✔
107
  }
108

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