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

Camelcade / Perl5-IDEA / #525521576

05 Jun 2025 06:17AM UTC coverage: 82.298% (-0.02%) from 82.318%
#525521576

push

github

hurricup
Localized strings and improved annotations

26 of 41 new or added lines in 19 files covered. (63.41%)

22 existing lines in 6 files now uncovered.

30837 of 37470 relevant lines covered (82.3%)

0.82 hits per line

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

95.18
/plugin/core/src/main/java/com/perl5/lang/perl/idea/annotators/PerlAnnotator.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.annotators;
18

19

20
import com.intellij.codeInspection.util.InspectionMessage;
21
import com.intellij.lang.annotation.AnnotationHolder;
22
import com.intellij.lang.annotation.HighlightSeverity;
23
import com.intellij.openapi.editor.colors.CodeInsightColors;
24
import com.intellij.openapi.editor.colors.TextAttributesKey;
25
import com.intellij.openapi.util.NlsSafe;
26
import com.intellij.openapi.util.NotNullLazyValue;
27
import com.intellij.openapi.util.text.StringUtil;
28
import com.intellij.psi.ElementManipulators;
29
import com.intellij.psi.PsiElement;
30
import com.intellij.psi.PsiReference;
31
import com.intellij.psi.tree.IElementType;
32
import com.intellij.psi.util.PsiUtilCore;
33
import com.perl5.PerlBundle;
34
import com.perl5.lang.perl.extensions.packageprocessor.impl.ConstantProcessor;
35
import com.perl5.lang.perl.idea.highlighter.PerlSyntaxHighlighter;
36
import com.perl5.lang.perl.psi.*;
37
import com.perl5.lang.perl.psi.impl.*;
38
import com.perl5.lang.perl.psi.light.PerlDelegatingLightNamedElement;
39
import com.perl5.lang.perl.psi.references.PerlSubReference;
40
import com.perl5.lang.perl.util.PerlSubUtil;
41
import org.jetbrains.annotations.NonNls;
42
import org.jetbrains.annotations.NotNull;
43

44
import java.util.Map;
45
import java.util.function.BiConsumer;
46
import java.util.function.Consumer;
47

48
import static com.perl5.lang.perl.idea.highlighter.PerlSyntaxHighlighter.*;
49

50
public class PerlAnnotator extends PerlBaseAnnotator {
1✔
51
  private static final NotNullLazyValue<Map<Class<? extends PerlVariable>, TextAttributesKey>> VARIABLE_KEYS_MAP =
1✔
52
    NotNullLazyValue.createValue(
1✔
53
      () -> Map.of(
1✔
54
        PsiPerlScalarVariableImpl.class, PERL_SCALAR_BUILTIN,
55
        PsiPerlArrayIndexVariableImpl.class, PERL_SCALAR_BUILTIN,
56
        PsiPerlHashVariableImpl.class, PERL_HASH_BUILTIN,
57
        PsiPerlArrayVariableImpl.class, PERL_ARRAY_BUILTIN)
58
    );
59

60
  @Override
61
  public void annotate(final @NotNull PsiElement element, @NotNull AnnotationHolder holder) {
62
    IElementType elementType = PsiUtilCore.getElementType(element);
1✔
63
    BiConsumer<@InspectionMessage String, TextAttributesKey> defaultAnnotationProducer =
1✔
64
      (var msg, var key) -> createInfoAnnotation(holder, element, msg, key);
1✔
65
    Consumer<TextAttributesKey> defaultSilentProducer = (key) -> createInfoAnnotation(holder, element, null, key);
1✔
66

67
    if (elementType == NYI_STATEMENT) {
1✔
68
      defaultAnnotationProducer.accept(PerlBundle.message("inspection.message.unimplemented.statement"),
1✔
69
                                       CodeInsightColors.TODO_DEFAULT_ATTRIBUTES);
70
    }
71
    else if (element instanceof PerlGlobVariableElement globalVariableElement && globalVariableElement.isBuiltIn()) {
1✔
72
      defaultSilentProducer.accept(PERL_GLOB_BUILTIN);
1✔
73
    }
74
    else if (element instanceof PerlVariable perlVariable && perlVariable.isBuiltIn()) {
1✔
75
      defaultSilentProducer.accept(VARIABLE_KEYS_MAP.get().get(element.getClass()));
1✔
76
    }
77
    else if (elementType == LABEL_DECLARATION || elementType == LABEL_EXPR) {
1✔
78
      createInfoAnnotation(holder, element.getFirstChild(), null, PerlSyntaxHighlighter.PERL_LABEL);
1✔
79
    }
80
    else if (elementType == PACKAGE) {
1✔
81
      assert element instanceof PerlNamespaceElement;
1✔
82
      PerlNamespaceElement namespaceElement = (PerlNamespaceElement)element;
1✔
83

84
      PsiElement parent = namespaceElement.getParent();
1✔
85

86
      if (parent instanceof PerlNamespaceDefinitionWithIdentifier) {
1✔
87
        createInfoAnnotation(holder, namespaceElement, null, PerlSyntaxHighlighter.PERL_PACKAGE_DEFINITION);
1✔
88
      }
89
      else {
90
        if (namespaceElement.isPragma()) {
1✔
91
          createInfoAnnotation(holder, namespaceElement, null, PerlSyntaxHighlighter.PERL_PACKAGE_PRAGMA);
1✔
92
        }
93
        else if (namespaceElement.isBuiltin()) {
1✔
94
          createInfoAnnotation(holder, namespaceElement, null, PerlSyntaxHighlighter.PERL_PACKAGE_CORE);
1✔
95
        }
96
      }
97
    }
1✔
98
    else if (element instanceof PerlCharSubstitution charSubstitution) {
1✔
99
      int codePoint = charSubstitution.getCodePoint();
1✔
100
      if (codePoint >= 0) {
1✔
101
        @NlsSafe StringBuilder sb = new StringBuilder("<ul>");
1✔
102
        @NonNls String chars = charSubstitution.getNonIgnorableChars();
1✔
103
        if (StringUtil.isEmptyOrSpaces(chars)) {
1✔
104
          chars = PerlBundle.message("perl.annotator.char.non.printable");
1✔
105
        }
106

107
        sb.append("<li>").append(PerlBundle.message("perl.annotator.char.character")).append(": ")
1✔
108
          .append(chars).append(" (").append(Character.getName(codePoint)).append(")").append("</li>");
1✔
109
        sb.append("<li>").append(PerlBundle.message("perl.annotator.char.codepoint")).append(": ")
1✔
110
          .append("0x").append(Integer.toHexString(codePoint).toUpperCase()).append(" (").append(codePoint).append(")").append("</li>");
1✔
111
        sb.append("</ul>");
1✔
112

113
        holder.newAnnotation(HighlightSeverity.INFORMATION, chars).range(element).tooltip(sb.toString()).create();
1✔
114
      }
115
    }
1✔
116
    else if (element instanceof PerlPolyNamedElement<?> polyNamedElement) {
1✔
117
      TextAttributesKey subAttribute = PerlSyntaxHighlighter.PERL_SUB_DEFINITION;
1✔
118
      if (element instanceof PerlUseStatementElement useStatementElement &&
1✔
119
          useStatementElement.getPackageProcessor() instanceof ConstantProcessor) {
1✔
120
        subAttribute = PerlSyntaxHighlighter.PERL_CONSTANT;
1✔
121
      }
122
      for (PerlDelegatingLightNamedElement<?> lightNamedElement : polyNamedElement.getLightElements()) {
1✔
123
        if (lightNamedElement.isImplicit()) {
1✔
124
          continue;
×
125
        }
126
        TextAttributesKey currentKey =
127
          lightNamedElement instanceof PerlSubDefinition ? subAttribute : PerlSyntaxHighlighter.PERL_PACKAGE_DEFINITION;
1✔
128
        PsiElement navigationElement = lightNamedElement.getNavigationElement();
1✔
129
        holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
1✔
130
          .range(ElementManipulators.getValueTextRange(navigationElement).shiftRight(lightNamedElement.getTextOffset()))
1✔
131
          .enforcedTextAttributes(adjustTextAttributes(currentScheme.getAttributes(currentKey), false))
1✔
132
          .create();
1✔
133
      }
1✔
134
    }
1✔
135
    else if (elementType == SUB_NAME) {
1✔
136
      PsiElement parent = element.getParent();
1✔
137
      if (parent instanceof PsiPerlSubDeclaration) {
1✔
138
        defaultSilentProducer.accept(PerlSyntaxHighlighter.PERL_SUB_DECLARATION);
1✔
139
      }
140
      else if (parent instanceof PerlSubDefinitionElement) {
1✔
141
        if (PerlSubUtil.SUB_AUTOLOAD.equals(((PerlSubNameElement)element).getName())) {
1✔
142
          defaultSilentProducer.accept(PerlSyntaxHighlighter.PERL_AUTOLOAD);
×
143
        }
144
        else {
145
          defaultSilentProducer.accept(PerlSyntaxHighlighter.PERL_SUB_DEFINITION);
1✔
146
        }
147
      }
148
      else if (parent instanceof PerlMethod perlMethod) {
1✔
149
        // fixme don't we need to take multiple references here?
150
        PsiElement grandParent = perlMethod.getParent();
1✔
151
        PerlNamespaceElement methodNamespace = perlMethod.getNamespaceElement();
1✔
152

153
        if (
1✔
154
          !PerlSubCallElement.isNestedCall(grandParent) /// not ...->method fixme shouldn't we use isObjectMethod here?
1✔
155
          && (methodNamespace == null || methodNamespace.isCORE())// no explicit NS or it's core
1✔
156
          && ((PerlSubNameElement)element).isBuiltIn()
1✔
157
        ) {
158
          createInfoAnnotation(holder, element, null, PerlSyntaxHighlighter.PERL_SUB_BUILTIN);
1✔
159
        }
160
        else {
161

162
          PsiReference reference = element.getReference();
1✔
163

164
          if (reference instanceof PerlSubReference perlSubReference) {
1✔
165
            perlSubReference.multiResolve(false);
1✔
166

167
            if (perlSubReference.isConstant()) {
1✔
168
              defaultAnnotationProducer.accept(PerlBundle.message("inspection.message.constant"), PerlSyntaxHighlighter.PERL_CONSTANT);
1✔
169
            }
170
            else if (perlSubReference.isAutoloaded()) {
1✔
NEW
171
              defaultAnnotationProducer.accept(PerlBundle.message("inspection.message.auto.loaded.sub"),
×
172
                                               PerlSyntaxHighlighter.PERL_AUTOLOAD);
173
            }
174
            else if (perlSubReference.isXSub()) {
1✔
175
              defaultAnnotationProducer.accept("XSub", PerlSyntaxHighlighter.PERL_XSUB);
×
176
            }
177
          }
178
        }
179
      }
180
    }
181
  }
1✔
182
}
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