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

Camelcade / Perl5-IDEA / #525521578

05 Jun 2025 08:31AM UTC coverage: 82.354% (+0.06%) from 82.298%
#525521578

push

github

hurricup
Redundant throws

30858 of 37470 relevant lines covered (82.35%)

0.82 hits per line

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

78.82
/plugin/core/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.PerlValuesManager;
26
import com.perl5.lang.perl.psi.*;
27
import org.jetbrains.annotations.NotNull;
28
import org.jetbrains.annotations.Nullable;
29

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

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

36

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

43
  private byte myFlags = 0;
1✔
44

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

109
    PerlSubAnnotations that = (PerlSubAnnotations)o;
×
110

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

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

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

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

145
    return null;
1✔
146
  }
147

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

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

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

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

177
    return result;
1✔
178
  }
179

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

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

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

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