• 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

88.89
/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/asm/ExecutableStub.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.symbols.internal.asm;
6

7
import java.util.ArrayList;
8
import java.util.Collections;
9
import java.util.List;
10

11
import org.checkerframework.checker.nullness.qual.Nullable;
12
import org.objectweb.asm.Opcodes;
13
import org.objectweb.asm.TypePath;
14
import org.pcollections.HashTreePSet;
15
import org.pcollections.IntTreePMap;
16
import org.pcollections.PMap;
17
import org.pcollections.PSet;
18

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.JFormalParamSymbol;
22
import net.sourceforge.pmd.lang.java.symbols.JMethodSymbol;
23
import net.sourceforge.pmd.lang.java.symbols.SymbolicValue;
24
import net.sourceforge.pmd.lang.java.symbols.SymbolicValue.SymAnnot;
25
import net.sourceforge.pmd.lang.java.symbols.internal.SymbolEquality;
26
import net.sourceforge.pmd.lang.java.symbols.internal.SymbolToStrings;
27
import net.sourceforge.pmd.lang.java.symbols.internal.asm.GenericSigBase.LazyMethodType;
28
import net.sourceforge.pmd.lang.java.types.JTypeMirror;
29
import net.sourceforge.pmd.lang.java.types.JTypeVar;
30
import net.sourceforge.pmd.lang.java.types.Substitution;
31
import net.sourceforge.pmd.lang.java.types.TypeOps;
32
import net.sourceforge.pmd.lang.java.types.TypeSystem;
33

34
abstract class ExecutableStub extends MemberStubBase implements JExecutableSymbol, TypeAnnotationReceiver {
35

36
    private final String descriptor;
37
    protected final LazyMethodType type;
38
    private List<JFormalParamSymbol> params;
39
    private PMap<Integer, PSet<SymAnnot>> parameterAnnotations = IntTreePMap.empty();
1✔
40

41
    protected ExecutableStub(ClassStub owner,
42
                             String simpleName,
43
                             int accessFlags,
44
                             String descriptor,
45
                             @Nullable String signature,
46
                             @Nullable String[] exceptions,
47
                             boolean skipFirstParam) {
48
        super(owner, simpleName, accessFlags);
1✔
49
        this.descriptor = descriptor;
1✔
50
        this.type = new LazyMethodType(this, descriptor, signature, exceptions, skipFirstParam);
1✔
51
    }
1✔
52

53
    boolean matches(String name, String descriptor) {
54
        return this.nameEquals(name) && descriptor.equals(this.descriptor);
×
55
    }
56

57

58
    @Override
59
    public List<JTypeVar> getTypeParameters() {
60
        return type.getTypeParams();
1✔
61
    }
62

63
    @Override
64
    public List<JFormalParamSymbol> getFormalParameters() {
65
        if (params == null) {
1✔
66
            List<JTypeMirror> ptypes = type.getParameterTypes();
1✔
67
            List<JFormalParamSymbol> newParams = new ArrayList<>(ptypes.size());
1✔
68
            for (int i = 0; i < ptypes.size(); i++) {
1✔
69
                newParams.add(new FormalParamStub(ptypes.get(i), i));
1✔
70
            }
71
            params = Collections.unmodifiableList(newParams);
1✔
72
        }
73
        return params;
1✔
74
    }
75

76
    @Override
77
    public boolean isVarargs() {
78
        return (getModifiers() & Opcodes.ACC_VARARGS) != 0;
1✔
79
    }
80

81
    @Override
82
    public int getArity() {
83
        return type.getParameterTypes().size();
1✔
84
    }
85

86
    PSet<SymAnnot> getFormalParameterAnnotations(int parameterIndex) {
87
        return parameterAnnotations.getOrDefault(parameterIndex, HashTreePSet.empty());
1✔
88
    }
89

90
    @Override
91
    public @Nullable JTypeMirror getAnnotatedReceiverType(Substitution subst) {
92
        if (!this.hasReceiver()) {
1✔
93
            return null;
×
94
        }
95
        JTypeMirror receiver = getTypeSystem().declaration(getEnclosingClass()).subst(subst);
1✔
96
        return type.applyReceiverAnnotations(receiver);
1✔
97
    }
98

99
    @Override
100
    public List<JTypeMirror> getFormalParameterTypes(Substitution subst) {
101
        return TypeOps.subst(type.getParameterTypes(), subst);
1✔
102
    }
103

104
    @Override
105
    public List<JTypeMirror> getThrownExceptionTypes(Substitution subst) {
106
        return TypeOps.subst(type.getExceptionTypes(), subst);
1✔
107
    }
108

109
    void setDefaultAnnotValue(@Nullable SymbolicValue defaultAnnotValue) {
110
        // overridden by MethodStub
111
    }
1✔
112

113
    @Override
114
    public void acceptTypeAnnotation(int typeRef, @Nullable TypePath path, SymAnnot annot) {
115
        type.acceptTypeAnnotation(typeRef, path, annot);
1✔
116
    }
1✔
117

118
    void addParameterAnnotation(int paramIndex, SymbolicValue.SymAnnot annot) {
119
        PSet<SymAnnot> newAnnots = parameterAnnotations.getOrDefault(paramIndex, HashTreePSet.empty()).plus(annot);
1✔
120
        parameterAnnotations = parameterAnnotations.plus(paramIndex, newAnnots);
1✔
121
    }
1✔
122

123
    /**
124
     * Formal parameter symbols obtained from the class have no info
125
     * about name or whether it's final. This info is missing from
126
     * classfiles when they're not compiled with debug symbols.
127
     */
128
    class FormalParamStub implements JFormalParamSymbol {
129

130
        private final JTypeMirror type;
131
        private final int index;
132

133
        FormalParamStub(JTypeMirror type, int index) {
1✔
134
            this.type = type;
1✔
135
            this.index = index;
1✔
136
        }
1✔
137

138
        @Override
139
        public JExecutableSymbol getDeclaringSymbol() {
140
            return ExecutableStub.this;
×
141
        }
142

143
        @Override
144
        public boolean isFinal() {
145
            return false;
1✔
146
        }
147

148
        @Override
149
        public JTypeMirror getTypeMirror(Substitution subst) {
150
            return type.subst(subst);
1✔
151
        }
152

153
        @Override
154
        public String getSimpleName() {
155
            return "";
1✔
156
        }
157

158
        @Override
159
        public TypeSystem getTypeSystem() {
160
            return ExecutableStub.this.getTypeSystem();
1✔
161
        }
162

163
        @Override
164
        public PSet<SymAnnot> getDeclaredAnnotations() {
165
            return ExecutableStub.this.getFormalParameterAnnotations(index);
1✔
166
        }
167
    }
168

169
    /**
170
     * Formal parameter symbols obtained from the class have no info
171
     * about name or whether it's final. This is because due to ASM's
172
     * design, parsing this information would entail parsing a lot of
173
     * other information we don't care about, and so this would be
174
     * wasteful. It's unlikely anyone cares about this anyway.
175
     *
176
     * <p>If classes are compiled without debug symbols that info
177
     * is NOT in the classfile anyway.
178
     */
179
    static class MethodStub extends ExecutableStub implements JMethodSymbol {
180

181
        private @Nullable SymbolicValue defaultAnnotValue;
182

183
        protected MethodStub(ClassStub owner,
184
                             String simpleName,
185
                             int accessFlags,
186
                             String descriptor,
187
                             @Nullable String signature,
188
                             @Nullable String[] exceptions) {
189
            super(owner, simpleName, accessFlags, descriptor, signature, exceptions, false);
1✔
190
        }
1✔
191

192
        @Override
193
        public boolean isBridge() {
194
            return (getModifiers() & Opcodes.ACC_BRIDGE) != 0;
×
195
        }
196

197
        @Override
198
        public JTypeMirror getReturnType(Substitution subst) {
199
            return type.getReturnType().subst(subst);
1✔
200
        }
201

202

203
        @Override
204
        public String toString() {
205
            return SymbolToStrings.ASM.toString(this);
1✔
206
        }
207

208
        @Override
209
        public int hashCode() {
210
            return SymbolEquality.METHOD.hash(this);
1✔
211
        }
212

213
        @Override
214
        public boolean equals(Object obj) {
215
            return SymbolEquality.METHOD.equals(this, obj);
1✔
216
        }
217

218
        @Override
219
        public @Nullable SymbolicValue getDefaultAnnotationValue() {
220
            return defaultAnnotValue;
1✔
221
        }
222

223
        @Override
224
        void setDefaultAnnotValue(@Nullable SymbolicValue defaultAnnotValue) {
225
            this.defaultAnnotValue = defaultAnnotValue;
1✔
226
        }
1✔
227
    }
228

229
    static class CtorStub extends ExecutableStub implements JConstructorSymbol {
230

231
        protected CtorStub(ClassStub owner,
232
                           int accessFlags,
233
                           String descriptor,
234
                           @Nullable String signature,
235
                           @Nullable String[] exceptions,
236
                           boolean isInnerNonStaticClass) {
237
            super(owner, JConstructorSymbol.CTOR_NAME, accessFlags, descriptor, signature, exceptions, isInnerNonStaticClass);
1✔
238
        }
1✔
239

240
        @Override
241
        public String toString() {
242
            return SymbolToStrings.ASM.toString(this);
×
243
        }
244

245
        @Override
246
        public int hashCode() {
247
            return SymbolEquality.CONSTRUCTOR.hash(this);
×
248
        }
249

250
        @Override
251
        public boolean equals(Object obj) {
252
            return SymbolEquality.CONSTRUCTOR.equals(this, obj);
1✔
253
        }
254

255
    }
256
}
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