• 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

94.12
/plugin/backend/src/main/java/com/perl5/lang/perl/util/PerlArrayUtil.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.util;
18

19
import com.intellij.openapi.project.Project;
20
import com.intellij.psi.search.GlobalSearchScope;
21
import com.intellij.util.Processor;
22
import com.intellij.util.SmartList;
23
import com.perl5.lang.perl.lexer.PerlElementTypes;
24
import com.perl5.lang.perl.psi.PerlVariableDeclarationElement;
25
import com.perl5.lang.perl.psi.references.PerlImplicitDeclarationsService;
26
import org.jetbrains.annotations.NotNull;
27
import org.jetbrains.annotations.Nullable;
28

29
import java.util.Collection;
30
import java.util.Collections;
31
import java.util.List;
32

33
import static com.perl5.lang.perl.psi.stubs.variables.PerlArrayNamespaceStubIndex.KEY_ARRAY_IN_NAMESPACE;
34
import static com.perl5.lang.perl.psi.stubs.variables.PerlArrayStubIndex.KEY_ARRAY;
35

36

37
public final class PerlArrayUtil implements PerlElementTypes {
38
  private PerlArrayUtil() {
39
  }
40

41

42
  /**
43
   * Searching project files for global array definitions by specific package and variable name
44
   *
45
   * @param project       project to search in
46
   * @param canonicalName canonical variable name package::name
47
   * @return Collection of found definitions
48
   */
49
  public static Collection<PerlVariableDeclarationElement> getGlobalArrayDefinitions(@NotNull Project project,
50
                                                                                     @NotNull String canonicalName) {
51
    return getGlobalArrayDefinitions(project, canonicalName, GlobalSearchScope.allScope(project));
1✔
52
  }
53

54
  public static @NotNull Collection<PerlVariableDeclarationElement> getGlobalArrayDefinitions(@NotNull Project project,
55
                                                                                              @Nullable String canonicalName,
56
                                                                                              @NotNull GlobalSearchScope scope) {
57
    if (canonicalName == null) {
1✔
58
      return Collections.emptyList();
×
59
    }
60
    List<PerlVariableDeclarationElement> result = new SmartList<>();
1✔
61
    processGlobalArraysByName(project, scope, canonicalName, true, it -> {
1✔
62
      if (canonicalName.equals(it.getCanonicalName())) {
1✔
63
        result.add(it);
1✔
64
      }
65
      return true;
1✔
66
    });
67
    return result;
1✔
68
  }
69

70
  /**
71
   * Returns list of defined global arrays
72
   *
73
   * @param project project to search in
74
   * @return collection of variable canonical names
75
   */
76
  @SuppressWarnings("StaticMethodOnlyUsedInOneClass")
77
  public static Collection<String> getDefinedGlobalArrayNames(@NotNull Project project) {
78
    return PerlStubUtil.getAllKeys(KEY_ARRAY, GlobalSearchScope.allScope(project));
1✔
79
  }
80

81
  @SuppressWarnings("UnusedReturnValue")
82
  public static boolean processGlobalArraysByName(@NotNull Project project,
83
                                                  @NotNull GlobalSearchScope scope,
84
                                                  @NotNull String canonicalName,
85
                                                  boolean processAll,
86
                                                  @NotNull Processor<? super PerlVariableDeclarationElement> processor) {
87
    return PerlImplicitDeclarationsService.getInstance(project).processArrays(canonicalName, processor) &&
1✔
88
           PerlVariableUtil.processGlobalVariables(KEY_ARRAY, project, scope, processor, canonicalName, processAll);
1✔
89
  }
90

91
  @SuppressWarnings("StaticMethodOnlyUsedInOneClass")
92
  public static boolean processGlobalArrays(@NotNull Project project,
93
                                            @NotNull GlobalSearchScope scope,
94
                                            @Nullable String namespaceName,
95
                                            boolean processAll,
96
                                            @NotNull Processor<? super PerlVariableDeclarationElement> processor) {
97
    if( namespaceName == null){
1✔
98
      return PerlImplicitDeclarationsService.getInstance(project).processArrays( processor) &&
1✔
99
             PerlVariableUtil.processGlobalVariables(KEY_ARRAY, project, scope, processor, processAll);
1✔
100
    }
101
    return PerlImplicitDeclarationsService.getInstance(project).processArraysInNamespace(namespaceName, processor) &&
1✔
102
           PerlVariableUtil.processGlobalVariables(KEY_ARRAY_IN_NAMESPACE, project, scope, processor, namespaceName, !processAll);
1✔
103
  }
104
}
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