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

Camelcade / Perl5-IDEA / #525521806

30 Mar 2026 09:28AM UTC coverage: 76.008% (+0.03%) from 75.979%
#525521806

push

github

hurricup
Cleaned up several unused methods

They were part of API but we can restore them when necessary, for now it is just a ballast.

14772 of 22624 branches covered (65.29%)

Branch coverage included in aggregate %.

31095 of 37721 relevant lines covered (82.43%)

0.82 hits per line

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

85.25
/plugin/common/src/main/java/com/perl5/lang/perl/psi/mixins/PerlNamespaceDefinitionMixin.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.mixins;
18

19
import com.intellij.lang.ASTNode;
20
import com.intellij.navigation.ItemPresentation;
21
import com.intellij.openapi.util.ClearableLazyValue;
22
import com.intellij.openapi.util.text.StringUtil;
23
import com.intellij.psi.PsiElement;
24
import com.intellij.psi.StubBasedPsiElement;
25
import com.intellij.psi.tree.IElementType;
26
import com.intellij.psi.util.PsiTreeUtil;
27
import com.intellij.util.IncorrectOperationException;
28
import com.intellij.util.Processor;
29
import com.perl5.PerlIcons;
30
import com.perl5.lang.perl.extensions.packageprocessor.PerlMroProvider;
31
import com.perl5.lang.perl.extensions.packageprocessor.PerlPackageProcessor;
32
import com.perl5.lang.perl.idea.presentations.PerlItemPresentationSimple;
33
import com.perl5.lang.perl.psi.*;
34
import com.perl5.lang.perl.psi.impl.PerlUseStatementElement;
35
import com.perl5.lang.perl.psi.mro.PerlMroType;
36
import com.perl5.lang.perl.psi.stubs.namespaces.PerlNamespaceDefinitionStub;
37
import com.perl5.lang.perl.psi.utils.PerlNamespaceAnnotations;
38
import com.perl5.lang.perl.psi.utils.PerlPsiUtil;
39
import com.perl5.lang.perl.util.PerlPackageUtilCore;
40
import org.jetbrains.annotations.NotNull;
41
import org.jetbrains.annotations.Nullable;
42

43
import javax.swing.*;
44
import java.util.ArrayList;
45
import java.util.Collections;
46
import java.util.List;
47
import java.util.Map;
48

49
import static com.perl5.lang.perl.idea.PerlElementPatterns.*;
50

51

52
public abstract class PerlNamespaceDefinitionMixin extends PerlStubBasedPsiElementBase<PerlNamespaceDefinitionStub>
53
  implements StubBasedPsiElement<PerlNamespaceDefinitionStub>,
54
             PerlNamespaceDefinitionWithIdentifier,
55
             PerlCompositeElement {
56
  private final ClearableLazyValue<ExporterInfo> myExporterInfo = ClearableLazyValue.create(this::computeExporterInfo);
1✔
57
  private final ClearableLazyValue<PerlMroType> myMroType = ClearableLazyValue.create(this::computeMroType);
1✔
58
  private final ClearableLazyValue<List<String>> myParentNamespaces = ClearableLazyValue.create(
1✔
59
    () -> PerlPackageUtilCore.collectParentNamespaceNamesFromPsi(this));
1✔
60

61
  public PerlNamespaceDefinitionMixin(@NotNull ASTNode node) {
62
    super(node);
1✔
63
  }
1✔
64

65
  public PerlNamespaceDefinitionMixin(@NotNull PerlNamespaceDefinitionStub stub, @NotNull IElementType nodeType) {
66
    super(stub, nodeType);
1✔
67
  }
1✔
68

69
  @Override
70
  public @Nullable PsiPerlNamespaceContent getNamespaceContent() {
71
    return PsiTreeUtil.getChildOfType(this, PsiPerlNamespaceContent.class);
×
72
  }
73

74
  @Override
75
  public @Nullable String getName() {
76
    return getNamespaceName();
1✔
77
  }
78

79
  @Override
80
  public @Nullable PerlNamespaceElement getNamespaceElement() {
81
    return findChildByClass(PerlNamespaceElement.class);
1✔
82
  }
83

84
  @Override
85
  public @Nullable PsiElement getNameIdentifier() {
86
    return getNamespaceElement();
1✔
87
  }
88

89
  @Override
90
  public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
91
    return PerlPsiUtil.renameNamedElement(this, name);
1✔
92
  }
93

94

95
  @Override
96
  public @Nullable String getNamespaceName() {
97
    PerlNamespaceDefinitionStub stub = getGreenStub();
1✔
98
    if (stub != null) {
1✔
99
      return stub.getNamespaceName();
1✔
100
    }
101

102
    return computeNamespaceName();
1✔
103
  }
104

105
  protected @Nullable String computeNamespaceName() {
106
    PerlNamespaceElement namespaceElement = getNamespaceElement();
1✔
107
    if (namespaceElement != null) {
1✔
108
      return namespaceElement.getCanonicalName();
1✔
109
    }
110
    return null;
1✔
111
  }
112

113
  @Override
114
  public @NotNull List<String> getParentNamespacesNames() {
115
    PerlNamespaceDefinitionStub stub = getGreenStub();
1✔
116
    if (stub != null) {
1✔
117
      return stub.getParentNamespacesNames();
1!
118
    }
119
    return myParentNamespaces.getValue();
1!
120
  }
121

122
  @Override
123
  public @Nullable Icon getIcon(int flags) {
124
    return PerlIcons.PACKAGE_GUTTER_ICON;
1✔
125
  }
126

127
  @Override
128
  public ItemPresentation getPresentation() {
129
    return new PerlItemPresentationSimple(this, getPresentableName());
1✔
130
  }
131

132
  @Override
133
  public @NotNull PerlMroType getMroType() {
134
    PerlNamespaceDefinitionStub stub = getGreenStub();
1✔
135
    if (stub != null) {
1✔
136
      return stub.getMroType();
1!
137
    }
138

139
    return myMroType.getValue();
1!
140
  }
141

142
  private @NotNull PerlMroType computeMroType() {
143
    MroSearcher searcher = new MroSearcher();
1✔
144
    PerlPsiUtil.processNamespaceStatements(this, searcher);
1✔
145
    return searcher.getResult();
1!
146
  }
147

148

149
  @Override
150
  public @NotNull List<String> getEXPORT() {
151
    PerlNamespaceDefinitionStub stub = getGreenStub();
1✔
152
    if (stub != null) {
1✔
153
      return stub.getEXPORT();
1!
154
    }
155

156
    return getExporterInfo().getEXPORT();
1!
157
  }
158

159
  @Override
160
  public @NotNull List<String> getEXPORT_OK() {
161
    PerlNamespaceDefinitionStub stub = getGreenStub();
1✔
162
    if (stub != null) {
1✔
163
      return stub.getEXPORT_OK();
1!
164
    }
165

166
    return getExporterInfo().getEXPORT_OK();
1!
167
  }
168

169
  @Override
170
  public @NotNull Map<String, List<String>> getEXPORT_TAGS() {
171
    PerlNamespaceDefinitionStub stub = getGreenStub();
1✔
172
    if (stub != null) {
1!
173
      return stub.getEXPORT_TAGS();
×
174
    }
175

176
    return getExporterInfo().getEXPORT_TAGS();
1!
177
  }
178

179
  @Override
180
  public int getTextOffset() {
181
    PsiElement nameIdentifier = getNameIdentifier();
1✔
182

183
    return nameIdentifier == null
1✔
184
           ? super.getTextOffset()
1✔
185
           : nameIdentifier.getTextOffset();
1✔
186
  }
187

188
  public @NotNull ExporterInfo getExporterInfo() {
189
    return myExporterInfo.getValue();
1!
190
  }
191

192
  private @NotNull ExporterInfo computeExporterInfo() {
193
    ExporterInfo result = new ExporterInfo();
1✔
194
    PerlPsiUtil.processNamespaceStatements(this, result);
1✔
195
    return result;
1!
196
  }
197

198
  @Override
199
  public @Nullable PerlNamespaceAnnotations getAnnotations() {
200
    PerlNamespaceDefinitionStub stub = getGreenStub();
1✔
201
    if (stub != null) {
1✔
202
      return stub.getAnnotations();
1✔
203
    }
204
    else {
205
      // re-parsing
206
      return getLocalAnnotations();
1✔
207
    }
208
  }
209

210
  public @Nullable PerlNamespaceAnnotations getLocalAnnotations() {
211
    return PerlNamespaceAnnotations.tryToFindAnnotations(this);
1✔
212
  }
213

214
  @Override
215
  public String toString() {
216
    return super.toString() + "@" + getNamespaceName();
1✔
217
  }
218

219
  public static class MroSearcher implements Processor<PsiElement> {
1✔
220
    private @NotNull PerlMroType myResult = PerlMroType.DFS;
1✔
221

222
    @Override
223
    public boolean process(PsiElement element) {
224
      if (element instanceof PerlUseStatementElement useStatementElement) {
1✔
225
        PerlPackageProcessor packageProcessor = useStatementElement.getPackageProcessor();
1✔
226
        if (packageProcessor instanceof PerlMroProvider mroProvider) {
1✔
227
          myResult = mroProvider.getMroType(useStatementElement);
1✔
228
          return false;
1✔
229
        }
230
      }
231
      return true;
1✔
232
    }
233

234
    public @NotNull PerlMroType getResult() {
235
      return myResult;
1!
236
    }
237
  }
238

239
  @Override
240
  public void subtreeChanged() {
241
    super.subtreeChanged();
1✔
242
    myExporterInfo.drop();
1✔
243
    myMroType.drop();
1✔
244
    myParentNamespaces.drop();
1✔
245
  }
1✔
246

247
  public static class ExporterInfo implements Processor<PsiElement> {
1✔
248
    private final @NotNull List<String> EXPORT = new ArrayList<>();
1✔
249
    private final @NotNull List<String> EXPORT_OK = new ArrayList<>();
1✔
250
    private final @NotNull Map<String, List<String>> EXPORT_TAGS = Collections.emptyMap();
1✔
251

252
    @Override
253
    public boolean process(PsiElement element) {
254
      if (ASSIGN_STATEMENT.accepts(element)) {
1✔
255
        if (EXPORT_ASSIGN_STATEMENT.accepts(element)) {
1✔
256
          PsiElement rightSide = element.getFirstChild().getLastChild();
1✔
257
          if (rightSide != null) {
1!
258
            EXPORT.clear();
1✔
259
            EXPORT.addAll(getRightSideStrings(rightSide));
1✔
260
          }
261
        }
1✔
262
        else if (EXPORT_OK_ASSIGN_STATEMENT.accepts(element)) {
1✔
263
          PsiElement rightSide = element.getFirstChild().getLastChild();
1✔
264
          if (rightSide != null) {
1✔
265
            EXPORT_OK.clear();
1✔
266
            EXPORT_OK.addAll(getRightSideStrings(rightSide));
1✔
267
          }
268
        }
269
      }
270

271
      return true;
1✔
272
    }
273

274
    protected List<String> getRightSideStrings(@NotNull PsiElement rightSide) {
275
      List<String> result = new ArrayList<>();
1✔
276
      if (rightSide.getFirstChild() != null) {
1✔
277
        int lastEnd = -1;
1✔
278
        for (PsiElement psiElement : PerlPsiUtil.collectStringElements(rightSide.getFirstChild())) {
1✔
279
          String text = psiElement.getText();
1✔
280
          if (StringUtil.isNotEmpty(text)) {
1!
281
            int newStart = psiElement.getNode().getStartOffset();
1✔
282
            if (newStart == lastEnd) // appending
1!
283
            {
284
              int lastIndex = result.size() - 1;
×
285
              result.add(result.remove(lastIndex) + text);
×
286
            }
×
287
            else {
288
              result.add(text);
1✔
289
            }
290
            lastEnd = newStart + text.length();
1✔
291
          }
292
        }
1✔
293
      }
294
      return result;
1✔
295
    }
296

297
    public @NotNull List<String> getEXPORT() {
298
      return EXPORT;
1!
299
    }
300

301
    public @NotNull List<String> getEXPORT_OK() {
302
      return EXPORT_OK;
1!
303
    }
304

305
    public @NotNull Map<String, List<String>> getEXPORT_TAGS() {
306
      return EXPORT_TAGS;
1!
307
    }
308
  }
309
}
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