• 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

87.8
/plugin/profiler/src/main/java/com/perl5/lang/perl/profiler/parser/frames/PerlBeginStackElement.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.profiler.parser.frames;
18

19
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
20
import com.intellij.openapi.progress.ProgressManager;
21
import com.intellij.openapi.project.Project;
22
import com.intellij.openapi.projectRoots.Sdk;
23
import com.intellij.openapi.util.text.StringUtil;
24
import com.intellij.psi.NavigatablePsiElement;
25
import com.intellij.psi.PsiDocumentManager;
26
import com.intellij.psi.PsiFile;
27
import com.intellij.psi.search.GlobalSearchScope;
28
import com.perl5.lang.perl.psi.impl.PerlUseStatementElementBase;
29
import com.perl5.lang.perl.psi.impl.PsiPerlNamedBlockImpl;
30
import com.perl5.lang.perl.psi.utils.PerlPsiUtil;
31
import com.perl5.lang.perl.util.PerlNamespaceUtil;
32
import com.perl5.lang.perl.util.PerlPackageUtilCore;
33
import org.jetbrains.annotations.NotNull;
34

35
import java.util.*;
36

37
/**
38
 * Frame created for use statements and BEGIN blocks. Looks like {@code Foo::Bar::BEGIN@123}
39
 *
40
 * @implNote it's not possible to deduce exact file. So, for now we are iterating all files up to {@link #MAX_FILE_TO_OPEN},
41
 * parsing them, traversing and collecting all matching statements and blocks.
42
 */
43
class PerlBeginStackElement extends PerlCallStackElement {
44
  private final @NotNull String myNamespaceName;
45
  private final int myLineNumber;
46

47
  PerlBeginStackElement(@NotNull String frameText) {
48
    super(frameText);
1✔
49
    var cleanedFrameText = getFrameText();
1✔
50
    var beginStartSuffix = cleanedFrameText.indexOf(BEGIN_BLOCK_SUFFIX);
1✔
51

52
    if (beginStartSuffix < 0) {
1✔
53
      LOG.error("Attempting to create try frame from non-try text: " + frameText);
×
54
    }
55
    myNamespaceName = PerlPackageUtilCore.getCanonicalName(cleanedFrameText.substring(0, beginStartSuffix));
1✔
56
    int lineNumber = 1;
1✔
57
    try {
58
      var lineNumberInfo = cleanedFrameText.substring(beginStartSuffix + BEGIN_BLOCK_SUFFIX.length());
1✔
59
      var lineNumberParts = StringUtil.split(lineNumberInfo, ".");
1✔
60
      lineNumber = Integer.parseInt(lineNumberParts.getFirst());
1✔
61
    }
62
    catch (NumberFormatException e) {
×
63
      LOG.warn("Unable to parse line number from: " + cleanedFrameText + "; " + e.getMessage());
×
64
    }
1✔
65
    myLineNumber = lineNumber;
1✔
66
  }
1✔
67

68
  @Override
69
  public @NotNull String fullName() {
70
    return "BEGIN in " + myNamespaceName + " " + myLineNumber;
1✔
71
  }
72

73
  @Override
74
  protected @NotNull List<NavigatablePsiElement> computeNavigatables(@NotNull Project project, @NotNull Sdk perlSdk) {
75
    if (PerlPackageUtilCore.MAIN_NAMESPACE_NAME.equals(myNamespaceName)) {
1✔
76
      return Collections.emptyList();
×
77
    }
78
    List<NavigatablePsiElement> result = new ArrayList<>();
1✔
79
    Set<PsiFile> processedFiles = new HashSet<>();
1✔
80
    PerlNamespaceUtil.processNamespaces(
1✔
81
      myNamespaceName, project, GlobalSearchScope.allScope(project),
1✔
82
      it -> {
83
        var psiFile = it.getContainingFile();
1✔
84
        if (processedFiles.add(psiFile)) {
1✔
85
          ProgressManager.checkCanceled();
1✔
86
          var documentManager = PsiDocumentManager.getInstance(project);
1✔
87
          var document = documentManager.getDocument(psiFile);
1✔
88
          if (document == null || document.getLineCount() < myLineNumber) {
1✔
89
            return true;
×
90
          }
91

92
          var startOffset = document.getLineStartOffset(myLineNumber - 1);
1✔
93
          var endOffset = document.getLineEndOffset(myLineNumber - 1);
1✔
94

95
          var useStatement = PerlPsiUtil.findElementOfClassAtRange(psiFile, startOffset, endOffset, PerlUseStatementElementBase.class);
1✔
96
          if (myNamespaceName.equals(PerlPackageUtilCore.getContextNamespaceName(useStatement))) {
1✔
97
            result.add(useStatement);
1✔
98
          }
99
          else {
100
            var namedBlockAtOffset = PerlPsiUtil.findElementOfClassAtRange(psiFile, startOffset, endOffset, PsiPerlNamedBlockImpl.class);
1✔
101
            if (myNamespaceName.equals(PerlPackageUtilCore.getContextNamespaceName(namedBlockAtOffset))) {
1✔
102
              result.add(new PerlTargetElementWrapper(namedBlockAtOffset) {
1✔
103
                @Override
104
                public void navigate(boolean requestFocus) {
105
                  new OpenFileDescriptor(getProject(), psiFile.getVirtualFile(), startOffset).navigate(requestFocus);
1✔
106
                }
1✔
107
              });
108
            }
109
          }
110
        }
111
        return processedFiles.size() < MAX_FILE_TO_OPEN;
1✔
112
      });
113
    return result;
1✔
114
  }
115
}
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