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

Camelcade / Perl5-IDEA / #525521637

21 Jul 2025 12:07PM UTC coverage: 82.347% (+0.08%) from 82.266%
#525521637

push

github

hurricup
#2842 Moved embedded perl extensions

30964 of 37602 relevant lines covered (82.35%)

0.82 hits per line

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

75.86
/tt2/backend/src/main/java/com/perl5/lang/tt2/idea/editor/TemplateToolkitTypedHandler.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.tt2.idea.editor;
18

19
import com.intellij.codeInsight.editorActions.TypedHandlerDelegate;
20
import com.intellij.openapi.editor.Editor;
21
import com.intellij.openapi.editor.EditorModificationUtilEx;
22
import com.intellij.openapi.fileTypes.FileType;
23
import com.intellij.openapi.project.Project;
24
import com.intellij.openapi.util.text.StringUtil;
25
import com.intellij.psi.FileViewProvider;
26
import com.intellij.psi.PsiElement;
27
import com.intellij.psi.PsiFile;
28
import com.intellij.psi.tree.IElementType;
29
import com.perl5.lang.tt2.TemplateToolkitFileViewProvider;
30
import com.perl5.lang.tt2.TemplateToolkitLanguage;
31
import com.perl5.lang.tt2.elementTypes.TemplateToolkitElementTypes;
32
import com.perl5.lang.tt2.idea.settings.TemplateToolkitSettings;
33
import org.jetbrains.annotations.NotNull;
34
import org.jetbrains.annotations.Nullable;
35

36

37
public class TemplateToolkitTypedHandler extends TypedHandlerDelegate implements TemplateToolkitElementTypes {
1✔
38
  @Override
39
  public @NotNull Result beforeCharTyped(char c,
40
                                         @NotNull Project project,
41
                                         @NotNull Editor editor,
42
                                         @NotNull PsiFile file,
43
                                         @NotNull FileType fileType) {
44
    Result result = processChar(c, project, editor, file);
1✔
45
    return result == null ? super.beforeCharTyped(c, project, editor, file, fileType) : result;
1✔
46
  }
47

48
  protected @Nullable Result processChar(char c, Project project, Editor editor, PsiFile file) {
49
    FileViewProvider viewProvider = file.getViewProvider();
1✔
50
    if (!(viewProvider instanceof TemplateToolkitFileViewProvider)) {
1✔
51
      return null;
×
52
    }
53

54
    TemplateToolkitSettings settings = TemplateToolkitSettings.getInstance(project);
1✔
55
    String openTag = settings.START_TAG;
1✔
56
    if (StringUtil.isEmpty(openTag) || c != openTag.charAt(openTag.length() - 1)) {
1✔
57
      return null;
1✔
58
    }
59

60
    int offset = editor.getCaretModel().getOffset();
1✔
61
    if (offset == 0) {
1✔
62
      return null;
×
63
    }
64

65
    PsiElement element = viewProvider.findElementAt(offset - 1, TemplateToolkitLanguage.INSTANCE);
1✔
66
    if (element == null) {
1✔
67
      return null;
×
68
    }
69
    IElementType tokenType = element.getNode().getElementType();
1✔
70
    if (tokenType != TT2_HTML) {
1✔
71
      return null;
×
72
    }
73

74
    String openTagPrefix = openTag.substring(0, openTag.length() - 1);
1✔
75
    if (openTagPrefix.isEmpty()) {
1✔
76
      return null;
×
77
    }
78

79
    int startOffset = offset - openTagPrefix.length();
1✔
80
    if (startOffset < 0) {
1✔
81
      return null;
×
82
    }
83

84
    if (StringUtil.equals(file.getText().subSequence(startOffset, offset), openTagPrefix)) {
1✔
85
      EditorModificationUtilEx.insertStringAtCaret(editor, c + "  " + settings.END_TAG, false, true, 2);
1✔
86
      return Result.STOP;
1✔
87
    }
88
    return null;
×
89
  }
90
}
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