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

Camelcade / Perl5-IDEA / #525521855

16 Jun 2026 02:03AM UTC coverage: 76.24% (+0.06%) from 76.177%
#525521855

Pull #3220

github

web-flow
Merge ccf41d17b into 7a34dc7be
Pull Request #3220: Bump JetBrains/qodana-action from 2026.1.0 to 2026.1.3

14772 of 22542 branches covered (65.53%)

Branch coverage included in aggregate %.

31111 of 37640 relevant lines covered (82.65%)

0.83 hits per line

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

83.2
/plugin/common/src/main/java/com/perl5/lang/perl/psi/mixins/PerlVariableDeclarationElementMixin.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.mixins;
18

19
import com.intellij.lang.ASTNode;
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.search.LocalSearchScope;
24
import com.intellij.psi.search.SearchScope;
25
import com.intellij.psi.tree.IElementType;
26
import com.intellij.util.IncorrectOperationException;
27
import com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlScalarValue;
28
import com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue;
29
import com.perl5.lang.perl.idea.presentations.PerlItemPresentationSimpleDynamicLocation;
30
import com.perl5.lang.perl.psi.*;
31
import com.perl5.lang.perl.psi.properties.PerlLexicalScope;
32
import com.perl5.lang.perl.psi.stubs.variables.PerlVariableDeclarationStub;
33
import com.perl5.lang.perl.psi.utils.PerlPsiUtil;
34
import com.perl5.lang.perl.psi.utils.PerlVariableAnnotations;
35
import com.perl5.lang.perl.psi.utils.PerlVariableType;
36
import com.perl5.lang.perl.util.PerlPackageUtilCore;
37
import org.jetbrains.annotations.NotNull;
38
import org.jetbrains.annotations.Nullable;
39

40
import javax.swing.*;
41
import java.util.Objects;
42

43
import static com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValues.UNKNOWN_VALUE;
44

45
/**
46
 * Stubbed wrapper for variables declarations
47
 */
48
public class PerlVariableDeclarationElementMixin extends PerlStubBasedPsiElementBase<PerlVariableDeclarationStub>
49
  implements PerlVariableDeclarationElement {
50
  public PerlVariableDeclarationElementMixin(ASTNode node) {
51
    super(node);
1✔
52
  }
1✔
53

54
  public PerlVariableDeclarationElementMixin(@NotNull PerlVariableDeclarationStub stub, @NotNull IElementType nodeType) {
55
    super(stub, nodeType);
1✔
56
  }
1✔
57

58
  @Override
59
  public @NotNull PerlVariable getVariable() {
60
    return Objects.requireNonNull(findChildByClass(PerlVariable.class), () -> "Unable to find variable in: " + getText());
1!
61
  }
62

63
  @Override
64
  public @Nullable PsiElement getNameIdentifier() {
65
    return getVariable().getVariableNameElement();
1✔
66
  }
67

68

69
  @Override
70
  public String getVariableName() {
71
    return getName();
1✔
72
  }
73

74
  @Override
75
  public String getName() {
76
    PerlVariableDeclarationStub stub = getGreenStub();
1✔
77
    if (stub != null) {
1✔
78
      return stub.getVariableName();
1✔
79
    }
80
    return getVariable().getName();
1✔
81
  }
82

83
  @Override
84
  public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
85
    PerlPsiUtil.renameNamedElement(this, name);
1✔
86
    return this;
1✔
87
  }
88

89
  @Override
90
  public int getTextOffset() {
91
    PsiElement nameIdentifier = getNameIdentifier();
1✔
92

93
    return nameIdentifier == null
1!
94
           ? super.getTextOffset()
×
95
           : nameIdentifier.getTextOffset();
1✔
96
  }
97

98
  @Override
99
  public @Nullable String getExplicitNamespaceName() {
100
    return getVariable().getExplicitNamespaceName();
×
101
  }
102

103
  @Override
104
  public @NotNull PerlValue getDeclaredValue() {
105
    PerlValue valueFromAnnotations = PerlVariableDeclarationElement.super.getDeclaredValue();
1✔
106
    if (!valueFromAnnotations.isUnknown()) {
1✔
107
      return valueFromAnnotations;
1!
108
    }
109
    return getPsiDeclaredValue();
1!
110
  }
111

112
  public @NotNull PerlValue getPsiDeclaredValue() {
113
    PerlVariableDeclarationStub stub = getGreenStub();
1✔
114
    if (stub != null) {
1!
115
      return stub.getDeclaredValue();
×
116
    }
117
    PerlVariableDeclarationExpr declaration = getDeclarationExpression();
1✔
118
    return declaration == null ? UNKNOWN_VALUE :
1!
119
           PerlScalarValue.create(declaration.getDeclarationType());
1✔
120
  }
121

122
  @Override
123
  public @NotNull String getNamespaceName() {
124
    PerlVariableDeclarationStub stub = getGreenStub();
1✔
125
    if (stub != null) {
1✔
126
      return stub.getNamespaceName();
1!
127
    }
128
    String qualifierName = getVariable().getExplicitNamespaceName();
1✔
129
    if (StringUtil.isNotEmpty(qualifierName)) {
1!
130
      return qualifierName;
×
131
    }
132
    return PerlPackageUtilCore.getContextNamespaceName(getVariable());
1!
133
  }
134

135
  @Override
136
  public PerlVariableType getActualType() {
137
    PerlVariableDeclarationStub stub = getGreenStub();
1✔
138
    if (stub != null) {
1✔
139
      return stub.getActualType();
1✔
140
    }
141
    return getVariable().getActualType();
1✔
142
  }
143

144
  @Override
145
  public @NotNull SearchScope getUseScope() {
146
    if (isLexicalDeclaration()) {
1✔
147
      PsiElement lexicalScope = PerlLexicalScope.from(this);
1✔
148
      if (lexicalScope instanceof PerlSubDefinition) {
1✔
149
        lexicalScope = getContainingFile();
1✔
150
      }
151
      else if (lexicalScope instanceof PerlForeachCompound) {
1✔
152
        lexicalScope = PerlLexicalScope.from(lexicalScope);
1✔
153
      }
154
      if (lexicalScope != null) {
1!
155
        return new LocalSearchScope(lexicalScope);
1✔
156
      }
157
    }
158

159
    return super.getUseScope();
1!
160
  }
161

162
  @Override
163
  public boolean isLexicalDeclaration() {
164
    if (getGreenStub() != null) {
1✔
165
      return false;
1✔
166
    }
167
    PsiElement parent = getParent();
1✔
168
    return parent instanceof PerlLexicalVariableDeclarationMarker ||
1✔
169
           isInvocantDeclaration() || isLocalDeclaration();
1✔
170
  }
171

172
  @Override
173
  public boolean isInvocantDeclaration() {
174
    return getParent() instanceof PsiPerlMethodSignatureInvocant;
1✔
175
  }
176

177
  @Override
178
  public boolean isLocalDeclaration() {
179
    return getParent() instanceof PsiPerlVariableDeclarationLocal;
1✔
180
  }
181

182
  @Override
183
  public boolean isGlobalDeclaration() {
184
    return !isLexicalDeclaration();
1✔
185
  }
186

187
  @Override
188
  public ItemPresentation getPresentation() {
189
    return new PerlItemPresentationSimpleDynamicLocation(this, getName());
1✔
190
  }
191

192

193
  @Override
194
  public @Nullable Icon getIcon(int flags) {
195
    Icon iconByType = getIconByType(getActualType());
1✔
196
    return iconByType == null ? super.getIcon(flags) : iconByType;
1!
197
  }
198

199
  @Override
200
  public @Nullable PerlVariableAnnotations getVariableAnnotations() {
201
    PerlVariableAnnotations variableAnnotations;
202

203
    PerlVariableDeclarationStub stub = getGreenStub();
1✔
204
    variableAnnotations = stub != null ? stub.getVariableAnnotations() : getLocalVariableAnnotations();
1✔
205

206
    if (!variableAnnotations.isEmpty()) {
1✔
207
      return variableAnnotations;
1✔
208
    }
209

210
    return null;
1✔
211
  }
212

213
  @Override
214
  public @NotNull PerlVariableAnnotations getLocalVariableAnnotations() {
215
    return PerlVariableAnnotations.from(this);
1!
216
  }
217
}
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