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

Camelcade / Perl5-IDEA / #525521563

01 Jun 2025 02:15PM UTC coverage: 82.332% (+0.04%) from 82.289%
#525521563

push

github

hurricup
Bounded wildcards

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

69 existing lines in 17 files now uncovered.

30882 of 37509 relevant lines covered (82.33%)

0.82 hits per line

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

87.72
/plugin/core/src/main/java/com/perl5/lang/perl/psi/references/PerlSubReferenceSimple.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.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.PerlPackageUtil;
33
import com.perl5.lang.perl.util.PerlSubUtil;
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.psi.mro.PerlMro.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 = PerlPackageUtil.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
  public boolean isImported() {
104
    return (FLAGS & FLAG_IMPORTED) > 0;
×
105
  }
106

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

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

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

119
  public void setDefined() {
120

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

124
  public void setXSub() {
125

126
    FLAGS |= FLAG_XSUB;
×
127
  }
×
128

129
  public void setDeclared() {
130

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

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

138
  public void setConstant() {
139

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

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

146
    resetFlags();
1✔
147

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

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

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

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

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

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

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

180

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