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

Camelcade / Perl5-IDEA / #525521551

26 May 2025 11:24AM UTC coverage: 82.32% (+0.001%) from 82.319%
#525521551

push

github

hurricup
Migrated to the presentation property

1 of 1 new or added line in 1 file covered. (100.0%)

148 existing lines in 15 files now uncovered.

30897 of 37533 relevant lines covered (82.32%)

0.82 hits per line

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

89.47
/plugin/core/src/main/java/com/perl5/lang/perl/psi/utils/PerlSubArgument.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.project.Project;
20
import com.intellij.openapi.util.text.StringUtil;
21
import com.intellij.psi.PsiElement;
22
import com.intellij.psi.stubs.StubInputStream;
23
import com.intellij.psi.stubs.StubOutputStream;
24
import com.intellij.psi.util.PsiUtilCore;
25
import com.perl5.lang.perl.idea.configuration.settings.PerlSharedSettings;
26
import com.perl5.lang.perl.lexer.PerlLexer;
27
import org.jetbrains.annotations.Contract;
28
import org.jetbrains.annotations.NonNls;
29
import org.jetbrains.annotations.NotNull;
30
import org.jetbrains.annotations.Nullable;
31

32
import java.io.IOException;
33
import java.util.ArrayList;
34
import java.util.Collections;
35
import java.util.List;
36
import java.util.Objects;
37

38
import static com.perl5.lang.perl.parser.PerlElementTypesGenerated.OPERATOR_ASSIGN;
39
import static com.perl5.lang.perl.parser.PerlElementTypesGenerated.SIGNATURE_ELEMENT;
40
import static com.perl5.lang.perl.util.PerlScalarUtil.DEFAULT_SELF_NAME;
41

42

43
public class PerlSubArgument {
44

45
  public static final @NonNls String NEW_VALUE_VALUE = "new_value";
46
  private final @NotNull PerlVariableType myArgumentType;
47
  private final @NotNull String myArgumentName;
48

49
  private final @NotNull String myVariableClass;
50

51
  private Boolean myIsOptional;
52

53
  private PerlSubArgument(@NotNull PerlVariableType variableType,
54
                          @NotNull String variableName,
55
                          @NotNull String variableClass,
56
                          boolean isOptional) {
1✔
57
    myArgumentType = variableType;
1✔
58
    myArgumentName = variableName;
1✔
59
    myIsOptional = isOptional;
1✔
60
    myVariableClass = variableClass;
1✔
61
  }
1✔
62

63
  public @NotNull PerlVariableType getArgumentType() {
64
    return myArgumentType;
1✔
65
  }
66

67
  public @NotNull String getArgumentName() {
68
    return myArgumentName;
1✔
69
  }
70

71
  public Boolean isOptional() {
72
    return myIsOptional;
1✔
73
  }
74

75
  public void setOptional(Boolean optional) {
76
    myIsOptional = optional;
1✔
77
  }
1✔
78

79
  public @NotNull String getVariableClass() {
80
    return myVariableClass;
1✔
81
  }
82

83
  public String toStringShort() {
84
    return StringUtil.isNotEmpty(myArgumentName) ? myArgumentType.getSigil() + myArgumentName : PerlLexer.STRING_UNDEF;
1✔
85
  }
86

87
  public String toStringLong() {
88
    if (StringUtil.isEmpty(myArgumentName)) {
1✔
89
      return PerlLexer.STRING_UNDEF;
1✔
90
    }
91

92
    String shortName = myArgumentType.getSigil() + myArgumentName;
1✔
93
    return StringUtil.isNotEmpty(myVariableClass) ? myVariableClass + " " + shortName : shortName;
1✔
94
  }
95

96
  @Override
97
  public String toString() {
98
    String toString = toStringLong();
1✔
99
    return myIsOptional ? "[" + toString + "]" : toString;
1✔
100
  }
101

102
  private void serialize(@NotNull StubOutputStream dataStream) throws IOException {
103
    dataStream.writeName(myArgumentType.toString());
1✔
104
    dataStream.writeName(myArgumentName);
1✔
105
    dataStream.writeName(myVariableClass);
1✔
106
    dataStream.writeBoolean(myIsOptional);
1✔
107
  }
1✔
108

109
  public boolean isSelf(Project project) {
110
    return getArgumentType() == PerlVariableType.SCALAR && PerlSharedSettings.getInstance(project).isSelfName(getArgumentName());
1✔
111
  }
112

113
  public boolean isEmpty() {
114
    return StringUtil.isEmpty(myArgumentName);
1✔
115
  }
116

117
  public PerlContextType getContextType() {
118
    if (myArgumentType == PerlVariableType.SCALAR || myArgumentType == PerlVariableType.CODE || myArgumentType == PerlVariableType.GLOB) {
1✔
119
      return PerlContextType.SCALAR;
1✔
120
    }
121
    return PerlContextType.LIST;
1✔
122
  }
123

124
  @Override
125
  public boolean equals(Object o) {
126
    if (this == o) {
1✔
UNCOV
127
      return true;
×
128
    }
129
    if (o == null || getClass() != o.getClass()) {
1✔
UNCOV
130
      return false;
×
131
    }
132

133
    PerlSubArgument argument = (PerlSubArgument)o;
1✔
134

135
    return myArgumentType == argument.myArgumentType &&
1✔
136
           myArgumentName.equals(argument.myArgumentName) &&
1✔
137
           myVariableClass.equals(argument.myVariableClass) &&
1✔
138
           (Objects.equals(myIsOptional, argument.myIsOptional));
1✔
139
  }
140

141
  @Override
142
  public int hashCode() {
143
    int result = myArgumentType.hashCode();
1✔
144
    result = 31 * result + myArgumentName.hashCode();
1✔
145
    result = 31 * result + myVariableClass.hashCode();
1✔
146
    result = 31 * result + (myIsOptional != null ? myIsOptional.hashCode() : 0);
1✔
147
    return result;
1✔
148
  }
149

150
  public static PerlSubArgument optional(@NotNull PerlVariableType variableType, @NotNull String variableName) {
UNCOV
151
    return create(variableType, variableName, true);
×
152
  }
153

154
  public static PerlSubArgument optionalScalar(@NotNull String variableName) {
155
    return create(PerlVariableType.SCALAR, variableName, true);
1✔
156
  }
157

158
  public static PerlSubArgument optionalScalar(@NotNull String variableName, @Nullable String variableClass) {
159
    return create(PerlVariableType.SCALAR, variableName, variableClass == null ? "" : variableClass, true);
1✔
160
  }
161

162
  public static PerlSubArgument mandatoryScalar(@NotNull String variableName) {
163
    return mandatoryScalar(variableName, "");
1✔
164
  }
165

166
  public static @NotNull PerlSubArgument mandatoryScalar(@NotNull String variableName, @NotNull String variableClass) {
167
    return mandatory(PerlVariableType.SCALAR, variableName, variableClass);
1✔
168
  }
169

170
  public static PerlSubArgument mandatory(@NotNull PerlVariableType variableType, @NotNull String variableName) {
171
    return create(variableType, variableName, false);
1✔
172
  }
173

174
  public static PerlSubArgument mandatory(@NotNull PerlVariableType variableType,
175
                                          @NotNull String variableName,
176
                                          @NotNull String variableClass) {
177
    return create(variableType, variableName, variableClass, false);
1✔
178
  }
179

180
  public static PerlSubArgument create(@NotNull PerlVariableType variableType, @NotNull String variableName, boolean isOptional) {
181
    return create(variableType, variableName, "", isOptional);
1✔
182
  }
183

184
  public static PerlSubArgument create(@NotNull PerlVariableType variableType,
185
                                       @NotNull String variableName,
186
                                       @NotNull String variableClass,
187
                                       boolean isOptional) {
188
    return new PerlSubArgument(variableType, variableName, variableClass, isOptional);
1✔
189
  }
190

191
  @SuppressWarnings("ConstantConditions")
192
  private static PerlSubArgument deserialize(@NotNull StubInputStream dataStream) throws IOException {
193
    PerlVariableType argumentType = PerlVariableType.valueOf(dataStream.readName().toString());
1✔
194
    String argumentName = dataStream.readName().toString();
1✔
195
    String variableClass = dataStream.readName().toString();
1✔
196
    boolean isOptional = dataStream.readBoolean();
1✔
197
    return PerlSubArgument.create(argumentType, argumentName, variableClass, isOptional);
1✔
198
  }
199

200
  public static @NotNull List<PerlSubArgument> deserializeList(@NotNull StubInputStream dataStream) throws IOException {
201
    int argumentsNumber = dataStream.readVarInt();
1✔
202

203
    if (argumentsNumber <= 0) {
1✔
204
      return Collections.emptyList();
1✔
205
    }
206
    List<PerlSubArgument> arguments = new ArrayList<>(argumentsNumber);
1✔
207
    for (int i = 0; i < argumentsNumber; i++) {
1✔
208
      arguments.add(deserialize(dataStream));
1✔
209
    }
210
    return arguments;
1✔
211
  }
212

213
  public static PerlSubArgument empty() {
214
    return mandatoryScalar("");
1✔
215
  }
216

217
  public static PerlSubArgument self() {
218
    return mandatoryScalar(DEFAULT_SELF_NAME);
1✔
219
  }
220

221
  public static void serializeList(@NotNull StubOutputStream dataStream, List<PerlSubArgument> arguments) throws IOException {
222
    dataStream.writeVarInt(arguments.size());
1✔
223
    for (PerlSubArgument argument : arguments) {
1✔
224
      argument.serialize(dataStream);
1✔
225
    }
1✔
226
  }
1✔
227

228
  /**
229
   * @return true iff {@code psiElement} is default value of sub/method/modifier parameter specified in signature
230
   */
231
  @Contract("null->false")
232
  public static boolean isDefaultValue(@Nullable PsiElement psiElement) {
233
    if (psiElement == null) {
×
UNCOV
234
      return false;
×
235
    }
236
    if (PsiUtilCore.getElementType(psiElement.getParent()) != SIGNATURE_ELEMENT) {
×
UNCOV
237
      return false;
×
238
    }
UNCOV
239
    return PsiUtilCore.getElementType(PerlPsiUtil.getPrevSignificantSibling(psiElement)) == OPERATOR_ASSIGN;
×
240
  }
241
}
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