• 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

88.54
/plugin/backend/src/main/java/com/perl5/lang/perl/idea/livetemplates/PerlTemplateContextType.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.livetemplates;
18

19
import com.intellij.codeInsight.template.TemplateActionContext;
20
import com.intellij.codeInsight.template.TemplateContextType;
21
import com.intellij.openapi.util.NlsContexts;
22
import com.intellij.psi.PsiComment;
23
import com.intellij.psi.PsiElement;
24
import com.intellij.psi.PsiWhiteSpace;
25
import com.intellij.psi.tree.IElementType;
26
import com.intellij.psi.util.PsiTreeUtil;
27
import com.intellij.psi.util.PsiUtilCore;
28
import com.perl5.PerlBundle;
29
import com.perl5.lang.perl.PerlLanguage;
30
import com.perl5.lang.perl.fileTypes.PerlFileTypeTest;
31
import com.perl5.lang.perl.psi.PerlIfUnlessCompound;
32
import com.perl5.lang.perl.psi.PsiPerlStatement;
33
import com.perl5.lang.perl.psi.impl.PerlStringContentElementImpl;
34
import com.perl5.lang.perl.psi.properties.PerlLoop;
35
import com.perl5.lang.perl.psi.utils.PerlPsiUtil;
36
import org.jetbrains.annotations.NotNull;
37

38
import static com.perl5.lang.perl.parser.PerlElementTypesGenerated.REGEX_TOKEN;
39

40

41
public abstract class PerlTemplateContextType extends TemplateContextType {
42
  protected PerlTemplateContextType(@NlsContexts.Label @NotNull String presentableName) {
43
    super(presentableName);
1✔
44
  }
1✔
45

46
  @Override
47
  public boolean isInContext(@NotNull TemplateActionContext templateActionContext) {
48
    var psiFile = templateActionContext.getFile();
1✔
49
    var startOffset = templateActionContext.getStartOffset();
1✔
50
    if (!PsiUtilCore.getLanguageAtOffset(psiFile, startOffset).isKindOf(PerlLanguage.INSTANCE)) {
1✔
51
      return false;
1✔
52
    }
53
    PsiElement element = psiFile.findElementAt(startOffset);
1✔
54

55
    if (element == null) {
1!
56
      element = psiFile.findElementAt(startOffset - 1);
×
57
    }
58

59
    if (element == null) {
1!
60
      return false;
×
61
    }
62

63
    IElementType tokenType = PsiUtilCore.getElementType(element);
1✔
64

65
    return !(element instanceof PsiWhiteSpace ||
1!
66
             element instanceof PerlStringContentElementImpl ||
67
             element instanceof PsiComment ||
68
             tokenType == REGEX_TOKEN) &&
69
           isInContext(element);
1✔
70
  }
71

72
  protected abstract boolean isInContext(PsiElement element);
73

74
  public static class Generic extends PerlTemplateContextType {
75
    public Generic() {
76
      super(PerlLanguage.NAME);
1✔
77
    }
1✔
78

79
    @Override
80
    public boolean isInContext(PsiElement element) {
81
      return true;
1✔
82
    }
83
  }
84

85
  public static class Postfix extends PerlTemplateContextType {
86
    public Postfix() {
87
      super(PerlBundle.message("perl.template.context.postfix"));
1✔
88
    }
1✔
89

90
    @Override
91
    public boolean isInContext(PsiElement element) {
92
      PsiPerlStatement statement = PsiTreeUtil.getParentOfType(element, PsiPerlStatement.class);
1✔
93

94
      return statement != null && statement.getTextOffset() < element.getTextOffset();
1✔
95
    }
96
  }
97

98
  public static class Prefix extends PerlTemplateContextType {
99
    public Prefix() {
100
      this(PerlBundle.message("perl.template.context.prefix"));
1✔
101
    }
1✔
102

103
    public Prefix(@NlsContexts.Label @NotNull String presentableName) {
104
      super(presentableName);
1✔
105
    }
1✔
106

107
    @Override
108
    public boolean isInContext(PsiElement element) {
109
      PsiPerlStatement statement = PsiTreeUtil.getParentOfType(element, PsiPerlStatement.class);
1✔
110

111
      return statement != null && statement.getTextOffset() == element.getTextOffset();
1✔
112
    }
113
  }
114

115
  public static class UnfinishedIf extends PerlTemplateContextType.Prefix {
116
    public UnfinishedIf() {
117
      super(PerlBundle.message("perl.template.context.incomplete.if"));
1✔
118
    }
1✔
119

120
    @Override
121
    public boolean isInContext(PsiElement element) {
122
      if (!super.isInContext(element)) {
1✔
123
        return false;
1✔
124
      }
125
      PsiPerlStatement statement = PsiTreeUtil.getParentOfType(element, PsiPerlStatement.class);
1✔
126
      if (statement == null) {
1!
127
        return false;
×
128
      }
129

130
      PsiElement ifStatement = PerlPsiUtil.getPrevSignificantSibling(statement);
1✔
131
      return ifStatement instanceof PerlIfUnlessCompound compound && compound.getUnconditionalBlock() == null;
1✔
132
    }
133
  }
134

135
  public static class Continue extends PerlTemplateContextType.Prefix {
136
    public Continue() {
137
      super(PerlBundle.message("perl.template.context.continue"));
1✔
138
    }
1✔
139

140
    @Override
141
    public boolean isInContext(PsiElement element) {
142
      if (!super.isInContext(element)) {
1✔
143
        return false;
1✔
144
      }
145

146
      PsiPerlStatement statement = PsiTreeUtil.getParentOfType(element, PsiPerlStatement.class);
1✔
147
      if (statement == null) {
1!
148
        return false;
×
149
      }
150

151
      PsiElement possibleLoop = PerlPsiUtil.getPrevSignificantSibling(statement);
1✔
152
      return possibleLoop instanceof PerlLoop perlLoop &&
1✔
153
             perlLoop.canHaveContinueBlock() &&
1✔
154
             perlLoop.getContinueBlock() == null;
1✔
155
    }
156
  }
157

158
  public static class TestFile extends PerlTemplateContextType.Prefix {
159
    public TestFile() {
160
      super(PerlBundle.message("perl.template.context.test.file"));
1✔
161
    }
1✔
162

163
    @Override
164
    public boolean isInContext(PsiElement element) {
165
      return PerlFileTypeTest.isMy(element) && super.isInContext(element);
1✔
166
    }
167
  }
168
}
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