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

Camelcade / Perl5-IDEA / #525521824

24 Apr 2026 06:38PM UTC coverage: 76.187% (+0.2%) from 75.952%
#525521824

push

github

hurricup
Pass a disposable to Registry.get to revert it in the end

14757 of 22542 branches covered (65.46%)

Branch coverage included in aggregate %.

31096 of 37643 relevant lines covered (82.61%)

0.83 hits per line

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

73.4
/plugin/common/src/main/java/com/perl5/lang/perl/psi/light/PerlDelegatingLightNamedElement.java
1
/*
2
 * Copyright 2015-2026 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 final 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) {
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

88
    throw new PsiInvalidElementAccessException(this, myNameIdentifier == null
×
89
                                                     ? "Attempt to access element without identifier"
×
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!
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 {
120
      super.navigate(requestFocus);
×
121
    }
122
  }
1✔
123

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

128
  @Override
129
  public @NotNull PsiElement getNavigationElement() {
130
    return myIsImplicit ? getDelegate() : Objects.requireNonNull(getNameIdentifier());
1!
131
  }
132

133
  @Override
134
  public int getTextOffset() {
135
    return getNavigationElement().getTextOffset();
1✔
136
  }
137

138
  @Override
139
  public TextRange getTextRange() {
140
    return myIsImplicit ? super.getTextRange() : Objects.requireNonNull(getNameIdentifier()).getTextRange();
1✔
141
  }
142

143
  @Override
144
  public boolean isValid() {
145
    return getDelegate().isValid() && (myIsImplicit || myNameIdentifier == null || myNameIdentifier.isValid());
1✔
146
  }
147

148
  @Override
149
  public boolean equals(Object o) {
150
    if (!(o instanceof PerlDelegatingLightNamedElement<?> namedElement)) {
1!
151
      return false;
×
152
    }
153
    if (!super.equals(o)) {
1!
154
      return false;
×
155
    }
156

157
    return myIsImplicit == namedElement.myIsImplicit && myName.equals(namedElement.myName);
1!
158
  }
159

160
  @Override
161
  public int hashCode() {
162
    int result = super.hashCode();
1✔
163
    result = 31 * result + myName.hashCode();
1✔
164
    result = 31 * result + (myIsImplicit ? 1 : 0);
1✔
165
    return result;
1✔
166
  }
167

168
  @Override
169
  public void accept(@NotNull PsiElementVisitor visitor) {
170
    if (visitor instanceof PerlVisitor perlVisitor) {
×
171
      perlVisitor.visitLightNamedElement(this);
×
172
    }
173
    else {
174
      super.accept(visitor);
×
175
    }
176
  }
×
177

178
  @Override
179
  public ItemPresentation getPresentation() {
180
    return new PerlItemPresentationSimple(this, getName());
1✔
181
  }
182
}
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