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

pmd / pmd / 277

27 Nov 2025 01:37PM UTC coverage: 78.778% (+0.03%) from 78.749%
277

push

github

adangel
[java] UseArraysAsList: skip when if-statements (#6228)

18419 of 24233 branches covered (76.01%)

Branch coverage included in aggregate %.

40090 of 50038 relevant lines covered (80.12%)

0.81 hits per line

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

77.36
/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ArraySymbolImpl.java
1
/*
2
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3
 */
4

5
package net.sourceforge.pmd.lang.java.types;
6

7
import static net.sourceforge.pmd.util.CollectionUtil.listOf;
8

9
import java.lang.reflect.Modifier;
10
import java.util.Collections;
11
import java.util.List;
12
import java.util.Objects;
13

14
import org.checkerframework.checker.nullness.qual.NonNull;
15
import org.checkerframework.checker.nullness.qual.Nullable;
16
import org.objectweb.asm.Opcodes;
17

18
import net.sourceforge.pmd.lang.java.symbols.JClassSymbol;
19
import net.sourceforge.pmd.lang.java.symbols.JConstructorSymbol;
20
import net.sourceforge.pmd.lang.java.symbols.JExecutableSymbol;
21
import net.sourceforge.pmd.lang.java.symbols.JFieldSymbol;
22
import net.sourceforge.pmd.lang.java.symbols.JMethodSymbol;
23
import net.sourceforge.pmd.lang.java.symbols.JTypeDeclSymbol;
24
import net.sourceforge.pmd.lang.java.symbols.SymbolVisitor;
25
import net.sourceforge.pmd.lang.java.symbols.internal.ImplicitMemberSymbols;
26
import net.sourceforge.pmd.lang.java.symbols.internal.SymbolEquality;
27
import net.sourceforge.pmd.lang.java.symbols.internal.SymbolToStrings;
28

29
/**
30
 * Generic implementation for array symbols, which does not rely on
31
 * reflection.
32
 */
33
class ArraySymbolImpl implements JClassSymbol {
34

35
    // Like Class::getModifiers, we preserve the public/private/protected flag
36
    private static final int COMPONENT_MOD_MASK =
37
        Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC;
38

39
    private final TypeSystem ts;
40
    private final JTypeDeclSymbol component;
41

42
    ArraySymbolImpl(TypeSystem ts, JTypeDeclSymbol component) {
1✔
43
        this.component = Objects.requireNonNull(component, "Array symbol requires component");
1✔
44
        this.ts = Objects.requireNonNull(ts, "Array symbol requires symbol factory");
1✔
45
        if (component instanceof JClassSymbol && ((JClassSymbol) component).isAnonymousClass()) {
1!
46
            throw new IllegalArgumentException("Anonymous classes cannot be array components: " + component);
×
47
        }
48
    }
1✔
49

50
    @Override
51
    public TypeSystem getTypeSystem() {
52
        return ts;
1✔
53
    }
54

55
    @Override
56
    public @NonNull String getBinaryName() {
57
        if (component instanceof JClassSymbol) {
1✔
58
            return ((JClassSymbol) component).getBinaryName() + "[]";
1✔
59
        }
60
        return component.getSimpleName() + "[]";
1✔
61
    }
62

63
    @Override
64
    public String getCanonicalName() {
65
        if (component instanceof JClassSymbol) {
1✔
66
            String compName = ((JClassSymbol) component).getCanonicalName();
1✔
67
            return compName == null ? null : compName + "[]";
1!
68
        }
69
        return component.getSimpleName() + "[]";
1✔
70
    }
71

72
    @Override
73
    public boolean isUnresolved() {
74
        return false;
1✔
75
    }
76

77
    @Override
78
    public @Nullable JExecutableSymbol getEnclosingMethod() {
79
        return null;
×
80
    }
81

82
    @Override
83
    public List<JMethodSymbol> getDeclaredMethods() {
84
        return Collections.singletonList(ImplicitMemberSymbols.arrayClone(this));
1✔
85
    }
86

87
    @Override
88
    public List<JFieldSymbol> getDeclaredFields() {
89
        return Collections.singletonList(ImplicitMemberSymbols.arrayLengthField(this));
1✔
90
    }
91

92
    @Override
93
    public @Nullable JClassSymbol getSuperclass() {
94
        return getTypeSystem().OBJECT.getSymbol();
1✔
95
    }
96

97
    @Override
98
    public List<JClassSymbol> getSuperInterfaces() {
99
        return listOf(getTypeSystem().CLONEABLE.getSymbol(), getTypeSystem().SERIALIZABLE.getSymbol());
1✔
100
    }
101

102
    @Override
103
    public List<JClassType> getSuperInterfaceTypes(Substitution substitution) {
104
        return listOf(getTypeSystem().CLONEABLE, getTypeSystem().SERIALIZABLE);
×
105
    }
106

107
    @Override
108
    public @Nullable JClassType getSuperclassType(Substitution substitution) {
109
        return getTypeSystem().OBJECT;
×
110
    }
111

112
    @Override
113
    public @NonNull JTypeDeclSymbol getArrayComponent() {
114
        return component;
1✔
115
    }
116

117
    @Override
118
    public <R, P> R acceptVisitor(SymbolVisitor<R, P> visitor, P param) {
119
        return visitor.visitArray(this, component, param);
1✔
120
    }
121

122
    @Override
123
    public boolean equals(Object o) {
124
        return SymbolEquality.equals(this, o);
1✔
125
    }
126

127
    @Override
128
    public int hashCode() {
129
        return SymbolEquality.hash(this);
1✔
130
    }
131

132
    @Override
133
    public boolean isAnnotation() {
134
        return false;
1✔
135
    }
136

137
    @Override
138
    public List<JClassSymbol> getDeclaredClasses() {
139
        return Collections.emptyList();
×
140
    }
141

142
    @Override
143
    public List<JConstructorSymbol> getConstructors() {
144
        return Collections.singletonList(ImplicitMemberSymbols.arrayConstructor(this));
1✔
145
    }
146

147
    @Override
148
    public @NonNull String getPackageName() {
149
        return getArrayComponent().getPackageName();
1✔
150
    }
151

152
    @Override
153
    public @NonNull String getSimpleName() {
154
        return getArrayComponent().getSimpleName() + "[]";
1✔
155
    }
156

157
    @Override
158
    public int getModifiers() {
159
        int comp = getArrayComponent().getModifiers() & COMPONENT_MOD_MASK;
1✔
160
        return Modifier.FINAL | Modifier.ABSTRACT | comp;
1✔
161
    }
162

163
    @Override
164
    public List<JTypeVar> getTypeParameters() {
165
        return Collections.emptyList();
1✔
166
    }
167

168
    @Override
169
    public @Nullable JClassSymbol getEnclosingClass() {
170
        return null;
×
171
    }
172

173
    @Override
174
    public boolean isArray() {
175
        return true;
1✔
176
    }
177

178
    @Override
179
    public boolean isPrimitive() {
180
        return false;
×
181
    }
182

183
    @Override
184
    public boolean isInterface() {
185
        return false;
1✔
186
    }
187

188
    @Override
189
    public boolean isEnum() {
190
        return false;
×
191
    }
192

193
    @Override
194
    public boolean isRecord() {
195
        return false;
×
196
    }
197

198
    @Override
199
    public boolean isLocalClass() {
200
        return false;
×
201
    }
202

203
    @Override
204
    public boolean isAnonymousClass() {
205
        return false;
1✔
206
    }
207

208
    @Override
209
    public String toString() {
210
        return SymbolToStrings.SHARED.toString(this);
1✔
211
    }
212

213
}
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