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

Camelcade / Perl5-IDEA / #525521581

06 Jun 2025 08:26AM UTC coverage: 82.33% (-0.02%) from 82.354%
#525521581

push

github

hurricup
Moved debugger properties to the respective bundle

18 of 26 new or added lines in 8 files covered. (69.23%)

158 existing lines in 31 files now uncovered.

30858 of 37481 relevant lines covered (82.33%)

0.82 hits per line

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

92.0
/plugin/core/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.lexer.PerlElementTypes;
32
import com.perl5.lang.perl.psi.PerlIfUnlessCompound;
33
import com.perl5.lang.perl.psi.PsiPerlStatement;
34
import com.perl5.lang.perl.psi.impl.PerlStringContentElementImpl;
35
import com.perl5.lang.perl.psi.properties.PerlLoop;
36
import com.perl5.lang.perl.psi.utils.PerlPsiUtil;
37
import org.jetbrains.annotations.NotNull;
38

39

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

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

54
    if (element == null) {
1✔
UNCOV
55
      element = psiFile.findElementAt(startOffset - 1);
×
56
    }
57

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

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

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

71
  protected abstract boolean isInContext(PsiElement element);
72

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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