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

Camelcade / Perl5-IDEA / #525521819

12 Apr 2026 11:03AM UTC coverage: 76.189% (+0.1%) from 76.061%
#525521819

push

github

hurricup
[qodana] Suppressed a warning on the api method

14764 of 22542 branches covered (65.5%)

Branch coverage included in aggregate %.

31091 of 37644 relevant lines covered (82.59%)

0.83 hits per line

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

82.24
/plugin/backend/src/main/java/com/perl5/lang/perl/psi/references/PerlSubReferenceSimple.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.references;
18

19
import com.intellij.openapi.project.Project;
20
import com.intellij.openapi.util.TextRange;
21
import com.intellij.psi.PsiElement;
22
import com.intellij.psi.PsiElementResolveResult;
23
import com.intellij.psi.ResolveResult;
24
import com.intellij.util.IncorrectOperationException;
25
import com.perl5.lang.perl.extensions.PerlRenameUsagesHelper;
26
import com.perl5.lang.perl.parser.constant.psi.light.PerlLightConstantDefinitionElement;
27
import com.perl5.lang.perl.psi.PerlGlobVariableElement;
28
import com.perl5.lang.perl.psi.PerlSubDeclarationElement;
29
import com.perl5.lang.perl.psi.PerlSubDefinitionElement;
30
import com.perl5.lang.perl.psi.PerlSubElement;
31
import com.perl5.lang.perl.psi.properties.PerlIdentifierOwner;
32
import com.perl5.lang.perl.util.PerlPackageUtilCore;
33
import com.perl5.lang.perl.util.PerlSubUtilCore;
34
import org.jetbrains.annotations.NotNull;
35

36
import java.util.ArrayList;
37
import java.util.Collection;
38
import java.util.List;
39

40
import static com.perl5.lang.perl.util.PerlMroUtil.collectCallables;
41

42
/**
43
 * Basic class for sub reference. Uses context package to resolve. Used in string contents, moose, etc.
44
 */
45
public class PerlSubReferenceSimple extends PerlCachingReference<PsiElement> {
46
  protected static final int FLAG_AUTOLOADED = 1;
47
  protected static final int FLAG_CONSTANT = 2;
48
  protected static final int FLAG_DECLARED = 4;
49
  protected static final int FLAG_DEFINED = 8;
50
  protected static final int FLAG_ALIASED = 16;
51
  protected static final int FLAG_IMPORTED = 32;    // fixme this is not set anyway
52
  protected static final int FLAG_XSUB = 64;
53

54
  protected int FLAGS = 0;
1✔
55

56
  public PerlSubReferenceSimple(PsiElement psiElement) {
57
    super(psiElement);
1✔
58
  }
1✔
59

60
  public PerlSubReferenceSimple(@NotNull PsiElement element, TextRange textRange) {
61
    super(element, textRange);
1✔
62
  }
1✔
63

64
  @Override
65
  protected @NotNull ResolveResult[] resolveInner(boolean incompleteCode) {
66
    // fixme not dry with super resolver, need some generics fix
67
    PsiElement element = getElement();
1✔
68

69
    String packageName = PerlPackageUtilCore.getContextNamespaceName(element);
1✔
70
    String subName = element.getNode().getText();
1✔
71
    Project project = element.getProject();
1✔
72

73
    var result = getResolveResults(collectCallables(
1✔
74
      project, element.getResolveScope(),
1✔
75
      packageName,
76
      subName,
77
      false
78
    ));
79

80
    return result.toArray(ResolveResult.EMPTY_ARRAY);
1!
81
  }
82

83
  public boolean isAutoloaded() {
84
    return (FLAGS & FLAG_AUTOLOADED) > 0;
1!
85
  }
86

87
  public boolean isDefined() {
88
    return (FLAGS & FLAG_DEFINED) > 0;
1✔
89
  }
90

91
  public boolean isDeclared() {
92
    return (FLAGS & FLAG_DECLARED) > 0;
1✔
93
  }
94

95
  public boolean isAliased() {
96
    return (FLAGS & FLAG_ALIASED) > 0;
1✔
97
  }
98

99
  public boolean isConstant() {
100
    return (FLAGS & FLAG_CONSTANT) > 0;
1✔
101
  }
102

103
  @SuppressWarnings("unused")
104
  public boolean isImported() {
105
    return (FLAGS & FLAG_IMPORTED) > 0;
×
106
  }
107

108
  public boolean isXSub() {
109
    return (FLAGS & FLAG_XSUB) > 0;
1!
110
  }
111

112
  public void resetFlags() {
113
    FLAGS = 0;
1✔
114
  }
1✔
115

116
  public void setAutoloaded() {
117
    FLAGS |= FLAG_AUTOLOADED;
×
118
  }
×
119

120
  public void setDefined() {
121

122
    FLAGS |= FLAG_DEFINED;
1✔
123
  }
1✔
124

125
  public void setXSub() {
126

127
    FLAGS |= FLAG_XSUB;
×
128
  }
×
129

130
  public void setDeclared() {
131

132
    FLAGS |= FLAG_DECLARED;
1✔
133
  }
1✔
134

135
  public void setAliased() {
136
    FLAGS |= FLAG_ALIASED;
1✔
137
  }
1✔
138

139
  public void setConstant() {
140

141
    FLAGS |= FLAG_CONSTANT;
1✔
142
  }
1✔
143

144
  public @NotNull List<ResolveResult> getResolveResults(Collection<? extends PsiElement> relatedItems) {
145
    List<ResolveResult> result = new ArrayList<>();
1✔
146

147
    resetFlags();
1✔
148

149
    for (PsiElement element : relatedItems) {
1✔
150
      if (!isAutoloaded() &&
1!
151
          element instanceof PerlIdentifierOwner identifierOwner &&
1✔
152
          PerlSubUtilCore.SUB_AUTOLOAD.equals(identifierOwner.getName())) {
1!
153
        setAutoloaded();
×
154
      }
155

156
      if (!isConstant() && element instanceof PerlLightConstantDefinitionElement) {
1!
157
        setConstant();
1✔
158
      }
159

160
      if (!isDeclared() && element instanceof PerlSubDeclarationElement) {
1✔
161
        setDeclared();
1✔
162
      }
163

164
      if (!isDefined() && element instanceof PerlSubDefinitionElement) {
1✔
165
        setDefined();
1✔
166
      }
167

168
      if (!isXSub() && element instanceof PerlSubElement perlSubElement && perlSubElement.isXSub()) {
1!
169
        setXSub();
×
170
      }
171

172
      if (!isAliased() && element instanceof PerlGlobVariableElement) {
1✔
173
        setAliased();
1✔
174
      }
175

176
      result.add(new PsiElementResolveResult(element));
1✔
177
    }
1✔
178
    return result;
1!
179
  }
180

181

182
  @Override
183
  public PsiElement handleElementRename(@NotNull String newElementName) throws IncorrectOperationException {
184
    PsiElement target = resolve();
1✔
185
    if (target instanceof PerlRenameUsagesHelper renameUsagesHelper) {
1✔
186
      newElementName = renameUsagesHelper.getSubstitutedUsageName(newElementName, myElement);
1✔
187
    }
188
    return super.handleElementRename(newElementName);
1✔
189
  }
190
}
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