• 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

93.22
/plugin/core/src/main/java/com/perl5/lang/pod/idea/livetemplates/PodTemplateContextType.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.pod.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.openapi.util.text.StringUtil;
23
import com.intellij.psi.FileViewProvider;
24
import com.intellij.psi.PsiElement;
25
import com.intellij.psi.PsiFile;
26
import com.intellij.psi.PsiWhiteSpace;
27
import com.intellij.psi.tree.IElementType;
28
import com.intellij.psi.util.PsiTreeUtil;
29
import com.intellij.psi.util.PsiUtilCore;
30
import com.perl5.PerlBundle;
31
import com.perl5.lang.pod.PodLanguage;
32
import com.perl5.lang.pod.lexer.PodElementTypes;
33
import com.perl5.lang.pod.parser.psi.mixin.PodOverSectionContent;
34
import com.perl5.lang.pod.parser.psi.mixin.PodSectionItem;
35
import org.jetbrains.annotations.NotNull;
36
import org.jetbrains.annotations.Nullable;
37

38
public abstract class PodTemplateContextType extends TemplateContextType implements PodElementTypes {
39

40
  public PodTemplateContextType(@NlsContexts.Label @NotNull String presentableName) {
41
    super(presentableName);
1✔
42
  }
1✔
43

44
  @Override
45
  public boolean isInContext(@NotNull TemplateActionContext templateActionContext) {
46
    var psiFile = templateActionContext.getFile();
1✔
47
    var startOffset = templateActionContext.getStartOffset();
1✔
48
    PsiFile podFile = psiFile.getViewProvider().getPsi(PodLanguage.INSTANCE);
1✔
49

50
    if (podFile == null) {
1✔
51
      return false;
1✔
52
    }
53

54
    PsiElement element = podFile.findElementAt(startOffset);
1✔
55

56
    if (element == null) {
1✔
UNCOV
57
      element = podFile.findElementAt(startOffset - 1);
×
58
    }
59

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

64
    return isInContext(element);
1✔
65
  }
66

67
  protected abstract boolean isInContext(PsiElement element);
68

69
  public static class Generic extends PodTemplateContextType {
70
    public Generic() {
71
      this(PodLanguage.NAME);
1✔
72
    }
1✔
73

74
    public Generic(@NlsContexts.Label String presentableName) {
75
      super(presentableName);
1✔
76
    }
1✔
77

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

84
  public static class CommandPosition extends PodTemplateContextType.Generic {
85
    public CommandPosition() {
86
      this(PerlBundle.message("label.command.position"));
1✔
87
    }
1✔
88

89
    public CommandPosition(@NlsContexts.Label String presentableName) {
90
      super(presentableName);
1✔
91
    }
1✔
92

93
    @Override
94
    protected boolean isInContext(PsiElement element) {
95
      int startOffset = element.getNode().getStartOffset();
1✔
96

97
      if (startOffset == 0) {
1✔
98
        return true;
1✔
99
      }
100
      else {
101
        FileViewProvider viewProvider = element.getContainingFile().getViewProvider();
1✔
102

103
        PsiElement currentElement = viewProvider.findElementAt(startOffset, PodLanguage.INSTANCE);
1✔
104
        if (currentElement != null && currentElement.getNode().getElementType() == POD_CODE) {
1✔
UNCOV
105
          return false;
×
106
        }
107

108
        PsiElement prevElement = viewProvider.findElementAt(startOffset - 1, PodLanguage.INSTANCE);
1✔
109
        IElementType prevElementType = PsiUtilCore.getElementType(prevElement);
1✔
110

111
        if (prevElementType == PodElementTypes.POD_NEWLINE || prevElementType == POD_OUTER) {
1✔
112
          return true;
1✔
113
        }
114

115
        if (prevElement instanceof PsiWhiteSpace && StringUtil.equals(prevElement.getText(), "\n")) {
1✔
116
          while (true) {
117
            if (prevElement == null || prevElement.getTextOffset() == 0) {
1✔
118
              return true;
1✔
119
            }
120
            else if (prevElement.getNode().getElementType() == PodElementTypes.POD_NEWLINE) {
1✔
121
              return true;
1✔
122
            }
123
            else if (!(prevElement instanceof PsiWhiteSpace)) {
1✔
UNCOV
124
              return false;
×
125
            }
126
            prevElement = viewProvider.findElementAt(prevElement.getNode().getStartOffset() - 1, PodLanguage.INSTANCE);
1✔
127
          }
128
        }
129
      }
130
      return super.isInContext(element);
1✔
131
    }
132
  }
133

134
  public static class InsideOver extends CommandPosition {
135
    public InsideOver(@NlsContexts.Label String presentableName) {
136
      super(presentableName);
1✔
137
    }
1✔
138

139
    @Override
140
    protected boolean isInContext(PsiElement element) {
141
      return super.isInContext(element) && PsiTreeUtil.getParentOfType(element, PodOverSectionContent.class) != null;
1✔
142
    }
143

144
    protected @Nullable PodSectionItem getFirstSectionItem(PsiElement element) {
145
      PodOverSectionContent sectionContent = PsiTreeUtil.getParentOfType(element, PodOverSectionContent.class);
1✔
146
      return sectionContent == null ? null : sectionContent.getFirstItem();
1✔
147
    }
148
  }
149

150
  public static class InsideOverBulleted extends InsideOver {
151
    public InsideOverBulleted() {
152
      super(PerlBundle.message("label.inside.over.block.bulleted"));
1✔
153
    }
1✔
154

155
    @Override
156
    protected boolean isInContext(PsiElement element) {
157
      if (!super.isInContext(element)) {
1✔
158
        return false;
1✔
159
      }
160

161
      PodSectionItem firstItem = getFirstSectionItem(element);
1✔
162
      return firstItem == null || firstItem.isBulleted();
1✔
163
    }
164
  }
165

166
  public static class InsideOverNotBulleted extends InsideOver {
167
    public InsideOverNotBulleted() {
168
      super(PerlBundle.message("label.inside.over.block.not.bulleted"));
1✔
169
    }
1✔
170

171
    @Override
172
    protected boolean isInContext(PsiElement element) {
173
      if (!super.isInContext(element)) {
1✔
174
        return false;
1✔
175
      }
176

177
      PodSectionItem firstItem = getFirstSectionItem(element);
1✔
178
      return firstItem == null || !firstItem.isBulleted();
1✔
179
    }
180
  }
181
}
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