• 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

95.38
/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ClassMethodSigImpl.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.lang.java.types.Substitution.EMPTY;
8
import static net.sourceforge.pmd.lang.java.types.Substitution.isEmptySubst;
9
import static net.sourceforge.pmd.util.CollectionUtil.map;
10

11
import java.util.Collections;
12
import java.util.List;
13
import java.util.Objects;
14
import java.util.function.Function;
15

16
import org.checkerframework.checker.nullness.qual.NonNull;
17
import org.checkerframework.checker.nullness.qual.Nullable;
18

19
import net.sourceforge.pmd.lang.java.symbols.JExecutableSymbol;
20
import net.sourceforge.pmd.lang.java.symbols.JMethodSymbol;
21
import net.sourceforge.pmd.lang.java.types.internal.InternalMethodTypeItf;
22

23
class ClassMethodSigImpl implements JMethodSig, InternalMethodTypeItf {
24

25

26
    private final JMethodSig adaptedMethod;
27

28
    private final JClassType owner;
29
    // either method or constructor
30
    private final JExecutableSymbol symbol;
31

32
    private @Nullable List<JTypeVar> tparams;
33
    private JTypeMirror resultType;
34
    private List<JTypeMirror> formals;
35
    private List<JTypeMirror> thrown;
36

37
    ClassMethodSigImpl(@NonNull JClassType owner, @NonNull JExecutableSymbol symbol) {
38
        this(owner, symbol, null, null, null, null, null);
1✔
39
    }
1✔
40

41

42
    private ClassMethodSigImpl(@NonNull JClassType owner,
43
                               @NonNull JExecutableSymbol symbol,
44
                               JMethodSig adapted,
45
                               @Nullable List<JTypeVar> tparams,
46
                               @Nullable JTypeMirror resultType,
47
                               @Nullable List<JTypeMirror> formals,
48
                               @Nullable List<JTypeMirror> thrown) {
1✔
49

50
        this.adaptedMethod = adapted == null ? this : adapted;
1✔
51
        this.owner = owner;
1✔
52
        this.symbol = symbol;
1✔
53
        this.resultType = resultType;
1✔
54
        this.formals = formals;
1✔
55
        this.thrown = thrown;
1✔
56
        this.tparams = tparams;
1✔
57
    }
1✔
58

59
    @Override
60
    public TypeSystem getTypeSystem() {
61
        return owner.getTypeSystem();
1✔
62
    }
63

64
    @Override
65
    public JExecutableSymbol getSymbol() {
66
        return symbol;
1✔
67
    }
68

69
    @Override
70
    public JClassType getDeclaringType() {
71
        return owner;
1✔
72
    }
73

74
    @Override
75
    public JTypeMirror getAnnotatedReceiverType() {
76
        return symbol.getAnnotatedReceiverType(getTypeParamSubst());
1✔
77
    }
78

79
    @Override
80
    public JMethodSig getErasure() {
81
        return new ClassMethodSigImpl(
1✔
82
            owner.getErasure(),
1✔
83
            symbol,
84
            null,
85
            Collections.emptyList(),
1✔
86
            getReturnType().getErasure(),
1✔
87
            TypeOps.erase(getFormalParameters()),
1✔
88
            TypeOps.erase(getThrownExceptions())
1✔
89
        );
90
    }
91

92
    @Override
93
    public JTypeMirror getReturnType() {
94
        if (resultType == null) {
1✔
95
            if (symbol instanceof JMethodSymbol) {
1✔
96
                if (owner.isRaw()) {
1✔
97
                    resultType = ClassTypeImpl.eraseToRaw(((JMethodSymbol) symbol).getReturnType(EMPTY), getTypeParamSubst());
1✔
98
                } else {
99
                    resultType = ((JMethodSymbol) symbol).getReturnType(getTypeParamSubst());
1✔
100
                }
101
            } else {
102
                // constructor
103
                resultType = owner;
1✔
104
            }
105
        }
106
        return resultType;
1✔
107
    }
108

109
    @Override
110
    public List<JTypeMirror> getFormalParameters() {
111
        if (formals == null) {
1✔
112
            if (owner.isRaw()) {
1✔
113
                formals = map(symbol.getFormalParameterTypes(EMPTY), m -> ClassTypeImpl.eraseToRaw(m, getTypeParamSubst()));
1✔
114
            } else {
115
                formals = symbol.getFormalParameterTypes(getTypeParamSubst());
1✔
116
            }
117
        }
118
        return formals;
1✔
119
    }
120

121

122
    @Override
123
    public List<JTypeVar> getTypeParameters() {
124
        if (tparams == null) {
1✔
125
            // bounds of the type params of a method need to be substituted
126
            // with the lexical subst of the owner
127
            tparams = TypeOps.substInBoundsOnly(symbol.getTypeParameters(), owner.getTypeParamSubst());
1✔
128
        }
129
        return tparams;
1✔
130
    }
131

132
    @Override
133
    public List<JTypeMirror> getThrownExceptions() {
134
        if (thrown == null) {
1✔
135
            if (owner.isRaw()) {
1✔
136
                thrown = map(symbol.getThrownExceptionTypes(EMPTY), m -> ClassTypeImpl.eraseToRaw(m, getTypeParamSubst()));
1✔
137
            } else {
138
                thrown = symbol.getThrownExceptionTypes(getTypeParamSubst());
1✔
139
            }
140
        }
141
        return thrown;
1✔
142
    }
143

144
    @Override
145
    public InternalMethodTypeItf internalApi() {
146
        return this;
1✔
147
    }
148

149
    @Override
150
    public JMethodSig withReturnType(JTypeMirror returnType) {
151
        // share formals & thrown to avoid recomputing
152
        return new ClassMethodSigImpl(owner, symbol, adaptedMethod, tparams, returnType, formals, thrown);
1✔
153
    }
154

155
    @Override
156
    public JMethodSig withTypeParams(@Nullable List<JTypeVar> tparams) {
157
        return new ClassMethodSigImpl(owner, symbol, adaptedMethod, tparams, resultType, formals, thrown);
1✔
158
    }
159

160
    @Override
161
    public JMethodSig subst(Function<? super SubstVar, ? extends JTypeMirror> fun) {
162
        if (isEmptySubst(fun)) {
1✔
163
            return this;
1✔
164
        }
165
        return new ClassMethodSigImpl(
1✔
166
            owner,
167
            symbol,
168
            adaptedMethod,
169
            tparams, // don't substitute type parameters
170
            TypeOps.subst(getReturnType(), fun),
1✔
171
            TypeOps.subst(getFormalParameters(), fun),
1✔
172
            TypeOps.subst(getThrownExceptions(), fun)
1✔
173
        );
174
    }
175

176
    @Override
177
    public JMethodSig markAsAdapted() {
178
        return new ClassMethodSigImpl(owner, symbol, null, tparams, resultType, formals, thrown);
1✔
179
    }
180

181
    @Override
182
    public JMethodSig withOwner(JTypeMirror newOwner) {
183
        if (newOwner instanceof JClassType && Objects.equals(newOwner.getSymbol(), this.owner.getSymbol())) {
1✔
184
            return new ClassMethodSigImpl((JClassType) newOwner, symbol, adaptedMethod, tparams, resultType, formals, thrown);
1✔
185
        } else {
186
            throw new IllegalArgumentException(newOwner + " cannot be the owner of " + this);
×
187
        }
188
    }
189

190
    @Override
191
    public JMethodSig originalMethod() {
192
        return new ClassMethodSigImpl(owner, symbol);
1✔
193
    }
194

195
    @Override
196
    public JMethodSig adaptedMethod() {
197
        return adaptedMethod == null ? originalMethod() : adaptedMethod;
1✔
198
    }
199

200
    private Substitution getTypeParamSubst() {
201
        return owner.getTypeParamSubst();
1✔
202
    }
203

204
    @Override
205
    public String toString() {
206
        return TypePrettyPrint.prettyPrint(this);
1✔
207
    }
208

209

210
    @Override
211
    public boolean equals(Object o) {
212
        if (this == o) {
1✔
213
            return true;
×
214
        }
215
        if (!(o instanceof JMethodSig)) {
1✔
216
            return false;
1✔
217
        }
218
        JMethodSig that = (JMethodSig) o;
1✔
219
        return TypeOps.isSameType(this, that);
1✔
220
    }
221

222
    @Override
223
    public int hashCode() {
224
        return Objects.hash(getName(), getFormalParameters(), getReturnType());
×
225
    }
226
}
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