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

Camelcade / Perl5-IDEA / #525521628

13 Jul 2025 04:11PM UTC coverage: 82.308% (-0.07%) from 82.38%
#525521628

push

github

hurricup
#2842 #3039 Moved values deserialization to helper class

Fixes #3039

47 of 49 new or added lines in 37 files covered. (95.92%)

120 existing lines in 32 files now uncovered.

30868 of 37503 relevant lines covered (82.31%)

0.82 hits per line

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

78.82
/plugin/backend/src/main/java/com/perl5/lang/perl/psi/utils/PerlSubAnnotations.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.psi.utils;
18

19
import com.intellij.openapi.util.text.StringUtil;
20
import com.intellij.psi.PsiElement;
21
import com.intellij.psi.stubs.StubInputStream;
22
import com.intellij.psi.stubs.StubOutputStream;
23
import com.intellij.psi.util.PsiTreeUtil;
24
import com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue;
25
import com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValueSerializer;
26
import com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValuesManager;
27
import com.perl5.lang.perl.psi.*;
28
import org.jetbrains.annotations.NotNull;
29
import org.jetbrains.annotations.Nullable;
30

31
import java.io.IOException;
32
import java.util.ArrayList;
33
import java.util.List;
34

35
import static com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValues.UNKNOWN_VALUE;
36

37

38
public class PerlSubAnnotations {
39
  private static final byte IS_METHOD = 0x01;
40
  private static final byte IS_DEPRECATED = 0x02;
41
  private static final byte IS_ABSTRACT = 0x04;
42
  private static final byte IS_OVERRIDE = 0x08;
43

44
  private byte myFlags = 0;
1✔
45

46
  private @NotNull PerlValue myReturnValue = UNKNOWN_VALUE;
1✔
47

48
  public PerlSubAnnotations() {
1✔
49
  }
1✔
50

51
  private PerlSubAnnotations(byte flags, @NotNull PerlValue returnValue) {
1✔
52
    myFlags = flags;
1✔
53
    myReturnValue = returnValue;
1✔
54
  }
1✔
55

56
  public void serialize(@NotNull StubOutputStream dataStream) throws IOException {
57
    dataStream.writeByte(myFlags);
1✔
58
    PerlValueSerializer.serialize(myReturnValue, dataStream);
1✔
59
  }
1✔
60

61
  public boolean isMethod() {
62
    return (myFlags & IS_METHOD) == IS_METHOD;
1✔
63
  }
64

65
  public void setIsMethod() {
66
    myFlags |= IS_METHOD;
1✔
67
  }
1✔
68

69
  public boolean isDeprecated() {
70
    return (myFlags & IS_DEPRECATED) == IS_DEPRECATED;
1✔
71
  }
72

73
  public void setIsDeprecated() {
74
    myFlags |= IS_DEPRECATED;
1✔
75
  }
1✔
76

77
  public boolean isAbstract() {
78
    return (myFlags & IS_ABSTRACT) == IS_ABSTRACT;
1✔
79
  }
80

81
  public void setIsAbstract() {
82
    myFlags |= IS_ABSTRACT;
×
UNCOV
83
  }
×
84

85
  public boolean isOverride() {
86
    return (myFlags & IS_OVERRIDE) == IS_OVERRIDE;
1✔
87
  }
88

89
  public void setIsOverride() {
90
    myFlags |= IS_OVERRIDE;
1✔
91
  }
1✔
92

93
  public @NotNull PerlValue getReturnValue() {
94
    return myReturnValue;
1✔
95
  }
96

97
  public void setReturnValue(@NotNull PerlValue returnValue) {
98
    myReturnValue = returnValue;
1✔
99
  }
1✔
100

101
  @Override
102
  public boolean equals(Object o) {
103
    if (this == o) {
×
UNCOV
104
      return true;
×
105
    }
106
    if (o == null || getClass() != o.getClass()) {
×
UNCOV
107
      return false;
×
108
    }
109

UNCOV
110
    PerlSubAnnotations that = (PerlSubAnnotations)o;
×
111

112
    if (myFlags != that.myFlags) {
×
UNCOV
113
      return false;
×
114
    }
UNCOV
115
    return myReturnValue.equals(that.myReturnValue);
×
116
  }
117

118
  @Override
119
  public int hashCode() {
120
    int result = myFlags;
1✔
121
    result = 31 * result + myReturnValue.hashCode();
1✔
122
    return result;
1✔
123
  }
124

125
  public static PerlSubAnnotations deserialize(@NotNull StubInputStream dataStream) throws IOException {
126
    return new PerlSubAnnotations(
1✔
127
      dataStream.readByte(),
1✔
128
      PerlValuesManager.readValue(dataStream)
1✔
129
    );
130
  }
131

132
  /**
133
   * Attempts to build sub annotations from one of the base elements. Fist wins
134
   *
135
   * @param baseElements elements to process, e.g. identifier or use constant
136
   * @return Sub annotations
137
   */
138
  public static @Nullable PerlSubAnnotations tryToFindAnnotations(@NotNull PsiElement... baseElements) {
139
    for (PsiElement element : baseElements) {
1✔
140
      List<PerlAnnotation> annotations = PerlAnnotations.collectAnnotations(element);
1✔
141
      if (!annotations.isEmpty()) {
1✔
142
        return createFromAnnotationsList(annotations);
1✔
143
      }
144
    }
145

146
    return null;
1✔
147
  }
148

149
  public static @Nullable PerlSubAnnotations tryToFindAnnotations(@NotNull List<PsiElement> baseElements) {
150
    return tryToFindAnnotations(baseElements.toArray(PsiElement.EMPTY_ARRAY));
1✔
151
  }
152

153
  public static @Nullable PerlSubAnnotations createFromAnnotationsList(List<? extends PerlAnnotation> annotations) {
154
    if (annotations.isEmpty()) {
1✔
155
      return null;
1✔
156
    }
157

158
    PerlSubAnnotations result = new PerlSubAnnotations();
1✔
159

160
    for (PerlAnnotation annotation : annotations) {
1✔
161
      if (annotation instanceof PsiPerlAnnotationAbstract) {
1✔
UNCOV
162
        result.setIsAbstract();
×
163
      }
164
      else if (annotation instanceof PsiPerlAnnotationDeprecated) {
1✔
165
        result.setIsDeprecated();
1✔
166
      }
167
      else if (annotation instanceof PsiPerlAnnotationMethod) {
1✔
168
        result.setIsMethod();
1✔
169
      }
170
      else if (annotation instanceof PsiPerlAnnotationOverride) {
1✔
171
        result.setIsOverride();
1✔
172
      }
173
      else if (annotation instanceof PsiPerlAnnotationReturns annotationReturns) {
1✔
174
        result.setReturnValue(annotationReturns.getValue());
1✔
175
      }
176
    }
1✔
177

178
    return result;
1✔
179
  }
180

181
  public static @Nullable PerlSubAnnotations computeForLightElement(@NotNull PsiElement delegate, @NotNull PsiElement nameIdentifier) {
182
    List<PsiElement> baseElements = new ArrayList<>();
1✔
183
    PsiPerlStatement containingStatement = PsiTreeUtil.getParentOfType(delegate, PsiPerlStatement.class);
1✔
184
    if (containingStatement != null) {
1✔
185
      baseElements.add(containingStatement);
1✔
186
    }
187
    baseElements.add(delegate);
1✔
188

189
    if (nameIdentifier instanceof PerlStringContentElement) {
1✔
190
      PerlStringList perlStringList = PsiTreeUtil.getParentOfType(nameIdentifier, PerlStringList.class);
×
191
      if (perlStringList != null) {
×
UNCOV
192
        baseElements.add(perlStringList);
×
193
      }
UNCOV
194
    }
×
195
    else {
196
      baseElements.add(nameIdentifier);
1✔
197
    }
198

199
    return tryToFindAnnotations(baseElements);
1✔
200
  }
201

202
  @Override
203
  public String toString() {
204
    List<String> result = new ArrayList<>();
1✔
205
    if (isMethod()) {
1✔
UNCOV
206
      result.add("method");
×
207
    }
208
    if (isAbstract()) {
1✔
UNCOV
209
      result.add("abstract");
×
210
    }
211
    if (isDeprecated()) {
1✔
212
      result.add("deprecated");
1✔
213
    }
214
    if (isOverride()) {
1✔
UNCOV
215
      result.add("override");
×
216
    }
217
    result.add("returns: " + myReturnValue);
1✔
218
    return StringUtil.join(result, "; ");
1✔
219
  }
220
}
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