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

Camelcade / Perl5-IDEA / #525521635

20 Jul 2025 03:45PM UTC coverage: 82.266% (-0.09%) from 82.355%
#525521635

push

github

hurricup
Build 252.23892.248

30936 of 37605 relevant lines covered (82.27%)

0.82 hits per line

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

88.37
/plugin/backend/src/main/java/com/perl5/lang/perl/psi/references/PerlVariableReference.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.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor;
25
import com.perl5.lang.perl.psi.PerlNamespaceDefinitionElement;
26
import com.perl5.lang.perl.psi.PerlVariable;
27
import com.perl5.lang.perl.psi.PerlVariableDeclarationElement;
28
import com.perl5.lang.perl.psi.utils.PerlResolveUtilCore;
29
import com.perl5.lang.perl.psi.utils.PerlVariableType;
30
import com.perl5.lang.perl.util.*;
31
import org.jetbrains.annotations.NotNull;
32

33
import java.util.ArrayList;
34
import java.util.List;
35

36

37
public class PerlVariableReference extends PerlCachingReference<PsiElement> {
1✔
38

39
  public PerlVariableReference(@NotNull PsiElement element, TextRange textRange) {
40
    super(element, textRange);
1✔
41
  }
1✔
42

43
  @Override
44
  protected @NotNull ResolveResult[] resolveInner(boolean incompleteCode) {
45
    PsiElement elementParent = myElement.getParent();
1✔
46
    assert elementParent instanceof PerlVariable;
1✔
47
    PerlVariable perlVariable = (PerlVariable)elementParent;
1✔
48

49
    List<PsiElement> result = new ArrayList<>();
1✔
50

51
    PerlVariableDeclarationElement lexicalDeclaration = PerlResolveUtilCore.getLexicalDeclaration(perlVariable);
1✔
52

53
    if (lexicalDeclaration != null) {
1✔
54
      result.add(lexicalDeclaration);
1✔
55
      if (lexicalDeclaration.isGlobalDeclaration()) {
1✔
56
        addRelatedGlobs(lexicalDeclaration.getVariable(), result);
1✔
57
        addGlobalVariables(lexicalDeclaration.getVariable(), result);
1✔
58
      }
59
      return PsiElementResolveResult.createResults(result);
1✔
60
    }
61

62
    // not found explicit lexically visible declarations
63

64
    // imports
65
    addImportedVariables(perlVariable, result);
1✔
66
    addRelatedGlobs(perlVariable, result);
1✔
67
    addGlobalVariables(perlVariable, result);
1✔
68

69
    return PsiElementResolveResult.createResults(result);
1✔
70
  }
71

72
  private void addGlobalVariables(@NotNull PerlVariable variable, @NotNull List<? super PsiElement> result) {
73
    result.addAll(PerlVariableUtil.getGlobalDeclarations(variable));
1✔
74
  }
1✔
75

76
  private void addRelatedGlobs(@NotNull PerlVariable variable, @NotNull List<? super PsiElement> result) {
77
    result.addAll(PerlVariableUtil.getRelatedGlobs(variable));
1✔
78
  }
1✔
79

80
  private void addImportedVariables(@NotNull PerlVariable perlVariable, @NotNull List<? super PsiElement> result) {
81
    PerlVariableType actualType = perlVariable.getActualType();
1✔
82
    Project project = perlVariable.getProject();
1✔
83
    PerlNamespaceDefinitionElement namespaceContainer = PerlPackageUtil.getNamespaceContainerForElement(perlVariable);
1✔
84

85
    if (namespaceContainer != null) // not true if LPE in TemplateToolkit
1✔
86
    {
87
      String variableName = perlVariable.getName();
1✔
88

89
      if (actualType == PerlVariableType.SCALAR) {
1✔
90
        for (PerlExportDescriptor importEntry : namespaceContainer.getImportedScalarDescriptors()) {
1✔
91
          if (importEntry.getImportedName().equals(variableName)) {
1✔
92
            result.addAll(PerlScalarUtil.getGlobalScalarDefinitions(project, importEntry.getTargetCanonicalName()));
1✔
93
          }
94
        }
1✔
95
      }
96
      else if (actualType == PerlVariableType.ARRAY) {
1✔
97
        for (PerlExportDescriptor importEntry : namespaceContainer.getImportedArrayDescriptors()) {
1✔
98
          if (importEntry.getImportedName().equals(variableName)) {
×
99
            result.addAll(PerlArrayUtil.getGlobalArrayDefinitions(project, importEntry.getTargetCanonicalName()));
×
100
          }
101
        }
1✔
102
      }
103
      else if (actualType == PerlVariableType.HASH) {
1✔
104
        for (PerlExportDescriptor importEntry : namespaceContainer.getImportedHashDescriptors()) {
1✔
105
          if (importEntry.getImportedName().equals(variableName)) {
×
106
            result.addAll(PerlHashUtil.getGlobalHashDefinitions(project, importEntry.getTargetCanonicalName()));
×
107
          }
108
        }
×
109
      }
110
    }
111
  }
1✔
112
}
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