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

Camelcade / Perl5-IDEA / #525521501

12 Dec 2024 02:23AM UTC coverage: 82.134% (-0.006%) from 82.14%
#525521501

Pull #2951

github

web-flow
Merge 06b105f52 into 842960e24
Pull Request #2951: Bump JetBrains/qodana-action from 2024.2.6 to 2024.3.2

30802 of 37502 relevant lines covered (82.13%)

0.82 hits per line

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

32.0
/mason/mason2/core/src/main/java/com/perl5/lang/mason2/psi/impl/MasonFlagsStatementImpl.java
1
/*
2
 * Copyright 2015-2023 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.mason2.psi.impl;
18

19
import com.intellij.lang.ASTNode;
20
import com.intellij.openapi.util.text.StringUtil;
21
import com.intellij.psi.ElementManipulators;
22
import com.intellij.psi.PsiElement;
23
import com.intellij.psi.tree.IElementType;
24
import com.perl5.lang.mason2.psi.MasonFlagsStatement;
25
import com.perl5.lang.perl.psi.PsiPerlCommaSequenceExpr;
26
import com.perl5.lang.perl.psi.impl.PsiPerlStatementImpl;
27
import com.perl5.lang.perl.psi.utils.PerlPsiUtil;
28
import org.jetbrains.annotations.Contract;
29
import org.jetbrains.annotations.NotNull;
30
import org.jetbrains.annotations.Nullable;
31

32
import java.util.List;
33

34
import static com.perl5.lang.perl.parser.PerlElementTypesGenerated.COMMA;
35
import static com.perl5.lang.perl.parser.PerlElementTypesGenerated.FAT_COMMA;
36

37

38
public class MasonFlagsStatementImpl extends PsiPerlStatementImpl implements MasonFlagsStatement {
39
  public MasonFlagsStatementImpl(ASTNode node) {
40
    super(node);
1✔
41
  }
1✔
42

43
  @Override
44
  public void changeParentsList(@NotNull List<? super String> currentList) {
45
    String extendsFlagsValue = getExtendsFlagValue();
1✔
46
    if (extendsFlagsValue != null) {
1✔
47
      currentList.add(extendsFlagsValue);
×
48
    }
49
  }
1✔
50

51

52
  private @Nullable String getExtendsFlagValue() {
53
    PsiElement expr = getExpr();
1✔
54
    // fixme this can be a prototype for scanning a hash to map
55
    if (expr instanceof PsiPerlCommaSequenceExpr) {
1✔
56
      PsiElement currentElement = expr.getFirstChild();
×
57
      while (currentElement != null) {
×
58
        PsiElement keyElement = currentElement;
×
59

60
        // comma between key and val
61
        if (isNullOrNotComma(currentElement = PerlPsiUtil.getNextSignificantSibling(currentElement))) {
×
62
          break;
×
63
        }
64

65
        PsiElement valElement = PerlPsiUtil.getNextSignificantSibling(currentElement);
×
66

67
        if (valElement != null && StringUtil.equals("extends", ElementManipulators.getValueText(keyElement))) {
×
68
          return ElementManipulators.getValueText(valElement);
×
69
        }
70

71
        // comma between pairs
72
        if (isNullOrNotComma(currentElement = PerlPsiUtil.getNextSignificantSibling(currentElement))) {
×
73
          break;
×
74
        }
75

76
        currentElement = PerlPsiUtil.getNextSignificantSibling(currentElement);
×
77
      }
×
78
    }
79

80
    return null;
1✔
81
  }
82

83
  @Contract("null -> true")
84
  private boolean isNullOrNotComma(@Nullable PsiElement element) {
85
    if (element == null) {
×
86
      return true;
×
87
    }
88

89
    IElementType elementType = element.getNode().getElementType();
×
90
    return elementType != COMMA && elementType != FAT_COMMA;
×
91
  }
92
}
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

© 2025 Coveralls, Inc