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

pmd / pmd / 95

22 Jul 2025 05:33PM UTC coverage: 78.418% (-0.02%) from 78.436%
95

push

github

web-flow
chore: [scala] Fix javadoc config (#5920)

17758 of 23477 branches covered (75.64%)

Branch coverage included in aggregate %.

38997 of 48898 relevant lines covered (79.75%)

0.81 hits per line

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

90.0
/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.types.internal.InternalMethodTypeItf;
21

22
class ClassMethodSigImpl implements JMethodSig, InternalMethodTypeItf {
23

24

25
    private final JMethodSig adaptedMethod;
26

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

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

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

40

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

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

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

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

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

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

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

91
    @Override
92
    public JTypeMirror getReturnType() {
93
        if (resultType == null) {
1✔
94
            if (owner.isRaw()) {
1✔
95
                resultType = ClassTypeImpl.eraseToRaw(symbol.getReturnType(EMPTY), getTypeParamSubst());
1✔
96
            } else {
97
                resultType = symbol.getReturnType(getTypeParamSubst());
1✔
98
            }
99
        }
100
        return resultType;
1✔
101
    }
102

103
    @Override
104
    public List<JTypeMirror> getFormalParameters() {
105
        if (formals == null) {
1✔
106
            if (owner.isRaw()) {
1✔
107
                formals = map(symbol.getFormalParameterTypes(EMPTY), m -> ClassTypeImpl.eraseToRaw(m, getTypeParamSubst()));
1✔
108
            } else {
109
                formals = symbol.getFormalParameterTypes(getTypeParamSubst());
1✔
110
            }
111
        }
112
        return formals;
1✔
113
    }
114

115

116
    @Override
117
    public List<JTypeVar> getTypeParameters() {
118
        if (tparams == null) {
1✔
119
            // bounds of the type params of a method need to be substituted
120
            // with the lexical subst of the owner
121
            tparams = TypeOps.substInBoundsOnly(symbol.getTypeParameters(), owner.getTypeParamSubst());
1✔
122
        }
123
        return tparams;
1✔
124
    }
125

126
    @Override
127
    public List<JTypeMirror> getThrownExceptions() {
128
        if (thrown == null) {
1✔
129
            if (owner.isRaw()) {
1✔
130
                thrown = map(symbol.getThrownExceptionTypes(EMPTY), m -> ClassTypeImpl.eraseToRaw(m, getTypeParamSubst()));
1✔
131
            } else {
132
                thrown = symbol.getThrownExceptionTypes(getTypeParamSubst());
1✔
133
            }
134
        }
135
        return thrown;
1✔
136
    }
137

138
    @Override
139
    public JMethodSig withReturnType(JTypeMirror returnType) {
140
        // share formals & thrown to avoid recomputing
141
        return new ClassMethodSigImpl(owner, symbol, adaptedMethod, tparams, returnType, formals, thrown);
1✔
142
    }
143

144
    @Override
145
    public JMethodSig withTypeParams(@Nullable List<JTypeVar> tparams) {
146
        return new ClassMethodSigImpl(owner, symbol, adaptedMethod, tparams, resultType, formals, thrown);
1✔
147
    }
148

149
    @Override
150
    public JMethodSig subst(Function<? super SubstVar, ? extends JTypeMirror> fun) {
151
        if (isEmptySubst(fun)) {
1✔
152
            return this;
1✔
153
        }
154
        return new ClassMethodSigImpl(
1✔
155
            owner,
156
            symbol,
157
            adaptedMethod,
158
            tparams, // don't substitute type parameters
159
            TypeOps.subst(getReturnType(), fun),
1✔
160
            TypeOps.subst(getFormalParameters(), fun),
1✔
161
            TypeOps.subst(getThrownExceptions(), fun)
1✔
162
        );
163
    }
164

165
    @Override
166
    public JMethodSig markAsAdapted() {
167
        return new ClassMethodSigImpl(owner, symbol, null, tparams, resultType, formals, thrown);
1✔
168
    }
169

170
    @Override
171
    public JMethodSig withOwner(JTypeMirror newOwner) {
172
        if (newOwner instanceof JClassType && Objects.equals(newOwner.getSymbol(), this.owner.getSymbol())) {
1!
173
            return new ClassMethodSigImpl((JClassType) newOwner, symbol, adaptedMethod, tparams, resultType, formals, thrown);
1✔
174
        } else {
175
            throw new IllegalArgumentException(newOwner + " cannot be the owner of " + this);
×
176
        }
177
    }
178

179
    @Override
180
    public JMethodSig originalMethod() {
181
        return new ClassMethodSigImpl(owner, symbol);
1✔
182
    }
183

184
    @Override
185
    public JMethodSig adaptedMethod() {
186
        return adaptedMethod == null ? originalMethod() : adaptedMethod;
1!
187
    }
188

189
    private Substitution getTypeParamSubst() {
190
        return owner.getTypeParamSubst();
1✔
191
    }
192

193
    @Override
194
    public String toString() {
195
        return TypePrettyPrint.prettyPrint(this);
1✔
196
    }
197

198

199
    @Override
200
    public boolean equals(Object o) {
201
        if (this == o) {
1!
202
            return true;
×
203
        }
204
        if (!(o instanceof JMethodSig)) {
1!
205
            return false;
×
206
        }
207
        JMethodSig that = (JMethodSig) o;
1✔
208
        return TypeOps.isSameType(this, that);
1✔
209
    }
210

211
    @Override
212
    public int hashCode() {
213
        return Objects.hash(getName(), getFormalParameters(), getReturnType());
×
214
    }
215
}
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