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

pmd / pmd / 4509

21 Mar 2025 11:23AM UTC coverage: 77.757% (-0.004%) from 77.761%
4509

push

github

adangel
[doc] Use full class name for deprecation in release notes

17505 of 23464 branches covered (74.6%)

Branch coverage included in aggregate %.

38318 of 48328 relevant lines covered (79.29%)

0.8 hits per line

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

88.33
/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/asm/TParamStub.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.List;
9

10
import org.checkerframework.checker.nullness.qual.NonNull;
11
import org.checkerframework.checker.nullness.qual.Nullable;
12
import org.objectweb.asm.TypePath;
13
import org.objectweb.asm.TypeReference;
14
import org.pcollections.HashTreePSet;
15
import org.pcollections.PSet;
16

17
import net.sourceforge.pmd.lang.java.symbols.JTypeParameterOwnerSymbol;
18
import net.sourceforge.pmd.lang.java.symbols.JTypeParameterSymbol;
19
import net.sourceforge.pmd.lang.java.symbols.SymbolicValue.SymAnnot;
20
import net.sourceforge.pmd.lang.java.symbols.internal.SymbolEquality;
21
import net.sourceforge.pmd.lang.java.symbols.internal.SymbolToStrings;
22
import net.sourceforge.pmd.lang.java.symbols.internal.asm.TypeAnnotationHelper.TypeAnnotationSetWithReferences;
23
import net.sourceforge.pmd.lang.java.types.JIntersectionType;
24
import net.sourceforge.pmd.lang.java.types.JTypeMirror;
25
import net.sourceforge.pmd.lang.java.types.JTypeVar;
26
import net.sourceforge.pmd.lang.java.types.TypeSystem;
27

28
class TParamStub implements JTypeParameterSymbol {
1✔
29

30
    private final String name;
31
    private final JTypeParameterOwnerSymbol owner;
32
    private final JTypeVar typeVar;
33
    private final String boundSignature;
34
    private final SignatureParser sigParser;
35
    private PSet<SymAnnot> annotations = HashTreePSet.empty();
1✔
36
    private TypeAnnotationSetWithReferences typeAnnotationsOnBound;
37
    private boolean canComputeBound;
38

39
    TParamStub(String name, GenericSigBase<?> sig, String bound) {
1✔
40
        this.name = name;
1✔
41
        this.owner = sig.ctx;
1✔
42
        this.sigParser = sig.typeLoader();
1✔
43
        this.boundSignature = bound;
1✔
44

45
        TypeSystem ts = sig.ctx.getTypeSystem();
1✔
46
        this.typeVar = ts.newTypeVar(this);
1✔
47
    }
1✔
48

49

50
    @Override
51
    public @NonNull String getSimpleName() {
52
        return name;
1✔
53
    }
54

55
    @Override
56
    public JTypeMirror computeUpperBound() {
57
        if (!canComputeBound) {
1!
58
            throw new IllegalStateException(
×
59
                "Can't compute upper bound of " + name + " in " + owner.getEnclosingTypeParameterOwner());
×
60
        }
61
        JTypeMirror bound = sigParser.parseTypeVarBound(owner.getLexicalScope(), boundSignature);
1✔
62
        if (typeAnnotationsOnBound == null) {
1✔
63
            return bound;
1✔
64
        }
65
        // apply all type annotations.
66
        return typeAnnotationsOnBound.reduce(
1✔
67
            bound,
68
            (tyRef, path, annot, acc) -> {
69
                int boundIdx = tyRef.getTypeParameterBoundIndex();
1✔
70

71
                return applyTypeAnnotationToBound(path, annot, boundIdx, acc);
1✔
72
            });
73
    }
74

75
    private static JTypeMirror applyTypeAnnotationToBound(@Nullable TypePath path, SymAnnot annot, int boundIdx, JTypeMirror ub) {
76
        if (ub instanceof JIntersectionType) {
1✔
77
            JIntersectionType intersection = (JIntersectionType) ub;
1✔
78

79
            // Object is pruned from the component list
80
            boundIdx = intersection.getPrimaryBound().isTop() ? boundIdx - 1 : boundIdx;
1!
81

82
            List<JTypeMirror> components = new ArrayList<>(intersection.getComponents());
1✔
83
            JTypeMirror bound = components.get(boundIdx);
1✔
84
            JTypeMirror newBound = TypeAnnotationHelper.applySinglePath(bound, path, annot);
1✔
85
            components.set(boundIdx, newBound);
1✔
86
            return intersection.getTypeSystem().glb(components);
1✔
87
        } else {
88
            return TypeAnnotationHelper.applySinglePath(ub, path, annot);
1✔
89
        }
90
    }
91

92
    /**
93
     * The bound cannot be computed before we have collected type annotations
94
     * for the bound. These may come from the parsing of the type annotations
95
     * for the enclosing declaration (method or class) so come relatively late.
96
     */
97
    void setCanComputeBound() {
98
        this.canComputeBound = true;
1✔
99
    }
1✔
100

101
    @Override
102
    public JTypeParameterOwnerSymbol getDeclaringSymbol() {
103
        return owner;
1✔
104
    }
105

106
    @Override
107
    public PSet<SymAnnot> getDeclaredAnnotations() {
108
        return annotations;
1✔
109
    }
110

111
    void addAnnotation(SymAnnot annot) {
112
        annotations = annotations.plus(annot);
1✔
113
    }
1✔
114

115
    @Override
116
    public JTypeVar getTypeMirror() {
117
        return typeVar;
1✔
118
    }
119

120
    @Override
121
    public TypeSystem getTypeSystem() {
122
        return owner.getTypeSystem();
1✔
123
    }
124

125
    @Override
126
    public String toString() {
127
        return SymbolToStrings.ASM.toString(this);
×
128
    }
129

130
    @Override
131
    public int hashCode() {
132
        return SymbolEquality.TYPE_PARAM.hash(this);
1✔
133
    }
134

135
    @Override
136
    public boolean equals(Object obj) {
137
        return SymbolEquality.TYPE_PARAM.equals(this, obj);
1✔
138
    }
139

140
    void addAnnotationOnBound(TypeReference tyRef, @Nullable TypePath path, SymAnnot annot) {
141
        assert tyRef.getSort() == TypeReference.CLASS_TYPE_PARAMETER_BOUND
1!
142
            || tyRef.getSort() == TypeReference.METHOD_TYPE_PARAMETER_BOUND;
1!
143

144
        if (typeAnnotationsOnBound == null) {
1✔
145
            typeAnnotationsOnBound = new TypeAnnotationSetWithReferences();
1✔
146
        }
147
        typeAnnotationsOnBound.add(tyRef, path, annot);
1✔
148
    }
1✔
149
}
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