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

Camelcade / Perl5-IDEA / #525521535

17 May 2025 12:51PM UTC coverage: 82.204% (+0.005%) from 82.199%
#525521535

push

github

hurricup
Suppressed deprecation warning in PerlImplicitVariableDeclaration

We can't avoid implementing this for now

30876 of 37560 relevant lines covered (82.2%)

0.82 hits per line

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

77.05
/plugin/core/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.stubs.IStubElementType;
23
import com.intellij.psi.tree.IElementType;
24
import com.intellij.util.Function;
25
import com.intellij.util.IncorrectOperationException;
26
import com.perl5.lang.perl.idea.presentations.PerlItemPresentationSimple;
27
import com.perl5.lang.perl.parser.PerlIdentifierRangeProvider;
28
import com.perl5.lang.perl.psi.PerlVisitor;
29
import com.perl5.lang.perl.psi.impl.PerlPolyNamedElement;
30
import org.jetbrains.annotations.NonNls;
31
import org.jetbrains.annotations.NotNull;
32
import org.jetbrains.annotations.Nullable;
33

34
import java.util.Objects;
35

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

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

46
  private boolean myIsImplicit = false;
1✔
47

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

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

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

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

70
  @Override
71
  public IStubElementType<?, PerlDelegatingLightNamedElement<?>> getElementType() {
72
    return (IStubElementType<?, PerlDelegatingLightNamedElement<?>>)super.getElementType();
1✔
73
  }
74

75
  protected final void setNameComputation(@NotNull Function<String, String> nameComputation) {
76
    myNameComputation = nameComputation;
1✔
77
  }
1✔
78

79
  @Override
80
  public @Nullable PsiElement getNameIdentifier() {
81
    if (myIsImplicit) {
1✔
82
      return null;
×
83
    }
84
    if (myNameIdentifier != null && myNameIdentifier.isValid()) {
1✔
85
      return myNameIdentifier;
1✔
86
    }
87

88
    for (PerlDelegatingLightNamedElement<?> element : getDelegate().computeLightElementsFromPsi()) {
1✔
89
      if (element.equals(this)) {
1✔
90
        return myNameIdentifier = element.getNameIdentifier();
1✔
91
      }
92
    }
1✔
93

94
    throw new PsiInvalidElementAccessException(this, myNameIdentifier == null
×
95
                                                     ? "Attempt to access element without identifier"
×
96
                                                     : "Could not restore valid identifier");
×
97
  }
98

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

115
  public @NotNull Function<String, String> getNameComputation() {
116
    return myNameComputation;
1✔
117
  }
118

119
  @Override
120
  public void navigate(boolean requestFocus) {
121
    PsiElement nameIdentifier = getNameIdentifier();
1✔
122
    if (nameIdentifier instanceof NavigatablePsiElement navigatablePsiElement) {
1✔
123
      navigatablePsiElement.navigate(requestFocus);
1✔
124
    }
125
    else {
126
      super.navigate(requestFocus);
×
127
    }
128
  }
1✔
129

130
  public boolean isImplicit() {
131
    return myIsImplicit;
1✔
132
  }
133

134
  public void setImplicit(boolean implicit) {
135
    myIsImplicit = implicit;
×
136
  }
×
137

138
  @Override
139
  public @NotNull PsiElement getNavigationElement() {
140
    return myIsImplicit ? getDelegate() : Objects.requireNonNull(getNameIdentifier());
1✔
141
  }
142

143
  @Override
144
  public int getTextOffset() {
145
    return getNavigationElement().getTextOffset();
1✔
146
  }
147

148
  @Override
149
  public TextRange getTextRange() {
150
    return myIsImplicit ? super.getTextRange() : Objects.requireNonNull(getNameIdentifier()).getTextRange();
1✔
151
  }
152

153
  @Override
154
  public boolean isValid() {
155
    return getDelegate().isValid() && (myIsImplicit || myNameIdentifier == null || myNameIdentifier.isValid());
1✔
156
  }
157

158
  @Override
159
  public boolean equals(Object o) {
160
    if (!(o instanceof PerlDelegatingLightNamedElement<?> namedElement)) {
1✔
161
      return false;
×
162
    }
163
    if (!super.equals(o)) {
1✔
164
      return false;
×
165
    }
166

167
    return myIsImplicit == namedElement.myIsImplicit && myName.equals(namedElement.myName);
1✔
168
  }
169

170
  @Override
171
  public int hashCode() {
172
    int result = super.hashCode();
1✔
173
    result = 31 * result + myName.hashCode();
1✔
174
    result = 31 * result + (myIsImplicit ? 1 : 0);
1✔
175
    return result;
1✔
176
  }
177

178
  @Override
179
  public void accept(@NotNull PsiElementVisitor visitor) {
180
    if (visitor instanceof PerlVisitor perlVisitor) {
×
181
      perlVisitor.visitLightNamedElement(this);
×
182
    }
183
    else {
184
      super.accept(visitor);
×
185
    }
186
  }
×
187

188
  @Override
189
  public ItemPresentation getPresentation() {
190
    return new PerlItemPresentationSimple(this, getName());
1✔
191
  }
192
}
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