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

pmd / pmd / #3722

pending completion
#3722

push

github actions

adangel
Suppress MissingOverride for Chars::isEmpty (#4291)

67270 of 127658 relevant lines covered (52.7%)

0.53 hits per line

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

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

5

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

8
import java.util.List;
9
import java.util.function.Function;
10
import java.util.function.Predicate;
11
import java.util.stream.Stream;
12

13
import org.checkerframework.checker.nullness.qual.NonNull;
14
import org.pcollections.HashTreePSet;
15
import org.pcollections.PSet;
16

17
import net.sourceforge.pmd.lang.java.symbols.JClassSymbol;
18
import net.sourceforge.pmd.lang.java.symbols.JMethodSymbol;
19
import net.sourceforge.pmd.lang.java.symbols.JTypeDeclSymbol;
20
import net.sourceforge.pmd.lang.java.symbols.SymbolicValue.SymAnnot;
21
import net.sourceforge.pmd.util.CollectionUtil;
22

23
/**
24
 * An array type (1 dimension). Multi-level arrays have an array type
25
 * as component themselves.
26
 */
27
public final class JArrayType implements JTypeMirror {
1✔
28

29
    private final JTypeMirror component;
30
    private final TypeSystem ts;
31
    private final PSet<SymAnnot> typeAnnots;
32
    private JClassSymbol symbol;
33

34
    JArrayType(TypeSystem ts, JTypeMirror component) {
35
        this(ts, component, null, HashTreePSet.empty());
1✔
36
    }
1✔
37

38
    JArrayType(TypeSystem ts, JTypeMirror component, JClassSymbol arraySymbol, PSet<SymAnnot> typeAnnots) {
1✔
39
        assert component != null : "Expected non-null component";
1✔
40
        assert typeAnnots != null : "Expected non-null annotations";
1✔
41
        this.component = component;
1✔
42
        this.ts = ts;
1✔
43
        this.symbol = arraySymbol;
1✔
44
        this.typeAnnots = typeAnnots;
1✔
45
    }
1✔
46

47
    @Override
48
    public TypeSystem getTypeSystem() {
49
        return ts;
1✔
50
    }
51

52
    @Override
53
    public @NonNull JClassSymbol getSymbol() {
54
        if (symbol == null) {
1✔
55
            JTypeDeclSymbol comp = getComponentType().getSymbol();
1✔
56
            if (comp == null) {
1✔
57
                comp = getComponentType().getErasure().getSymbol();
×
58
            }
59
            symbol = new ArraySymbolImpl(ts, comp); // will nullcheck
1✔
60
        }
61
        return symbol;
1✔
62
    }
63

64
    @Override
65
    public PSet<SymAnnot> getTypeAnnotations() {
66
        return typeAnnots;
1✔
67
    }
68

69
    @Override
70
    public JArrayType withAnnotations(PSet<SymAnnot> newTypeAnnots) {
71
        if (newTypeAnnots.isEmpty() && this.typeAnnots.isEmpty()) {
1✔
72
            return this;
1✔
73
        }
74
        return new JArrayType(ts, component, symbol, newTypeAnnots);
1✔
75
    }
76

77
    @Override
78
    public boolean isInterface() {
79
        return false;
1✔
80
    }
81

82
    @Override
83
    public JArrayType getErasure() {
84
        JTypeMirror erasedComp = component.getErasure();
1✔
85
        return erasedComp == component ? this  // NOPMD CompareObjectsWithEquals
1✔
86
                                       : new JArrayType(ts, erasedComp, symbol, typeAnnots);
1✔
87
    }
88

89

90
    /**
91
     * Gets the component type of this array. This is the same type as
92
     * the array, stripped of a single array dimensions, e.g. the component
93
     * type of {@code int[][][]} is {@code int[][]}.
94
     *
95
     * @return The component type of this array type
96
     *
97
     * @see #getElementType()
98
     */
99
    public JTypeMirror getComponentType() {
100
        return component;
1✔
101
    }
102

103
    /**
104
     * Gets the element type of this array. This is the same type as
105
     * the array, stripped of all array dimensions, e.g. the element
106
     * type of {@code int[][][]} is {@code int}.
107
     *
108
     * @return The element type of this array type
109
     *
110
     * @see #getComponentType()
111
     */
112
    public JTypeMirror getElementType() {
113
        JTypeMirror c = this;
1✔
114
        while (c instanceof JArrayType) {
1✔
115
            c = ((JArrayType) c).getComponentType();
1✔
116
        }
117

118
        return c;
1✔
119
    }
120

121

122
    @Override
123
    public Stream<JMethodSig> streamMethods(Predicate<? super JMethodSymbol> prefilter) {
124
        return Stream.concat(
1✔
125
            streamDeclaredMethods(prefilter),
1✔
126
            // inherited object methods
127
            ts.OBJECT.streamMethods(prefilter)
1✔
128
        );
129
    }
130

131
    @Override
132
    public Stream<JMethodSig> streamDeclaredMethods(Predicate<? super JMethodSymbol> prefilter) {
133
        return getSymbol().getDeclaredMethods().stream()
1✔
134
                          .filter(prefilter)
1✔
135
                          .map(it -> new ArrayMethodSigImpl(this, it));
1✔
136
    }
137

138
    @Override
139
    public List<JMethodSig> getConstructors() {
140
        return CollectionUtil.map(getSymbol().getConstructors(), it -> new ArrayMethodSigImpl(this, it));
1✔
141
    }
142

143
    @Override
144
    public boolean isRaw() {
145
        return getElementType().isRaw();
1✔
146
    }
147

148
    @Override
149
    public <T, P> T acceptVisitor(JTypeVisitor<T, P> visitor, P p) {
150
        return visitor.visitArray(this, p);
1✔
151
    }
152

153
    @Override
154
    public JArrayType subst(Function<? super SubstVar, ? extends @NonNull JTypeMirror> subst) {
155
        JTypeMirror newComp = getComponentType().subst(subst);
1✔
156
        return newComp == component ? this // NOPMD UseEqualsToCompareObjectReferences
1✔
157
                                    : getTypeSystem().arrayType(newComp).withAnnotations(getTypeAnnotations());
1✔
158
    }
159

160
    @Override
161
    public boolean equals(Object o) {
162
        if (this == o) {
1✔
163
            return true;
1✔
164
        }
165
        if (!(o instanceof JArrayType)) {
1✔
166
            return false;
1✔
167
        }
168
        JArrayType that = (JArrayType) o;
1✔
169
        return TypeOps.isSameType(this, that);
1✔
170
    }
171

172
    @Override
173
    public int hashCode() {
174
        return component.hashCode() * 3;
1✔
175
    }
176

177
    @Override
178
    public String toString() {
179
        return TypePrettyPrint.prettyPrint(this);
1✔
180
    }
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