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

Camelcade / Perl5-IDEA / #525521510

17 Apr 2025 02:29PM UTC coverage: 82.177% (-0.5%) from 82.723%
#525521510

push

github

hurricup
Do not update asdf for CI

They are using "awesome" stub and polluting stdout of the process with their update notification

https://github.com/asdf-vm/asdf/pull/1833

30814 of 37497 relevant lines covered (82.18%)

0.82 hits per line

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

64.36
/plugin/core/src/main/java/com/perl5/lang/perl/psi/impl/PerlImplicitVariableDeclaration.java
1
/*
2
 * Copyright 2015-2024 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.openapi.editor.Document;
20
import com.intellij.psi.*;
21
import com.intellij.psi.stubs.IStubElementType;
22
import com.intellij.util.IncorrectOperationException;
23
import com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlScalarValue;
24
import com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue;
25
import com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValues;
26
import com.perl5.lang.perl.psi.*;
27
import com.perl5.lang.perl.psi.mixins.PerlMethodDefinitionMixin;
28
import com.perl5.lang.perl.psi.stubs.variables.PerlVariableDeclarationStub;
29
import com.perl5.lang.perl.psi.utils.PerlVariableAnnotations;
30
import com.perl5.lang.perl.psi.utils.PerlVariableType;
31
import com.perl5.lang.perl.util.PerlPackageUtil;
32
import org.jetbrains.annotations.NonNls;
33
import org.jetbrains.annotations.NotNull;
34
import org.jetbrains.annotations.Nullable;
35

36
import javax.swing.*;
37
import java.util.Collections;
38
import java.util.List;
39

40

41
public class PerlImplicitVariableDeclaration extends PerlImplicitElement
42
  implements PerlVariable, PerlVariableNameElement, PerlVariableDeclarationElement {
43
  protected final PerlVariableType myVariableType;
44
  protected final @NotNull String myVariableName;
45
  protected final @NotNull PerlValue myDeclaredValue;
46
  protected final @Nullable String myNamespaceName;
47

48
  protected final boolean myIsLexical;
49
  protected final boolean myIsLocal;
50
  protected final boolean myIsInvocant;
51

52
  protected PerlImplicitVariableDeclaration(@NotNull PsiManager manager,
53
                                            @NotNull String variableNameWithSigil,
54
                                            @Nullable String namespaceName,
55
                                            @NotNull PerlValue variableValue,
56
                                            boolean isLexical,
57
                                            boolean isLocal,
58
                                            boolean isInvocant,
59
                                            @Nullable PsiElement parent) {
60
    this(manager,
1✔
61
         computeTypeFromNameWithSigil(variableNameWithSigil),
1✔
62
         variableNameWithSigil.substring(1),
1✔
63
         namespaceName,
64
         variableValue,
65
         isLexical,
66
         isLocal,
67
         isInvocant,
68
         parent);
69
  }
1✔
70

71
  protected PerlImplicitVariableDeclaration(@NotNull PsiManager manager,
72
                                            @NotNull PerlVariableType type,
73
                                            @NotNull String variableName,
74
                                            @Nullable String namespaceName,
75
                                            @NotNull PerlValue variableValue,
76
                                            boolean isLexical,
77
                                            boolean isLocal,
78
                                            boolean isInvocant,
79
                                            @Nullable PsiElement parent) {
80
    super(manager, parent);
1✔
81
    myVariableType = type;
1✔
82
    myVariableName = variableName;
1✔
83
    myDeclaredValue = variableValue;
1✔
84
    myIsLexical = isLexical;
1✔
85
    myIsLocal = isLocal;
1✔
86
    myIsInvocant = isInvocant;
1✔
87
    myNamespaceName = namespaceName;
1✔
88
  }
1✔
89

90
  private static PerlVariableType computeTypeFromNameWithSigil(@NotNull String variableNameWithSigil) {
91
    if (variableNameWithSigil.startsWith("$")) {
1✔
92
      return PerlVariableType.SCALAR;
1✔
93
    }
94
    else if (variableNameWithSigil.startsWith("@")) {
1✔
95
      return PerlVariableType.ARRAY;
1✔
96
    }
97
    else if (variableNameWithSigil.startsWith("%")) {
1✔
98
      return PerlVariableType.HASH;
1✔
99
    }
100
    else if (variableNameWithSigil.startsWith("*")) {
1✔
101
      return PerlVariableType.GLOB;
1✔
102
    }
103
    throw new RuntimeException("Incorrect variable name, should start from sigil: " + variableNameWithSigil);
×
104
  }
105

106
  @Override
107
  public void accept(@NotNull PsiElementVisitor visitor) {
108
    if (visitor instanceof PerlVisitor perlVisitor) {
1✔
109
      perlVisitor.visitPerlVariableDeclarationElement(this);
1✔
110
    }
111
    else {
112
      visitor.visitElement(this);
×
113
    }
114
  }
1✔
115

116
  @Override
117
  public final @NotNull String getNamespaceName() {
118
    String explicitPackageName = this.getExplicitNamespaceName();
1✔
119
    return explicitPackageName != null ? explicitPackageName : PerlPackageUtil.getContextNamespaceName(this);
1✔
120
  }
121

122
  @Override
123
  public @Nullable String getExplicitNamespaceName() {
124
    return myNamespaceName;
1✔
125
  }
126

127
  @Override
128
  public String toString() {
129
    return "Implicit variable: " + getVariableType().getSigil() + getCanonicalName() + '@' + getDeclaredValue();
1✔
130
  }
131

132
  @Override
133
  public @NotNull PerlValue getDeclaredValue() {
134
    return myDeclaredValue;
1✔
135
  }
136

137
  @Override
138
  public @NotNull PerlVariableType getActualType() {
139
    return getVariableType();
1✔
140
  }
141

142
  @Override
143
  public PerlVariableDeclarationElement getLexicalDeclaration() {
144
    return null;
×
145
  }
146

147
  @Override
148
  public @NotNull List<PerlVariableDeclarationElement> getGlobalDeclarations() {
149
    return Collections.emptyList();
1✔
150
  }
151

152
  @Override
153
  public @NotNull List<PerlGlobVariableElement> getRelatedGlobs() {
154
    return Collections.emptyList();
1✔
155
  }
156

157
  @Override
158
  public int getLineNumber() {
159
    PsiFile file = getContainingFile();
1✔
160
    if (file == null) {
1✔
161
      return 0;
1✔
162
    }
163
    Document document = PsiDocumentManager.getInstance(getProject()).getCachedDocument(file);
×
164
    return document == null ? 0 : document.getLineNumber(getTextOffset()) + 1;
×
165
  }
166

167
  @Override
168
  public PerlVariableNameElement getVariableNameElement() {
169
    return this;
×
170
  }
171

172
  @Override
173
  public boolean isBuiltIn() {
174
    return false;
×
175
  }
176

177
  @Override
178
  public boolean isDeprecated() {
179
    return false;
1✔
180
  }
181

182
  public PerlVariableType getVariableType() {
183
    return myVariableType;
1✔
184
  }
185

186
  @Override
187
  public @NotNull String getVariableName() {
188
    return myVariableName;
1✔
189
  }
190

191
  @Override
192
  public @NotNull PerlVariable getVariable() {
193
    return this;
1✔
194
  }
195

196
  @Override
197
  public boolean isLexicalDeclaration() {
198
    return myIsLexical;
×
199
  }
200

201
  @Override
202
  public boolean isLocalDeclaration() {
203
    return myIsLocal;
×
204
  }
205

206
  @Override
207
  public boolean isGlobalDeclaration() {
208
    return !myIsLexical;
1✔
209
  }
210

211
  @Override
212
  public boolean isInvocantDeclaration() {
213
    return myIsInvocant;
×
214
  }
215

216
  @Override
217
  public String getPresentableName() {
218
    return isLocalDeclaration() ? getName() : getCanonicalName();
×
219
  }
220

221
  @Override
222
  public @Nullable Icon getIcon(int flags) {
223
    Icon iconByType = getIconByType(getActualType());
×
224
    return iconByType == null ? super.getIcon(flags) : iconByType;
×
225
  }
226

227
  @Override
228
  public @Nullable PsiElement getNameIdentifier() {
229
    return null;
×
230
  }
231

232
  @Override
233
  public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
234
    return this;
×
235
  }
236

237
  @Override
238
  public IStubElementType<?, ?> getElementType() {
239
    return null;
1✔
240
  }
241

242
  @Override
243
  public PerlVariableDeclarationStub getStub() {
244
    return null;
1✔
245
  }
246

247
  @Override
248
  public @NotNull String getName() {
249
    return getVariableName();
1✔
250
  }
251

252
  @Override
253
  public boolean isDeclaration() {
254
    return true;
×
255
  }
256

257
  @Override
258
  public @Nullable PerlVariableAnnotations getVariableAnnotations() {
259
    return null;
×
260
  }
261

262
  @Override
263
  public @NotNull PerlVariableAnnotations getLocalVariableAnnotations() {
264
    return PerlVariableAnnotations.empty();
×
265
  }
266

267
  @Override
268
  public boolean equals(Object o) {
269
    if (this == o) {
1✔
270
      return true;
×
271
    }
272
    if (o == null || getClass() != o.getClass()) {
1✔
273
      return false;
1✔
274
    }
275
    if (!super.equals(o)) {
×
276
      return false;
×
277
    }
278

279
    PerlImplicitVariableDeclaration that = (PerlImplicitVariableDeclaration)o;
×
280

281
    if (myIsLexical != that.myIsLexical) {
×
282
      return false;
×
283
    }
284
    if (myIsLocal != that.myIsLocal) {
×
285
      return false;
×
286
    }
287
    if (myIsInvocant != that.myIsInvocant) {
×
288
      return false;
×
289
    }
290
    if (myVariableType != that.myVariableType) {
×
291
      return false;
×
292
    }
293
    if (!myVariableName.equals(that.myVariableName)) {
×
294
      return false;
×
295
    }
296
    if (!myDeclaredValue.equals(that.myDeclaredValue)) {
×
297
      return false;
×
298
    }
299
    return myNamespaceName != null ? myNamespaceName.equals(that.myNamespaceName) : that.myNamespaceName == null;
×
300
  }
301

302
  @Override
303
  public int hashCode() {
304
    int result = super.hashCode();
1✔
305
    result = 31 * result + (myVariableType != null ? myVariableType.hashCode() : 0);
1✔
306
    result = 31 * result + myVariableName.hashCode();
1✔
307
    result = 31 * result + myDeclaredValue.hashCode();
1✔
308
    result = 31 * result + (myNamespaceName != null ? myNamespaceName.hashCode() : 0);
1✔
309
    result = 31 * result + (myIsLexical ? 1 : 0);
1✔
310
    result = 31 * result + (myIsLocal ? 1 : 0);
1✔
311
    result = 31 * result + (myIsInvocant ? 1 : 0);
1✔
312
    return result;
1✔
313
  }
314

315
  public static @NotNull PerlImplicitVariableDeclaration createGlobal(@NotNull PsiElement parent,
316
                                                                      @NotNull String variableName,
317
                                                                      @Nullable String variableClass
318
  ) {
319
    return create(parent, variableName, variableClass, false, false, false);
1✔
320
  }
321

322
  public static @NotNull PerlImplicitVariableDeclaration createGlobal(@NotNull PsiManager psiManager,
323
                                                                      @NotNull String variableName,
324
                                                                      @Nullable String packageName) {
325
    return create(psiManager, variableName, packageName, null, false, false, false, null);
1✔
326
  }
327

328
  public static @NotNull PerlImplicitVariableDeclaration createLexical(@NotNull PsiElement parent,
329
                                                                       @NotNull String variableName
330
  ) {
331
    return createLexical(parent, variableName, null);
1✔
332
  }
333

334
  public static @NotNull PerlImplicitVariableDeclaration createLexical(@NotNull PsiElement parent,
335
                                                                       @NotNull String variableName,
336
                                                                       @Nullable String variableClass
337
  ) {
338
    return create(parent, variableName, variableClass, true, false, false);
1✔
339
  }
340

341
  public static @NotNull PerlImplicitVariableDeclaration createInvocant(@NotNull PsiElement parent) {
342
    return new PerlImplicitVariableDeclaration(
1✔
343
      parent.getManager(),
1✔
344
      PerlVariableType.SCALAR,
345
      PerlMethodDefinitionMixin.getDefaultInvocantName().substring(1),
1✔
346
      null,
347
      PerlValues.FIRST_ARGUMENT_VALUE,
348
      true,
349
      false,
350
      true,
351
      parent
352
    );
353
  }
354

355
  private static @NotNull PerlImplicitVariableDeclaration create(@NotNull PsiElement parent,
356
                                                                 @NotNull String variableName,
357
                                                                 @Nullable String variableClass,
358
                                                                 boolean isLexical,
359
                                                                 boolean isLocal,
360
                                                                 boolean isInvocant
361
  ) {
362
    return create(parent.getManager(), variableName, null, variableClass, isLexical, isLocal, isInvocant, parent);
1✔
363
  }
364

365
  private static @NotNull PerlImplicitVariableDeclaration create(@NotNull PsiManager psiManager,
366
                                                                 @NotNull String variableNameWithSigil,
367
                                                                 @Nullable String packageName,
368
                                                                 @Nullable String variableClass,
369
                                                                 boolean isLexical,
370
                                                                 boolean isLocal,
371
                                                                 boolean isInvocant,
372
                                                                 @Nullable PsiElement parent
373
  ) {
374
    return new PerlImplicitVariableDeclaration(
1✔
375
      psiManager, variableNameWithSigil, packageName, PerlScalarValue.create(variableClass), isLexical, isLocal, isInvocant, parent);
1✔
376
  }
377

378
  public @NotNull List<PsiPerlExpr> getExprList() {
379
    return Collections.emptyList();
×
380
  }
381
}
382

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