• 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

86.67
/plugin/backend/src/main/java/com/perl5/lang/perl/util/PerlGlobUtil.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.progress.ProgressManager;
20
import com.intellij.openapi.project.Project;
21
import com.intellij.psi.search.GlobalSearchScope;
22
import com.intellij.psi.stubs.StubIndex;
23
import com.intellij.util.Processor;
24
import com.perl5.lang.perl.lexer.PerlElementTypes;
25
import com.perl5.lang.perl.psi.PerlGlobVariableElement;
26
import com.perl5.lang.perl.psi.PsiPerlGlobVariable;
27
import com.perl5.lang.perl.psi.stubs.globs.PerlGlobStubIndex;
28
import org.jetbrains.annotations.NotNull;
29
import org.jetbrains.annotations.Nullable;
30

31
import java.util.Collection;
32
import java.util.Collections;
33
import java.util.HashSet;
34
import java.util.Set;
35

36
import static com.perl5.lang.perl.psi.stubs.globs.PerlGlobNamespaceStubIndex.KEY_GLOB_NAMESPACE;
37

38

39
public final class PerlGlobUtil implements PerlElementTypes {
40
  private PerlGlobUtil() {
41
  }
42

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

54
  public static Collection<PsiPerlGlobVariable> getGlobsDefinitions(@NotNull Project project,
55
                                                                    @Nullable String canonicalName,
56
                                                                    @NotNull GlobalSearchScope scope) {
57
    if (canonicalName == null) {
1✔
58
      return Collections.emptyList();
×
59
    }
60
    return StubIndex.getElements(PerlGlobStubIndex.KEY_GLOB, canonicalName, project, scope, PsiPerlGlobVariable.class);
1✔
61
  }
62

63
  public static @NotNull Collection<PsiPerlGlobVariable> getGlobsDefinitionsInNamespace(@NotNull Project project,
64
                                                                                        @Nullable String namespaceName) {
65
    return getGlobsDefinitionsInNamespace(project, namespaceName, GlobalSearchScope.allScope(project));
1✔
66
  }
67

68
  public static @NotNull Collection<PsiPerlGlobVariable> getGlobsDefinitionsInNamespace(@NotNull Project project,
69
                                                                                        @Nullable String namespaceName,
70
                                                                                        @NotNull GlobalSearchScope scope) {
71
    if (namespaceName == null) {
1✔
72
      return Collections.emptyList();
×
73
    }
74
    return StubIndex.getElements(KEY_GLOB_NAMESPACE, namespaceName, project, scope, PsiPerlGlobVariable.class);
1✔
75
  }
76

77
  /**
78
   * Returns list of known stubbed globs
79
   *
80
   * @param project project to search in
81
   * @return collection of globs names
82
   */
83
  public static Collection<String> getDefinedGlobsNames(Project project) {
84
    return PerlStubUtil.getAllKeys(PerlGlobStubIndex.KEY_GLOB, GlobalSearchScope.allScope(project));
1✔
85
  }
86

87
  @SuppressWarnings("StaticMethodOnlyUsedInOneClass")
88
  public static boolean processGlobs(@NotNull Project project,
89
                                     @NotNull GlobalSearchScope scope,
90
                                     @Nullable String namespaceName,
91
                                     boolean processAll,
92
                                     @NotNull Processor<? super PerlGlobVariableElement> processor) {
93
    Set<String> namespacesToProcess;
94
    if (namespaceName == null) {
1✔
95
      namespacesToProcess = new HashSet<>(getDefinedGlobsNames(project));
1✔
96
    }
97
    else {
98
      namespacesToProcess = Collections.singleton(namespaceName);
1✔
99
    }
100
    Set<String> processedNames = processAll ? null : new HashSet<>();
1✔
101
    for (String namespace : namespacesToProcess) {
1✔
102
      if (!StubIndex.getInstance().processElements(KEY_GLOB_NAMESPACE, namespace, project, scope, PsiPerlGlobVariable.class, it -> {
1✔
103
        ProgressManager.checkCanceled();
1✔
104
        String canonicalName = it.getCanonicalName();
1✔
105
        if (processAll || processedNames.add(canonicalName)) {
1✔
106
          return processor.process(it);
1✔
107
        }
108
        return true;
1✔
109
      })){
110
        return false;
×
111
      }
112
    }
1✔
113
    return true;
1✔
114
  }
115

116
  @SuppressWarnings({"StaticMethodOnlyUsedInOneClass", "UnusedReturnValue"})
117
  public static boolean processGlobsByName(@NotNull Project project,
118
                                           @NotNull GlobalSearchScope scope,
119
                                           @NotNull String canonicalName,
120
                                           @NotNull Processor<? super PerlGlobVariableElement> processor,
121
                                           boolean processAll) {
122
    Set<String> processedNames = processAll ? null : new HashSet<>();
1✔
123
    return StubIndex.getInstance().processElements(PerlGlobStubIndex.KEY_GLOB, canonicalName, project, scope, PsiPerlGlobVariable.class, it -> {
1✔
124
      ProgressManager.checkCanceled();
1✔
125
      String globName = it.getCanonicalName();
1✔
126
      if (processAll || processedNames.add(globName)) {
1✔
127
        return processor.process(it);
1✔
128
      }
129
      return true;
×
130
    });
131
  }
132
}
133

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