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

Camelcade / Perl5-IDEA / #525521551

26 May 2025 11:24AM UTC coverage: 82.32% (+0.001%) from 82.319%
#525521551

push

github

hurricup
Migrated to the presentation property

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

148 existing lines in 15 files now uncovered.

30897 of 37533 relevant lines covered (82.32%)

0.82 hits per line

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

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

19
import com.intellij.psi.PsiElement;
20
import com.intellij.psi.util.PsiTreeUtil;
21
import com.intellij.util.Processor;
22
import com.perl5.lang.perl.psi.*;
23
import com.perl5.lang.perl.psi.impl.PsiPerlCallArgumentsImpl;
24
import com.perl5.lang.perl.util.PerlArrayUtil;
25
import org.jetbrains.annotations.NotNull;
26
import org.jetbrains.annotations.Nullable;
27

28
import java.util.ArrayList;
29
import java.util.List;
30

31
import static com.perl5.lang.perl.idea.PerlElementPatterns.*;
32
import static com.perl5.lang.perl.parser.PerlElementTypesGenerated.UNDEF_EXPR;
33

34
public class PerlSubArgumentsExtractor implements Processor<PsiPerlStatement> {
1✔
35
  private final List<PerlSubArgument> myArguments = new ArrayList<>();
1✔
36

37
  @Override
38
  public boolean process(PsiPerlStatement statement) {
39
    if (myArguments.isEmpty() && PerlPsiUtil.isSelfShortcutStatement(statement)) {
1✔
40
      myArguments.add(PerlSubArgument.self());
1✔
41
      return true;
1✔
42
    }
43
    else if (EMPTY_SHIFT_STATEMENT_PATTERN.accepts(statement)) {
1✔
44
      myArguments.add(myArguments.isEmpty() ? PerlSubArgument.self() : PerlSubArgument.empty());
1✔
45
      return true;
1✔
46
    }
47
    else if (DECLARATION_ASSIGNING_PATTERN.accepts(statement)) {
1✔
48
      // fixme see #2007
49
      PerlAssignExpression assignExpression = PsiTreeUtil.getChildOfType(statement, PerlAssignExpression.class);
1✔
50

51
      if (assignExpression == null) {
1✔
UNCOV
52
        return false;
×
53
      }
54

55
      PsiElement leftSide = assignExpression.getLeftSide();
1✔
56
      PsiElement rightSide = assignExpression.getRightSide();
1✔
57

58
      if (rightSide == null) {
1✔
UNCOV
59
        return false;
×
60
      }
61

62
      PerlVariableDeclarationExpr variableDeclaration = PsiTreeUtil.findChildOfType(leftSide, PerlVariableDeclarationExpr.class, false);
1✔
63

64
      if (variableDeclaration == null) {
1✔
UNCOV
65
        return false;
×
66
      }
67

68
      String variableClass = variableDeclaration.getDeclarationType();
1✔
69
      if (variableClass == null) {
1✔
70
        variableClass = "";
1✔
71
      }
72

73
      List<PsiElement> rightSideElements = PerlArrayUtil.collectListElements(rightSide);
1✔
74
      int sequenceIndex = 0;
1✔
75

76
      boolean processNextStatement = true;
1✔
77
      PsiElement run = variableDeclaration.getFirstChild();
1✔
78
      while (run != null) {
1✔
79
        var nextArgument = getArgument(run, variableClass);
1✔
80

81
        if (nextArgument != null) {
1✔
82
          // we've found argument of left side
83
          if (rightSideElements.size() > sequenceIndex) {
1✔
84
            PsiElement rightSideElement = rightSideElements.get(sequenceIndex);
1✔
85
            boolean addArgument = false;
1✔
86

87
            if (SHIFT_PATTERN.accepts(rightSideElement)) // shift on the left side
1✔
88
            {
89
              assert rightSideElement instanceof PsiPerlArrayShiftExpr;
1✔
90
              PsiPerlCallArguments callArguments = ((PsiPerlArrayShiftExpr)rightSideElement).getCallArguments();
1✔
91
              List<PsiElement> argumentsList =
92
                callArguments == null ? null : ((PsiPerlCallArgumentsImpl)callArguments).getArgumentsList();
1✔
93
              if (argumentsList == null || argumentsList.isEmpty() || ALL_ARGUMENTS_PATTERN.accepts(argumentsList.getFirst())) {
1✔
94
                addArgument = true;
1✔
95
                sequenceIndex++;
1✔
96
              }
97
            }
1✔
98
            else if (ALL_ARGUMENTS_ELEMENT_PATTERN.accepts(rightSideElement)) // $_[smth] on the left side
1✔
99
            {
100
              addArgument = true;
1✔
101
              sequenceIndex++;
1✔
102
            }
103
            else if (ALL_ARGUMENTS_PATTERN.accepts(rightSideElement))    // @_ on the left side
1✔
104
            {
105
              addArgument = true;
1✔
106
              processNextStatement = false;
1✔
107
            }
108

109
            if (addArgument) {
1✔
110
              myArguments.add(nextArgument);
1✔
111
            }
112
          }
113
        }
114

115
        run = run.getNextSibling();
1✔
116
      }
1✔
117

118
      return processNextStatement;
1✔
119
    }
120
    return false;
1✔
121
  }
122

123
  private @Nullable PerlSubArgument getArgument(@NotNull PsiElement run, @NotNull String variableClass) {
124
    if (run instanceof PerlVariableDeclarationElement variableDeclarationElement) {
1✔
125
      PerlVariable variable = variableDeclarationElement.getVariable();
1✔
126
      return PerlSubArgument.mandatory(
1✔
127
        variable.getActualType(),
1✔
128
        variable.getName(),
1✔
129
        variableClass
130
      );
131
    }
132
    else if (run.getNode().getElementType() == UNDEF_EXPR) {
1✔
133
      return myArguments.isEmpty() ? PerlSubArgument.self() : PerlSubArgument.empty();
1✔
134
    }
135
    return null;
1✔
136
  }
137

138
  public List<PerlSubArgument> getArguments() {
139
    return myArguments;
1✔
140
  }
141
}
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