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

Camelcade / Perl5-IDEA / #525521553

27 May 2025 10:24AM UTC coverage: 82.286% (-0.03%) from 82.32%
#525521553

push

github

hurricup
Removed redundant implementations, moved up to the abstract class

1 of 1 new or added line in 1 file covered. (100.0%)

128 existing lines in 30 files now uncovered.

30886 of 37535 relevant lines covered (82.29%)

0.82 hits per line

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

92.5
/plugin/core/src/main/java/com/perl5/lang/perl/psi/PerlNamespaceDefinitionElement.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;
18

19
import com.intellij.navigation.NavigationItem;
20
import com.intellij.openapi.diagnostic.Logger;
21
import com.intellij.openapi.project.Project;
22
import com.intellij.openapi.util.text.StringUtil;
23
import com.intellij.psi.PsiInvalidElementAccessException;
24
import com.intellij.psi.PsiNamedElement;
25
import com.intellij.psi.search.GlobalSearchScope;
26
import com.intellij.util.Processor;
27
import com.perl5.lang.perl.extensions.packageprocessor.PerlExportDescriptor;
28
import com.perl5.lang.perl.psi.impl.PerlUseStatementElement;
29
import com.perl5.lang.perl.psi.stubs.imports.PerlUseStatementsIndex;
30
import com.perl5.lang.perl.util.PerlPackageUtil;
31
import com.perl5.lang.perl.util.PerlTimeLogger;
32
import com.perl5.lang.perl.util.processors.*;
33
import org.jetbrains.annotations.Contract;
34
import org.jetbrains.annotations.NotNull;
35

36
import java.util.HashSet;
37
import java.util.List;
38
import java.util.Set;
39

40
public interface PerlNamespaceDefinitionElement extends PerlNamespaceDefinition, PsiNamedElement, NavigationItem {
41
  Logger LOG_STUBS = Logger.getInstance("#perl5.namespce.stubs");
1✔
42

43
  @Override
44
  @NotNull
45
  @Contract(pure = true)
46
  Project getProject() throws PsiInvalidElementAccessException;
47

48
  @SuppressWarnings("UnusedReturnValue")
49
  default boolean processExportDescriptors(@NotNull PerlNamespaceEntityProcessor<PerlExportDescriptor> processor) {
50
    String namespaceName = getNamespaceName();
1✔
51
    if (StringUtil.isEmpty(namespaceName)) {
1✔
UNCOV
52
      return true;
×
53
    }
54
    return processExportDescriptors(
1✔
55
      getProject(), GlobalSearchScope.fileScope(getContainingFile().getOriginalFile()), namespaceName, processor);
1✔
56
  }
57

58
  default @NotNull List<PerlExportDescriptor> collectImportDescriptors(@NotNull PerlImportsCollector collector) {
59
    processExportDescriptors(collector);
1✔
60
    return collector.getResult();
1✔
61
  }
62

63
  default @NotNull List<PerlExportDescriptor> getImportedSubsDescriptors() {
64
    return collectImportDescriptors(new PerlSubImportsCollector());
1✔
65
  }
66

67
  default @NotNull List<PerlExportDescriptor> getImportedScalarDescriptors() {
68
    return collectImportDescriptors(new PerlScalarImportsCollector());
1✔
69
  }
70

71
  default @NotNull List<PerlExportDescriptor> getImportedArrayDescriptors() {
72
    return collectImportDescriptors(new PerlArrayImportsCollector());
1✔
73
  }
74

75
  default @NotNull List<PerlExportDescriptor> getImportedHashDescriptors() {
76
    return collectImportDescriptors(new PerlHashImportsCollector());
1✔
77
  }
78

79
  default List<PerlNamespaceDefinitionElement> getParentNamespaceDefinitions() {
80
    return PerlPackageUtil.collectNamespaceDefinitions(getProject(), getParentNamespacesNames());
1✔
81
  }
82

83
  default @NotNull List<PerlNamespaceDefinitionElement> getChildNamespaceDefinitions() {
84
    return PerlPackageUtil.getChildNamespaces(getProject(), getNamespaceName());
1✔
85
  }
86

87
  default void getLinearISA(@NotNull Set<String> recursionMap, @NotNull List<String> result) {
88
    getMro().getLinearISA(getProject(), getParentNamespaceDefinitions(), recursionMap, result);
1✔
89
  }
1✔
90

91
  static @NotNull Set<PerlExportDescriptor> getExportDescriptors(@NotNull Project project,
92
                                                                 @NotNull GlobalSearchScope searchScope,
93
                                                                 @NotNull String namespaceName) {
94
    Set<PerlExportDescriptor> result = new HashSet<>();
1✔
95
    PerlNamespaceDefinitionElement.processExportDescriptors(
1✔
96
      project, searchScope, namespaceName, (__, it) -> {
97
        result.add(it);
1✔
98
        return true;
1✔
99
      });
100
    return result;
1✔
101
  }
102

103
  static boolean processExportDescriptors(@NotNull Project project,
104
                                          @NotNull GlobalSearchScope searchScope,
105
                                          @NotNull String namespaceName,
106
                                          @NotNull PerlNamespaceEntityProcessor<? super PerlExportDescriptor> processor) {
107
    PerlTimeLogger logger = PerlTimeLogger.create(LOG_STUBS);
1✔
108
    PerlTimeLogger.Counter useStatementsCounter = logger.getCounter("use");
1✔
109
    PerlTimeLogger.Counter exportsCounter = logger.getCounter("export");
1✔
110

111
    boolean result = PerlUseStatementsIndex.getInstance().processElements(
1✔
112
      project, namespaceName, searchScope, createUseStatementsProcessor(processor, useStatementsCounter, exportsCounter));
1✔
113

114
    logger.debug("Processed: ", useStatementsCounter.get(), " use statements; ",
1✔
115
                 exportsCounter.get(), " exports");
1✔
116

117
    return result;
1✔
118
  }
119

120
  private static @NotNull Processor<PerlUseStatementElement> createUseStatementsProcessor(@NotNull PerlNamespaceEntityProcessor<? super PerlExportDescriptor> processor,
121
                                                                                          @NotNull PerlTimeLogger.Counter useStatementsCounter,
122
                                                                                          @NotNull PerlTimeLogger.Counter exportsCounter) {
123
    return it -> {
1✔
124
      useStatementsCounter.inc();
1✔
125
      String packageName = it.getPackageName();
1✔
126

127
      if (packageName == null) {
1✔
UNCOV
128
        return true;
×
129
      }
130
      for (PerlExportDescriptor entry : it.getPackageProcessor().getImports(it)) {
1✔
131
        exportsCounter.inc();
1✔
132
        if (!processor.process(packageName, entry)) {
1✔
UNCOV
133
          return false;
×
134
        }
135
      }
1✔
136
      return true;
1✔
137
    };
138
  }
139
}
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