• 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

93.22
/plugin/core/src/main/java/com/perl5/lang/perl/psi/stubs/PerlPolyNamedElementType.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.stubs;
18

19
import com.intellij.lang.ASTNode;
20
import com.intellij.openapi.diagnostic.Logger;
21
import com.intellij.psi.PsiElement;
22
import com.intellij.psi.stubs.*;
23
import com.intellij.util.containers.ContainerUtil;
24
import com.perl5.lang.perl.PerlLanguage;
25
import com.perl5.lang.perl.parser.elementTypes.PsiElementProvider;
26
import com.perl5.lang.perl.psi.impl.PerlPolyNamedElement;
27
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
28
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
29
import org.jetbrains.annotations.NotNull;
30

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

35
import static com.perl5.lang.perl.parser.Class.Accessor.ClassAccessorElementTypes.CLASS_ACCESSOR_METHOD;
36
import static com.perl5.lang.perl.psi.stubs.PerlStubElementTypes.*;
37

38
public abstract class PerlPolyNamedElementType<Stub extends PerlPolyNamedElementStub<Psi>, Psi extends PerlPolyNamedElement<Stub>>
39
  extends IStubElementType<Stub, Psi> implements PsiElementProvider {
40
  private static final Logger LOG = Logger.getInstance(PerlPolyNamedElementType.class);
1✔
41
  private static final Object2IntOpenHashMap<IStubElementType<?, ?>> DIRECT_MAP = new Object2IntOpenHashMap<>();
1✔
42
  private static final Int2ObjectOpenHashMap<IStubElementType<?, ?>> REVERSE_MAP = new Int2ObjectOpenHashMap<>();
1✔
43

44
  static {
45
    // 0 is reserved for n/a
46
    DIRECT_MAP.put(LIGHT_SUB_DEFINITION, 1);
1✔
47
    DIRECT_MAP.put(LIGHT_NAMESPACE_DEFINITION, 2);
1✔
48
    DIRECT_MAP.put(LIGHT_METHOD_DEFINITION, 3);
1✔
49
    DIRECT_MAP.put(CLASS_ACCESSOR_METHOD, 4);
1✔
50
    DIRECT_MAP.put(LIGHT_ATTRIBUTE_DEFINITION, 5);
1✔
51
    LOG.assertTrue(DIRECT_MAP.size() == 5);
1✔
52

53
    DIRECT_MAP.forEach((type, id) -> REVERSE_MAP.put(id.intValue(), type));
1✔
54
  }
1✔
55

56
  public PerlPolyNamedElementType(@NotNull String debugName) {
57
    super(debugName, PerlLanguage.INSTANCE);
1✔
58
  }
1✔
59

60
  @Override
61
  public @NotNull Stub createStub(@NotNull Psi psi, StubElement<?> parentStub) {
62
    List<StubElement<?>> lightNamedElements = new ArrayList<>();
1✔
63
    Stub result = createStub(psi, parentStub, lightNamedElements);
1✔
64

65
    psi.getLightElements().forEach(lightPsi -> {
1✔
66
      StubElement<?> lightStubElement = lightPsi.getElementType().createStub(lightPsi, result);
1✔
67
      if (lightStubElement instanceof PerlLightElementStub lightElementStub && lightPsi.isImplicit()) {
1✔
68
        lightElementStub.setImplicit(true);
×
69
      }
70
      lightNamedElements.add(lightStubElement);
1✔
71
    });
1✔
72

73
    return result;
1✔
74
  }
75

76
  protected abstract @NotNull Stub createStub(@NotNull Psi psi,
77
                                              StubElement<?> parentStub,
78
                                              @NotNull List<StubElement<?>> lightElementsStubs);
79

80
  @Override
81
  public final @NotNull String getExternalId() {
82
    return "perl.poly." + super.toString();
1✔
83
  }
84

85
  @Override
86
  public final void serialize(@NotNull Stub stub, @NotNull StubOutputStream dataStream) throws IOException {
87
    List<StubElement<?>> childrenStubs = ContainerUtil.filter(stub.getLightNamedElementsStubs(), it ->
1✔
88
      !(it instanceof PerlLightElementStub elementStub) || !elementStub.isImplicit());
1✔
89
    dataStream.writeVarInt(childrenStubs.size());
1✔
90
    serializeStub(stub, dataStream);
1✔
91
    //noinspection rawtypes
92
    for (StubElement childStub : childrenStubs) {
1✔
93
      dataStream.writeVarInt(getSerializationId(childStub)); // serialization id
1✔
94
      getSerializer(childStub).serialize(childStub, dataStream);
1✔
95
    }
1✔
96
  }
1✔
97

98
  @SuppressWarnings("rawtypes")
99
  private static ObjectStubSerializer getSerializer(@NotNull StubElement<?> childStub) {
100
    var elementType = childStub.getElementType();
1✔
101
    LOG.assertTrue(elementType instanceof ObjectStubSerializer,
1✔
102
                   "Don't know how to serialize:" + elementType + "; " + elementType.getClass());
1✔
103
    return (ObjectStubSerializer)elementType;
1✔
104
  }
105

106
  protected void serializeStub(@NotNull Stub stub, @NotNull StubOutputStream dataStream) throws IOException {
107
    // to save additional data in subclasses
108
  }
×
109

110
  @Override
111
  public final @NotNull Stub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
112
    int size = dataStream.readVarInt();
1✔
113
    List<StubElement<?>> childStubs = new ArrayList<>(size);
1✔
114
    Stub result = deserialize(dataStream, parentStub, childStubs);
1✔
115

116
    for (int i = 0; i < size; i++) {
1✔
117
      childStubs.add(getElementTypeById(dataStream.readVarInt()).deserialize(dataStream, result));
1✔
118
    }
119

120
    return result;
1✔
121
  }
122

123
  protected abstract @NotNull Stub deserialize(@NotNull StubInputStream dataStream,
124
                                               StubElement<?> parentStub,
125
                                               @NotNull List<StubElement<?>> lightElementsStubs) throws IOException;
126

127
  @Override
128
  public final void indexStub(@NotNull Stub stub, @NotNull IndexSink sink) {
129
    stub.getLightNamedElementsStubs().forEach(childStub -> getSerializer(childStub).indexStub(childStub, sink));
1✔
130
    doIndexStub(stub, sink);
1✔
131
  }
1✔
132

133
  protected void doIndexStub(@NotNull Stub stub, @NotNull IndexSink sink) {
134
  }
1✔
135

136
  @Override
137
  public boolean shouldCreateStub(ASTNode node) {
138
    PsiElement psi = node.getPsi();
1✔
139
    assert psi instanceof PerlPolyNamedElement;
1✔
140
    return !((PerlPolyNamedElement<?>)psi).getLightElements().isEmpty();
1✔
141
  }
142

143
  private static int getSerializationId(@NotNull StubElement<?> stubElement) {
144
    int id = DIRECT_MAP.getInt(stubElement.getElementType());
1✔
145
    if (id > 0) {
1✔
146
      return id;
1✔
147
    }
148
    throw new IllegalArgumentException("Unregistered stub element class:" + stubElement.getElementType());
×
149
  }
150

151
  private static @NotNull IStubElementType<?, ?> getElementTypeById(int id) {
152
    assert id > 0;
1✔
153
    IStubElementType<?, ?> type = REVERSE_MAP.get(id);
1✔
154
    if (type != null) {
1✔
155
      return type;
1✔
156
    }
157
    throw new IllegalArgumentException("Unregistered stub element id:" + id);
×
158
  }
159
}
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