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

pmd / pmd / 415

27 Feb 2026 12:39PM UTC coverage: 79.038% (+0.03%) from 79.004%
415

push

github

adangel
[release] Prepare next development version

18604 of 24437 branches covered (76.13%)

Branch coverage included in aggregate %.

40598 of 50466 relevant lines covered (80.45%)

0.81 hits per line

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

90.52
/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.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.ast;
6

7
import org.checkerframework.checker.nullness.qual.NonNull;
8
import org.checkerframework.checker.nullness.qual.Nullable;
9

10
import net.sourceforge.pmd.annotation.InternalApi;
11
import net.sourceforge.pmd.lang.ast.NodeStream;
12
import net.sourceforge.pmd.lang.ast.SemanticException;
13
import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccTokenDocument;
14
import net.sourceforge.pmd.lang.java.ast.ASTAssignableExpr.ASTNamedReferenceExpr;
15
import net.sourceforge.pmd.lang.java.internal.JavaAstProcessor;
16
import net.sourceforge.pmd.lang.java.symbols.JClassSymbol;
17
import net.sourceforge.pmd.lang.java.symbols.JConstructorSymbol;
18
import net.sourceforge.pmd.lang.java.symbols.JElementSymbol;
19
import net.sourceforge.pmd.lang.java.symbols.JMethodSymbol;
20
import net.sourceforge.pmd.lang.java.symbols.JRecordComponentSymbol;
21
import net.sourceforge.pmd.lang.java.symbols.JTypeDeclSymbol;
22
import net.sourceforge.pmd.lang.java.symbols.JTypeParameterSymbol;
23
import net.sourceforge.pmd.lang.java.symbols.JVariableSymbol;
24
import net.sourceforge.pmd.lang.java.symbols.table.JSymbolTable;
25
import net.sourceforge.pmd.lang.java.symbols.table.internal.ReferenceCtx;
26
import net.sourceforge.pmd.lang.java.types.JMethodSig;
27
import net.sourceforge.pmd.lang.java.types.JTypeMirror;
28
import net.sourceforge.pmd.lang.java.types.JVariableSig;
29
import net.sourceforge.pmd.lang.java.types.JVariableSig.FieldSig;
30
import net.sourceforge.pmd.lang.java.types.OverloadSelectionResult;
31
import net.sourceforge.pmd.lang.java.types.Substitution;
32
import net.sourceforge.pmd.lang.java.types.TypeSystem;
33
import net.sourceforge.pmd.lang.java.types.ast.ExprContext;
34
import net.sourceforge.pmd.lang.java.types.ast.internal.LazyTypeResolver;
35
import net.sourceforge.pmd.lang.java.types.internal.infer.Infer;
36
import net.sourceforge.pmd.lang.java.types.internal.infer.TypeInferenceLogger;
37
import net.sourceforge.pmd.util.AssertionUtil;
38

39
/**
40
 * Internal API.
41
 *
42
 * <p>Acts as a bridge between outer parts of PMD and the restricted access
43
 * internal API of this package.
44
 *
45
 * <p><b>None of this is published API, and compatibility can be broken anytime!</b>
46
 * Use this only at your own risk.
47
 *
48
 * @author Clément Fournier
49
 * @since 7.0.0
50
 * @internalApi None of this is published API, and compatibility can be broken anytime! Use this only at your own risk.
51
 */
52
@InternalApi
53
public final class InternalApiBridge {
54
    private InternalApiBridge() {}
55

56
    public static void setSymbol(SymbolDeclaratorNode node, JElementSymbol symbol) {
57
        if (node instanceof ASTMethodDeclaration) {
1✔
58
            ((ASTMethodDeclaration) node).setSymbol((JMethodSymbol) symbol);
1✔
59
        } else if (node instanceof ASTConstructorDeclaration) {
1✔
60
            ((ASTConstructorDeclaration) node).setSymbol((JConstructorSymbol) symbol);
1✔
61
        } else if (node instanceof ASTTypeDeclaration) {
1✔
62
            ((AbstractTypeDeclaration) node).setSymbol((JClassSymbol) symbol);
1✔
63
        } else if (node instanceof ASTVariableId) {
1✔
64
            ((ASTVariableId) node).setSymbol((JVariableSymbol) symbol);
1✔
65
        } else if (node instanceof ASTTypeParameter) {
1✔
66
            ((ASTTypeParameter) node).setSymbol((JTypeParameterSymbol) symbol);
1✔
67
        } else if (node instanceof ASTRecordComponentList) {
1✔
68
            ((ASTRecordComponentList) node).setSymbol((JConstructorSymbol) symbol);
1✔
69
        } else if (node instanceof ASTRecordComponent) {
1!
70
            ((ASTRecordComponent) node).setSymbol((JRecordComponentSymbol) symbol);
1✔
71
        } else {
72
            throw new AssertionError("Cannot set symbol " + symbol + " on node " + node);
×
73
        }
74
    }
1✔
75

76
    public static void disambigWithCtx(NodeStream<? extends JavaNode> nodes, ReferenceCtx ctx) {
77
        AstDisambiguationPass.disambigWithCtx(nodes, ctx);
1✔
78
    }
1✔
79

80
    public static void retryDisambigWithCtx(NodeStream<? extends ASTAmbiguousName> nodes, ReferenceCtx ctx, JSymbolTable symbolTable) {
81
        AstDisambiguationPass.retryDisambigWithCtx(nodes, ctx, symbolTable);
1✔
82
    }
1✔
83

84
    /**
85
     * Forcing type resolution allows us to report errors more cleanly
86
     * than if it was done completely lazy. Failures (other than semantic exceptions)
87
     * are thrown, because they are bugs in the typeres framework.
88
     * Semantic exceptions cause execution to abort too, but only right before
89
     * rules are applied, so several semantic exceptions may be collected.
90
     */
91
    public static void forceTypeResolutionPhase(JavaAstProcessor processor, ASTCompilationUnit root) {
92
        root.descendants(TypeNode.class)
1✔
93
            .crossFindBoundaries()
1✔
94
            .forEach(typeNode -> {
1✔
95
                try {
96
                    typeNode.getTypeMirror();
1✔
97
                } catch (SemanticException e) {
1✔
98
                    processor.getLogger().acceptError(e);
1✔
99
                }
1✔
100
            });
1✔
101
    }
1✔
102

103
    public static void usageResolution(JavaAstProcessor processor, ASTCompilationUnit root) {
104
        root.descendants(ASTNamedReferenceExpr.class)
1✔
105
            .crossFindBoundaries()
1✔
106
            .forEach(node -> {
1✔
107
                JVariableSymbol sym = node.getReferencedSym();
1✔
108
                if (sym != null) {
1✔
109
                    ASTVariableId reffed = sym.tryGetNode();
1✔
110
                    if (reffed != null) { // declared in this file
1✔
111
                        reffed.addUsage(node);
1✔
112
                    }
113
                }
114
            });
1✔
115
    }
1✔
116

117
    public static void overrideResolution(JavaAstProcessor processor, ASTCompilationUnit root) {
118
        root.descendants(ASTTypeDeclaration.class)
1✔
119
            .crossFindBoundaries()
1✔
120
            .forEach(OverrideResolutionPass::resolveOverrides);
1✔
121
    }
1✔
122

123
    public static @Nullable JTypeMirror getTypeMirrorInternal(TypeNode node) {
124
        return ((AbstractJavaTypeNode) node).getTypeMirrorInternal();
1✔
125
    }
126

127
    public static void setTypeMirrorInternal(TypeNode node, JTypeMirror inferred) {
128
        ((AbstractJavaTypeNode) node).setTypeMirror(inferred);
1✔
129
    }
1✔
130

131
    public static void setSignature(ASTFieldAccess node, FieldSig sig) {
132
        node.setTypedSym(sig);
×
133
    }
×
134

135
    public static void setSignature(ASTVariableAccess node, JVariableSig sig) {
136
        node.setTypedSym(sig);
×
137
    }
×
138

139
    public static void setFunctionalMethod(FunctionalExpression node, JMethodSig methodType) {
140
        if (node instanceof ASTMethodReference) {
1✔
141
            ((ASTMethodReference) node).setFunctionalMethod(methodType);
1✔
142
        } else if (node instanceof ASTLambdaExpression) {
1!
143
            ((ASTLambdaExpression) node).setFunctionalMethod(methodType);
1✔
144
        } else {
145
            throw AssertionUtil.shouldNotReachHere("FunctionalExpression is not handled: " + node);
×
146
        }
147
    }
1✔
148

149
    public static void setCompileTimeDecl(ASTMethodReference methodReference, OverloadSelectionResult methodType) {
150
        methodReference.setCompileTimeDecl(methodType);
1✔
151
    }
1✔
152

153
    public static void initTypeResolver(ASTCompilationUnit acu, JavaAstProcessor processor, TypeInferenceLogger logger) {
154
        acu.setTypeResolver(new LazyTypeResolver(processor, logger));
1✔
155
    }
1✔
156

157
    public static void setOverload(InvocationNode expression, OverloadSelectionResult result) {
158
        if (expression instanceof AbstractInvocationExpr) {
1✔
159
            ((AbstractInvocationExpr) expression).setOverload(result);
1✔
160
        } else if (expression instanceof ASTExplicitConstructorInvocation) {
1✔
161
            ((ASTExplicitConstructorInvocation) expression).setOverload(result);
1✔
162
        } else if (expression instanceof ASTEnumConstant) {
1!
163
            ((ASTEnumConstant) expression).setOverload(result);
1✔
164
        } else {
165
            throw new IllegalArgumentException("Wrong type: " + expression);
×
166
        }
167
    }
1✔
168

169
    public static JavaAstProcessor getProcessor(JavaNode n) {
170
        return n.getRoot().getLazyTypeResolver().getProcessor();
1✔
171
    }
172

173
    public static Infer getInferenceEntryPoint(JavaNode n) {
174
        return n.getRoot().getLazyTypeResolver().getInfer();
1✔
175
    }
176

177
    public static @NonNull LazyTypeResolver getLazyTypeResolver(JavaNode n) {
178
        return n.getRoot().getLazyTypeResolver();
×
179
    }
180

181
    public static @NonNull ExprContext getTopLevelExprContext(TypeNode n) {
182
        return n.getRoot().getLazyTypeResolver().getTopLevelContextIncludingInvocation(n);
1✔
183
    }
184

185
    public static void setSymbolTable(JavaNode node, JSymbolTable table) {
186
        ((AbstractJavaNode) node).setSymbolTable(table);
1✔
187
    }
1✔
188

189
    public static void setQname(ASTTypeDeclaration declaration, String binaryName, @Nullable String canon) {
190
        ((AbstractTypeDeclaration) declaration).setBinaryName(binaryName, canon);
1✔
191
    }
1✔
192

193
    public static void assignComments(ASTCompilationUnit root) {
194
        CommentAssignmentPass.assignCommentsToDeclarations(root);
1✔
195
    }
1✔
196

197
    public static JavaccTokenDocument.TokenDocumentBehavior javaTokenDoc() {
198
        return JavaTokenDocumentBehavior.INSTANCE;
1✔
199
    }
200

201
    public static void setStandaloneTernary(ASTConditionalExpression node) {
202
        node.setStandaloneTernary();
1✔
203
    }
1✔
204

205
    public static boolean isStandaloneInternal(ASTConditionalExpression node) {
206
        return node.isStandalone();
1✔
207
    }
208

209
    public static JTypeMirror buildTypeFromAstInternal(TypeSystem ts, Substitution lexicalSubst, ASTType node) {
210
        return TypesFromAst.fromAst(ts, lexicalSubst, node);
1✔
211
    }
212

213
    public static JTypeDeclSymbol getReferencedSym(ASTClassType type) {
214
        return type.getReferencedSym();
1✔
215
    }
216

217
    public static void setTypedSym(ASTFieldAccess expr, JVariableSig.FieldSig sym) {
218
        expr.setTypedSym(sym);
1✔
219
    }
1✔
220

221
    public static void setTypedSym(ASTVariableAccess expr, JVariableSig sym) {
222
        expr.setTypedSym(sym);
1✔
223
    }
1✔
224
}
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