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

Camelcade / Perl5-IDEA / #525521616

07 Jul 2025 01:01PM UTC coverage: 82.387% (+0.03%) from 82.356%
#525521616

push

github

hurricup
J2K: PerlMethodDefinitionElementType

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

22 existing lines in 5 files now uncovered.

30915 of 37524 relevant lines covered (82.39%)

0.82 hits per line

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

76.67
/plugin/backend/src/main/java/com/perl5/lang/perl/psi/light/PerlDelegatingLightNamedElement.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.light;
18

19
import com.intellij.navigation.ItemPresentation;
20
import com.intellij.openapi.util.TextRange;
21
import com.intellij.psi.*;
22
import com.intellij.psi.tree.IElementType;
23
import com.intellij.util.Function;
24
import com.intellij.util.IncorrectOperationException;
25
import com.perl5.lang.perl.idea.presentations.PerlItemPresentationSimple;
26
import com.perl5.lang.perl.parser.PerlIdentifierRangeProvider;
27
import com.perl5.lang.perl.psi.PerlVisitor;
28
import com.perl5.lang.perl.psi.impl.PerlPolyNamedElement;
29
import org.jetbrains.annotations.NonNls;
30
import org.jetbrains.annotations.NotNull;
31
import org.jetbrains.annotations.Nullable;
32

33
import java.util.Objects;
34

35
/**
36
 * Represents one of the declarations of {@link PerlPolyNamedElement}
37
 */
38
public class PerlDelegatingLightNamedElement<Delegate extends PerlPolyNamedElement<?>> extends PerlDelegatingLightElement<Delegate>
39
  implements PsiNameIdentifierOwner {
40
  public static final Function<String, String> DEFAULT_NAME_COMPUTATION = name -> name;
1✔
41

42
  protected @NotNull String myName;
43
  private @Nullable PsiElement myNameIdentifier;
44

45
  private boolean myIsImplicit = false;
1✔
46

47
  private @NotNull Function<String, String> myNameComputation = DEFAULT_NAME_COMPUTATION;
1✔
48

49
  public PerlDelegatingLightNamedElement(@NotNull Delegate delegate,
50
                                         @NotNull String name,
51
                                         @NotNull IElementType elementType) {
52
    this(delegate, name, elementType, null);
1✔
53
  }
1✔
54

55
  public PerlDelegatingLightNamedElement(@NotNull Delegate delegate,
56
                                         @NotNull String name,
57
                                         @NotNull IElementType elementType,
58
                                         @Nullable PsiElement nameIdentifier) {
59
    super(delegate, elementType);
1✔
60
    myName = name;
1✔
61
    myNameIdentifier = nameIdentifier;
1✔
62
  }
1✔
63

64
  @Override
65
  public @NotNull String getName() {
66
    return myName;
1✔
67
  }
68

69
  protected final void setNameComputation(@NotNull Function<String, String> nameComputation) {
70
    myNameComputation = nameComputation;
1✔
71
  }
1✔
72

73
  @Override
74
  public @Nullable PsiElement getNameIdentifier() {
75
    if (myIsImplicit) {
1✔
UNCOV
76
      return null;
×
77
    }
78
    if (myNameIdentifier != null && myNameIdentifier.isValid()) {
1✔
79
      return myNameIdentifier;
1✔
80
    }
81

82
    for (PerlDelegatingLightNamedElement<?> element : getDelegate().computeLightElementsFromPsi()) {
1✔
83
      if (element.equals(this)) {
1✔
84
        return myNameIdentifier = element.getNameIdentifier();
1✔
85
      }
86
    }
1✔
87

UNCOV
88
    throw new PsiInvalidElementAccessException(this, myNameIdentifier == null
×
UNCOV
89
                                                     ? "Attempt to access element without identifier"
×
UNCOV
90
                                                     : "Could not restore valid identifier");
×
91
  }
92

93
  @Override
94
  public PsiElement setName(@NonNls @NotNull String newBaseName) throws IncorrectOperationException {
95
    // fixme should be in com.perl5.lang.perl.psi.utils.PerlPsiUtil.renameElement()
96
    PsiElement nameIdentifier = getNameIdentifier();
1✔
97
    if (nameIdentifier == null) {
1✔
UNCOV
98
      return this;
×
99
    }
100
    ElementManipulator<PsiElement> manipulator = ElementManipulators.getManipulator(nameIdentifier);
1✔
101
    TextRange identifierRange = this instanceof PerlIdentifierRangeProvider
1✔
102
                                ? ((PerlIdentifierRangeProvider)this).getRangeInIdentifier()
1✔
103
                                : ElementManipulators.getValueTextRange(nameIdentifier);
1✔
104
    myNameIdentifier = manipulator.handleContentChange(nameIdentifier, identifierRange, newBaseName);
1✔
105
    myName = getNameComputation().fun(newBaseName);
1✔
106
    return this;
1✔
107
  }
108

109
  public @NotNull Function<String, String> getNameComputation() {
110
    return myNameComputation;
1✔
111
  }
112

113
  @Override
114
  public void navigate(boolean requestFocus) {
115
    PsiElement nameIdentifier = getNameIdentifier();
1✔
116
    if (nameIdentifier instanceof NavigatablePsiElement navigatablePsiElement) {
1✔
117
      navigatablePsiElement.navigate(requestFocus);
1✔
118
    }
119
    else {
UNCOV
120
      super.navigate(requestFocus);
×
121
    }
122
  }
1✔
123

124
  public boolean isImplicit() {
125
    return myIsImplicit;
1✔
126
  }
127

128
  public void setImplicit(boolean implicit) {
UNCOV
129
    myIsImplicit = implicit;
×
UNCOV
130
  }
×
131

132
  @Override
133
  public @NotNull PsiElement getNavigationElement() {
134
    return myIsImplicit ? getDelegate() : Objects.requireNonNull(getNameIdentifier());
1✔
135
  }
136

137
  @Override
138
  public int getTextOffset() {
139
    return getNavigationElement().getTextOffset();
1✔
140
  }
141

142
  @Override
143
  public TextRange getTextRange() {
144
    return myIsImplicit ? super.getTextRange() : Objects.requireNonNull(getNameIdentifier()).getTextRange();
1✔
145
  }
146

147
  @Override
148
  public boolean isValid() {
149
    return getDelegate().isValid() && (myIsImplicit || myNameIdentifier == null || myNameIdentifier.isValid());
1✔
150
  }
151

152
  @Override
153
  public boolean equals(Object o) {
154
    if (!(o instanceof PerlDelegatingLightNamedElement<?> namedElement)) {
1✔
UNCOV
155
      return false;
×
156
    }
157
    if (!super.equals(o)) {
1✔
UNCOV
158
      return false;
×
159
    }
160

161
    return myIsImplicit == namedElement.myIsImplicit && myName.equals(namedElement.myName);
1✔
162
  }
163

164
  @Override
165
  public int hashCode() {
166
    int result = super.hashCode();
1✔
167
    result = 31 * result + myName.hashCode();
1✔
168
    result = 31 * result + (myIsImplicit ? 1 : 0);
1✔
169
    return result;
1✔
170
  }
171

172
  @Override
173
  public void accept(@NotNull PsiElementVisitor visitor) {
UNCOV
174
    if (visitor instanceof PerlVisitor perlVisitor) {
×
UNCOV
175
      perlVisitor.visitLightNamedElement(this);
×
176
    }
177
    else {
UNCOV
178
      super.accept(visitor);
×
179
    }
180
  }
×
181

182
  @Override
183
  public ItemPresentation getPresentation() {
184
    return new PerlItemPresentationSimple(this, getName());
1✔
185
  }
186
}
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