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

Camelcade / Perl5-IDEA / #525521819

12 Apr 2026 11:03AM UTC coverage: 76.189% (+0.1%) from 76.061%
#525521819

push

github

hurricup
[qodana] Suppressed a warning on the api method

14764 of 22542 branches covered (65.5%)

Branch coverage included in aggregate %.

31091 of 37644 relevant lines covered (82.59%)

0.83 hits per line

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

76.47
/plugin/common/src/main/java/com/perl5/lang/perl/lexer/PerlTemplatingLexer.java
1
/*
2
 * Copyright 2015-2026 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.lexer;
18

19
import com.intellij.openapi.diagnostic.Logger;
20
import com.intellij.openapi.project.Project;
21
import com.intellij.psi.tree.IElementType;
22
import org.jetbrains.annotations.Nullable;
23

24
import java.io.IOException;
25

26
import static com.perl5.lang.perl.parser.PerlElementTypesGenerated.COMMENT_ANNOTATION;
27
import static com.perl5.lang.perl.parser.PerlElementTypesGenerated.COMMENT_LINE;
28

29
public abstract class PerlTemplatingLexer extends PerlProtoLexer {
1✔
30
  private static final Logger LOG = Logger.getInstance(PerlTemplatingLexer.class);
1✔
31
  protected final PerlLexer myPerlLexer = new PerlLexer(null);
1✔
32

33
  public PerlTemplatingLexer withProject(@Nullable Project project) {
34
    myPerlLexer.withProject(project);
1✔
35
    return this;
1✔
36
  }
37

38
  /**
39
   * syncronizes position of perl lexer with main one
40
   */
41
  private void syncPerlLexer() {
42
    myPerlLexer.setTokenEnd(getTokenEnd());
1✔
43
  }
1✔
44

45
  /**
46
   * syncronizes position of the main lexer with perl one
47
   */
48
  private void syncMainLexer() {
49
    setTokenEnd(myPerlLexer.getTokenEnd());
1✔
50
  }
1✔
51

52
  @Override
53
  public IElementType advance() throws IOException {
54
    if (myPerlLexer.hasPreparsedTokens()) {
1✔
55
      IElementType result = myPerlLexer.advance();
1✔
56
      syncMainLexer();
1✔
57
      if (LOG.isTraceEnabled()) {
1!
58
        LOG.debug("Preparsed by perl lexer: '", myPerlLexer.yytext(),
×
59
                  "'; state: ", myPerlLexer.yystate(),
×
60
                  "; real state: ", myPerlLexer.getRealLexicalState(),
×
61
                  "; tokenType: ", result,
62
                  "; start: ", myPerlLexer.getTokenStart(),
×
63
                  "; end: ", myPerlLexer.getTokenEnd()
×
64
        );
65
      }
66
      return result;
1✔
67
    }
68

69
    IElementType result = super.advance();
1✔
70
    if (LOG.isTraceEnabled()) {
1!
71
      LOG.debug("From template lexer: '", yytext(),
×
72
                "'; state: ", yystate(),
×
73
                "; real state: ", getRealLexicalState(),
×
74
                "; tokenType: ", result,
75
                "; start: ", getTokenStart(),
×
76
                "; end: ", getTokenEnd()
×
77
      );
78
    }
79
    return result;
1✔
80
  }
81

82
  @Override
83
  protected void resetInternals() {
84
    super.resetInternals();
1✔
85
    int packedLexicalState = getRealLexicalState();
1✔
86
    yybegin(getTemplateLexerState(packedLexicalState));
1✔
87
    myPerlLexer.reset(getBuffer(), getBufferStart(), getBufferEnd(), getPerlLexerState(packedLexicalState));
1✔
88
  }
1✔
89

90
  public static int packState(int perlLexerState, int templateLexerState) {
91
    return (templateLexerState << 16) + perlLexerState;
1✔
92
  }
93

94
  public static int getPerlLexerState(int packedState) {
95
    return packedState & 0xFFFF;
1✔
96
  }
97

98
  public static int getTemplateLexerState(int packedState) {
99
    return packedState >> 16;
1✔
100
  }
101

102
  /**
103
   * Delegating current position to the perl lexer
104
   */
105
  protected IElementType delegateLexing() {
106
    yypushback(yylength());
1✔
107
    syncPerlLexer();
1✔
108
    try {
109
      IElementType result = myPerlLexer.advance();
1✔
110
      CommentEndCalculator commentEndCalculator = getCommentEndCalculator();
1✔
111
      if (commentEndCalculator != null && (result == COMMENT_LINE || result == COMMENT_ANNOTATION)) {
1!
112
        int endIndex = commentEndCalculator.getCommentEndOffset(myPerlLexer.yytext());
1✔
113
        if (endIndex > -1) {
1✔
114
          myPerlLexer.setTokenEnd(myPerlLexer.getTokenStart() + endIndex);
1✔
115
        }
116
      }
117
      syncMainLexer();
1✔
118
      return result;
1✔
119
    }
120
    catch (Exception ignore) {
×
121
    }
122
    throw new RuntimeException("Something bad happened");
×
123
  }
124

125
  protected @Nullable CommentEndCalculator getCommentEndCalculator() {
126
    return null;
×
127
  }
128

129
  protected void startPerlExpression() {
130
    myPerlLexer.pushStateAndBegin(0);
1✔
131
  }
1✔
132

133
  protected void endPerlExpression() {
134
    myPerlLexer.popState();
1✔
135
  }
1✔
136

137
  protected void setPerlToInitial() {
138
    myPerlLexer.yybegin(0);
1✔
139
  }
1✔
140

141
  public interface CommentEndCalculator {
142
    /**
143
     * Finds real comment end offset
144
     *
145
     * @param commentText comment text, found by perl lexer
146
     * @return comment end offset or -1 if comment is ok
147
     */
148
    int getCommentEndOffset(CharSequence commentText);
149
  }
150
}
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