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

Camelcade / Perl5-IDEA / #525521660

24 Aug 2025 01:28PM UTC coverage: 75.89% (-6.3%) from 82.227%
#525521660

push

github

hurricup
Migrated coverage reporting to https://github.com/nbaztec/coveralls-jacoco-gradle-plugin

See: https://github.com/kt3k/coveralls-gradle-plugin/issues/119

14751 of 22639 branches covered (65.16%)

Branch coverage included in aggregate %.

31091 of 37767 relevant lines covered (82.32%)

0.82 hits per line

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

55.32
/plugin/common/src/main/java/com/perl5/lang/perl/idea/editor/PerlBraceMatcher.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.idea.editor;
18

19
import com.intellij.lang.BracePair;
20
import com.intellij.lang.PairedBraceMatcher;
21
import com.intellij.psi.PsiComment;
22
import com.intellij.psi.PsiElement;
23
import com.intellij.psi.PsiFile;
24
import com.intellij.psi.PsiWhiteSpace;
25
import com.intellij.psi.tree.IElementType;
26
import com.perl5.lang.perl.psi.PerlSubDefinitionElement;
27
import com.perl5.lang.perl.psi.PsiPerlBlock;
28
import com.perl5.lang.perl.psi.PsiPerlConditionalBlock;
29
import com.perl5.lang.perl.psi.PsiPerlForCompound;
30
import com.perl5.lang.perl.psi.impl.PsiPerlIfCompoundImpl;
31
import org.apache.groovy.util.Maps;
32
import org.jetbrains.annotations.NotNull;
33
import org.jetbrains.annotations.Nullable;
34

35
import java.util.Map;
36

37
import static com.perl5.lang.perl.parser.PerlElementTypesGenerated.*;
38

39

40
public class PerlBraceMatcher implements PairedBraceMatcher {
1✔
41
  public static final Map<IElementType, IElementType> PERL_BRACES_MAP = Map.of(
1✔
42
    LEFT_BRACE, RIGHT_BRACE,
43
    LEFT_BRACKET, RIGHT_BRACKET,
44
    LEFT_PAREN, RIGHT_PAREN,
45
    LEFT_ANGLE, RIGHT_ANGLE,
46
    LEFT_BRACE_SCALAR, RIGHT_BRACE_SCALAR,
47
    LEFT_BRACE_ARRAY, RIGHT_BRACE_ARRAY,
48
    LEFT_BRACE_HASH, RIGHT_BRACE_HASH,
49
    LEFT_BRACE_CODE, RIGHT_BRACE_CODE,
50
    LEFT_BRACE_GLOB, RIGHT_BRACE_GLOB
51
  );
52

53
  public static final Map<IElementType, IElementType> PERL_BRACES_MAP_REVERSED = Maps.inverse(PERL_BRACES_MAP);
1✔
54

55
  private static final BracePair[] PAIRS = new BracePair[]{
1✔
56
    new BracePair(REGEX_QUOTE_OPEN, REGEX_QUOTE_CLOSE, false),
57
    new BracePair(REGEX_QUOTE_OPEN_E, REGEX_QUOTE_CLOSE, false),
58
    new BracePair(QUOTE_DOUBLE_OPEN, QUOTE_DOUBLE_CLOSE, false),
59
    new BracePair(QUOTE_SINGLE_OPEN, QUOTE_SINGLE_CLOSE, false),
60
    new BracePair(QUOTE_TICK_OPEN, QUOTE_TICK_CLOSE, false),
61
    new BracePair(LEFT_PAREN, RIGHT_PAREN, false),
62
    new BracePair(LEFT_BRACKET, RIGHT_BRACKET, false),
63
    new BracePair(LEFT_ANGLE, RIGHT_ANGLE, false),
64
    new BracePair(LEFT_BRACE, RIGHT_BRACE, true),
65
    new BracePair(LEFT_BRACE_SCALAR, RIGHT_BRACE_SCALAR, true),
66
    new BracePair(LEFT_BRACE_ARRAY, RIGHT_BRACE_ARRAY, true),
67
    new BracePair(LEFT_BRACE_HASH, RIGHT_BRACE_HASH, true),
68
    new BracePair(LEFT_BRACE_CODE, RIGHT_BRACE_CODE, true),
69
    new BracePair(LEFT_BRACE_GLOB, RIGHT_BRACE_GLOB, true),
70
    new BracePair(STRING_SPECIAL_LEFT_BRACE, STRING_SPECIAL_RIGHT_BRACE, false),
71
  };
72

73
  @Override
74
  public BracePair @NotNull [] getPairs() {
75
    return PAIRS;
1!
76
  }
77

78
  @Override
79
  public boolean isPairedBracesAllowedBeforeType(@NotNull IElementType lbraceType, @Nullable IElementType contextType) {
80
    return true;
1✔
81
  }
82

83
  @Override
84
  public int getCodeConstructStart(PsiFile file, int openingBraceOffset) {
85
    PsiElement element = file.findElementAt(openingBraceOffset);
1✔
86
    if (element == null || element instanceof PsiFile) {
1!
87
      return openingBraceOffset;
×
88
    }
89
    PsiElement codeBlock = element.getParent();
1✔
90

91
    if (!(codeBlock instanceof PsiPerlBlock)) {
1✔
92
      return openingBraceOffset;
1✔
93
    }
94
    PsiElement blockContainer = codeBlock.getParent();
1✔
95

96
    if (blockContainer == null) {
1!
97
      return openingBraceOffset;
×
98
    }
99
    if (blockContainer instanceof PerlSubDefinitionElement || blockContainer instanceof PsiPerlForCompound) {
1!
100
      return blockContainer.getTextOffset();
×
101
    }
102

103
    if (!(blockContainer instanceof PsiPerlConditionalBlock) && !(blockContainer instanceof PsiPerlIfCompoundImpl)) {
1!
104
      return openingBraceOffset;
1✔
105
    }
106

107
    PsiElement keyword = blockContainer.getPrevSibling();
×
108

109
    while ((keyword instanceof PsiWhiteSpace || keyword instanceof PsiComment)) {
×
110
      keyword = keyword.getPrevSibling();
×
111
    }
112

113
    return keyword != null ? keyword.getTextOffset() : openingBraceOffset;
×
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