• 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

68.63
/tt2/common/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.idea.settings.TemplateToolkitSettings;
32
import org.jetbrains.annotations.NotNull;
33
import org.jetbrains.annotations.Nullable;
34

35
import static com.perl5.lang.tt2.parser.TemplateToolkitElementTypesGenerated.TT2_HTML;
36

37

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

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

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

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

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

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

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

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