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

Camelcade / Perl5-IDEA / #525521731

12 Dec 2025 02:05AM UTC coverage: 75.907% (-0.03%) from 75.932%
#525521731

Pull #3132

github

web-flow
Merge c9cd2d0d2 into ec1d65ccb
Pull Request #3132: Bump actions/cache from 4 to 5

14747 of 22633 branches covered (65.16%)

Branch coverage included in aggregate %.

31065 of 37720 relevant lines covered (82.36%)

0.82 hits per line

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

70.77
/plugin/common/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.util.PsiTreeUtil;
22
import com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValue;
23
import com.perl5.lang.perl.psi.*;
24
import org.jetbrains.annotations.NotNull;
25
import org.jetbrains.annotations.Nullable;
26

27
import java.util.ArrayList;
28
import java.util.List;
29

30
import static com.perl5.lang.perl.idea.codeInsight.typeInference.value.PerlValues.UNKNOWN_VALUE;
31

32

33
public class PerlSubAnnotations {
34
  private static final byte IS_METHOD = 0x01;
35
  private static final byte IS_DEPRECATED = 0x02;
36
  private static final byte IS_ABSTRACT = 0x04;
37
  private static final byte IS_OVERRIDE = 0x08;
38

39
  private byte myFlags = 0;
1✔
40

41
  private @NotNull PerlValue myReturnValue = UNKNOWN_VALUE;
1✔
42

43
  public PerlSubAnnotations() {
1✔
44
  }
1✔
45

46
  public byte getFlags() {
47
    return myFlags;
1✔
48
  }
49

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

55
  public boolean isMethod() {
56
    return (myFlags & IS_METHOD) == IS_METHOD;
1✔
57
  }
58

59
  public void setIsMethod() {
60
    myFlags |= IS_METHOD;
1✔
61
  }
1✔
62

63
  public boolean isDeprecated() {
64
    return (myFlags & IS_DEPRECATED) == IS_DEPRECATED;
1✔
65
  }
66

67
  public void setIsDeprecated() {
68
    myFlags |= IS_DEPRECATED;
1✔
69
  }
1✔
70

71
  public boolean isAbstract() {
72
    return (myFlags & IS_ABSTRACT) == IS_ABSTRACT;
1!
73
  }
74

75
  public void setIsAbstract() {
76
    myFlags |= IS_ABSTRACT;
×
77
  }
×
78

79
  public boolean isOverride() {
80
    return (myFlags & IS_OVERRIDE) == IS_OVERRIDE;
1!
81
  }
82

83
  public void setIsOverride() {
84
    myFlags |= IS_OVERRIDE;
1✔
85
  }
1✔
86

87
  public @NotNull PerlValue getReturnValue() {
88
    return myReturnValue;
1!
89
  }
90

91
  public void setReturnValue(@NotNull PerlValue returnValue) {
92
    myReturnValue = returnValue;
1✔
93
  }
1✔
94

95
  @Override
96
  public boolean equals(Object o) {
97
    if (this == o) {
×
98
      return true;
×
99
    }
100
    if (o == null || getClass() != o.getClass()) {
×
101
      return false;
×
102
    }
103

104
    PerlSubAnnotations that = (PerlSubAnnotations)o;
×
105

106
    if (myFlags != that.myFlags) {
×
107
      return false;
×
108
    }
109
    return myReturnValue.equals(that.myReturnValue);
×
110
  }
111

112
  @Override
113
  public int hashCode() {
114
    int result = myFlags;
1✔
115
    result = 31 * result + myReturnValue.hashCode();
1✔
116
    return result;
1✔
117
  }
118

119
  /**
120
   * Attempts to build sub annotations from one of the base elements. Fist wins
121
   *
122
   * @param baseElements elements to process, e.g. identifier or use constant
123
   * @return Sub annotations
124
   */
125
  public static @Nullable PerlSubAnnotations tryToFindAnnotations(@NotNull PsiElement... baseElements) {
126
    for (PsiElement element : baseElements) {
1✔
127
      List<PerlAnnotation> annotations = PerlAnnotations.collectAnnotations(element);
1✔
128
      if (!annotations.isEmpty()) {
1✔
129
        return createFromAnnotationsList(annotations);
1✔
130
      }
131
    }
132

133
    return null;
1✔
134
  }
135

136
  public static @Nullable PerlSubAnnotations tryToFindAnnotations(@NotNull List<PsiElement> baseElements) {
137
    return tryToFindAnnotations(baseElements.toArray(PsiElement.EMPTY_ARRAY));
1✔
138
  }
139

140
  public static @Nullable PerlSubAnnotations createFromAnnotationsList(List<? extends PerlAnnotation> annotations) {
141
    if (annotations.isEmpty()) {
1✔
142
      return null;
1✔
143
    }
144

145
    PerlSubAnnotations result = new PerlSubAnnotations();
1✔
146

147
    for (PerlAnnotation annotation : annotations) {
1✔
148
      if (annotation instanceof PsiPerlAnnotationAbstract) {
1!
149
        result.setIsAbstract();
×
150
      }
151
      else if (annotation instanceof PsiPerlAnnotationDeprecated) {
1✔
152
        result.setIsDeprecated();
1✔
153
      }
154
      else if (annotation instanceof PsiPerlAnnotationMethod) {
1✔
155
        result.setIsMethod();
1✔
156
      }
157
      else if (annotation instanceof PsiPerlAnnotationOverride) {
1✔
158
        result.setIsOverride();
1✔
159
      }
160
      else if (annotation instanceof PsiPerlAnnotationReturns annotationReturns) {
1✔
161
        result.setReturnValue(annotationReturns.getValue());
1✔
162
      }
163
    }
1✔
164

165
    return result;
1✔
166
  }
167

168
  public static @Nullable PerlSubAnnotations computeForLightElement(@NotNull PsiElement delegate, @NotNull PsiElement nameIdentifier) {
169
    List<PsiElement> baseElements = new ArrayList<>();
1✔
170
    PsiPerlStatement containingStatement = PsiTreeUtil.getParentOfType(delegate, PsiPerlStatement.class);
1✔
171
    if (containingStatement != null) {
1!
172
      baseElements.add(containingStatement);
1✔
173
    }
174
    baseElements.add(delegate);
1✔
175

176
    if (nameIdentifier instanceof PerlStringContentElement) {
1!
177
      PerlStringList perlStringList = PsiTreeUtil.getParentOfType(nameIdentifier, PerlStringList.class);
×
178
      if (perlStringList != null) {
×
179
        baseElements.add(perlStringList);
×
180
      }
181
    }
×
182
    else {
183
      baseElements.add(nameIdentifier);
1✔
184
    }
185

186
    return tryToFindAnnotations(baseElements);
1✔
187
  }
188

189
  @Override
190
  public String toString() {
191
    List<String> result = new ArrayList<>();
1✔
192
    if (isMethod()) {
1!
193
      result.add("method");
×
194
    }
195
    if (isAbstract()) {
1!
196
      result.add("abstract");
×
197
    }
198
    if (isDeprecated()) {
1!
199
      result.add("deprecated");
1✔
200
    }
201
    if (isOverride()) {
1!
202
      result.add("override");
×
203
    }
204
    result.add("returns: " + myReturnValue);
1✔
205
    return StringUtil.join(result, "; ");
1✔
206
  }
207
}
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

© 2025 Coveralls, Inc