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

pmd / pmd / 21

29 May 2025 06:28PM UTC coverage: 77.795% (+0.008%) from 77.787%
21

push

github

adangel
[java] Support annotated constructor return type in symbol API (#5763)

Merge pull request #5763 from oowekyala:java-type-annotations-improvements

17728 of 23750 branches covered (74.64%)

Branch coverage included in aggregate %.

21 of 22 new or added lines in 7 files covered. (95.45%)

38910 of 49054 relevant lines covered (79.32%)

0.8 hits per line

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

53.85
/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/JExecutableSymbol.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;
6

7
import java.lang.reflect.Constructor;
8
import java.lang.reflect.Method;
9
import java.lang.reflect.Modifier;
10
import java.util.List;
11

12
import org.checkerframework.checker.nullness.qual.NonNull;
13
import org.checkerframework.checker.nullness.qual.Nullable;
14

15
import net.sourceforge.pmd.lang.java.types.JMethodSig;
16
import net.sourceforge.pmd.lang.java.types.JTypeMirror;
17
import net.sourceforge.pmd.lang.java.types.Substitution;
18

19
/**
20
 * Common supertype for {@linkplain JMethodSymbol method}
21
 * and {@linkplain JConstructorSymbol constructor symbols}.
22
 */
23
public interface JExecutableSymbol extends JTypeParameterOwnerSymbol {
24

25

26
    /**
27
     * Returns the formal parameters this executable declares. These are
28
     * only non-synthetic parameters. For example, a constructor for an
29
     * inner non-static class will not reflect a parameter for the enclosing
30
     * instance.
31
     */
32
    List<JFormalParamSymbol> getFormalParameters();
33

34
    /**
35
     * Return the return type under the given substitution.
36
     * For a constructor, return the type of the owner. This type
37
     * may be annotated.
38
     * @see JConstructorSymbol
39
     */
40
    default JTypeMirror getReturnType(Substitution subst) {
41
        // JMethodSymbol has always had this method abstract so this branch
42
        // should never be taken.
NEW
43
        throw new UnsupportedOperationException("Default method was added for compatibility, will be removed");
×
44
    }
45

46

47
    default boolean isDefaultMethod() {
48
        // Default methods are public non-abstract instance methods
49
        // declared in an interface.
50
        return this instanceof JMethodSymbol
1!
51
            && (getModifiers() & (Modifier.ABSTRACT | Modifier.PUBLIC | Modifier.STATIC)) == Modifier.PUBLIC
1✔
52
            && getEnclosingClass().isInterface();
1!
53
    }
54

55

56
    /** Returns true if the last formal parameter is a varargs parameter. */
57
    boolean isVarargs();
58

59

60
    /**
61
     * Returns the number of formal parameters expected. This must be the
62
     * length of {@link #getFormalParameters()} but if it can be implemented
63
     * without creating the formal parameters, it should.
64
     *
65
     * <p>A varargs parameter counts as a single parameter.
66
     */
67
    int getArity();
68

69

70
    /**
71
     * Return the receiver type with all type annotations, when viewed
72
     * under the given substitution. Return null if this method
73
     * {@linkplain #hasReceiver() has no receiver}.
74
     *
75
     * @throws IllegalArgumentException If the argument is not the receiver type of this type.
76
     */
77
    @Nullable JTypeMirror getAnnotatedReceiverType(Substitution subst);
78

79
    /**
80
     * Return true if this method needs to be called on a receiver instance.
81
     * This is not the case if the method is static, or a constructor of an
82
     * outer or static class.
83
     */
84
    default boolean hasReceiver() {
85
        if (isStatic()) {
1!
86
            return false;
×
87
        }
88
        if (this instanceof JConstructorSymbol) {
1!
89
            return !getEnclosingClass().isStatic()
×
90
                && getEnclosingClass().getEnclosingClass() != null;
×
91
        }
92
        return true;
1✔
93
    }
94

95

96
    /**
97
     * Returns the class symbol declaring this method or constructor.
98
     * This is similar to {@link Constructor#getDeclaringClass()}, resp.
99
     * {@link Method#getDeclaringClass()}. Never null.
100
     */
101
    @Override
102
    @NonNull
103
    JClassSymbol getEnclosingClass();
104

105

106
    @Override
107
    default @NonNull String getPackageName() {
108
        return getEnclosingClass().getPackageName();
1✔
109
    }
110

111

112
    /**
113
     * Returns the types of the formal parameters, when viewed under the
114
     * given substitution. The returned list has one item for each formal.
115
     *
116
     * @see #getFormalParameters()
117
     */
118
    List<JTypeMirror> getFormalParameterTypes(Substitution subst);
119

120
    /**
121
     * Returns the types of the thrown exceptions, when viewed under the
122
     * given substitution.
123
     */
124
    List<JTypeMirror> getThrownExceptionTypes(Substitution subst);
125

126
    /**
127
     * Return a method sig corresponding to this symbol.
128
     * The returned signature may contain type parameters
129
     * of this method and of the enclosing classes.
130
     */
131
    default JMethodSig getGenericSignature() {
132
        return getTypeSystem().sigOf(this);
1✔
133
    }
134
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc