Skip to content

Add unit tests for JavaParserUtil name resolution - #8190

Closed
mernst wants to merge 14 commits into
relevance-type-variable-upper-boundfrom
javaparserutil-unit-tests
Closed

mernst wants to merge 14 commits into
relevance-type-variable-upper-boundfrom
javaparserutil-unit-tests

Conversation

@mernst

@mernst mernst commented Sep 16, 2026

Copy link
Copy Markdown
Member

Part 9 of 9, splitting #8177 into reviewable pieces. Based on #8189. With this merged, the stack is equivalent to #8177, which can then be closed.

Until now JavaParserUtil.resolveTypeName was exercised only indirectly, through the ainfer-relevance goal files, which cannot reach the cases that need types in more than one package.

Add a unit test that runs the resolver directly against fixture sources in superpkg and subpkg, covering inherited member types, package-private members that are not inherited across packages, shadowing, and type-variable resolution.

Test-only change; no production code is modified.

🤖 Generated with Claude Code

mernst and others added 14 commits September 16, 2026 12:12
The tests cover which member type a simple name refers to, which depends on
accessibility and on hiding, and when a name refers to a type variable rather
than to a type declaration that shadows it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ework-fork-mernst-branch-relevance-type-variable-upper-bound into javaparserutil-unit-tests
…ework-fork-mernst-branch-relevance-type-variable-upper-bound into javaparserutil-unit-tests
…ework-fork-mernst-branch-relevance-type-variable-upper-bound into javaparserutil-unit-tests
…ework-fork-mernst-branch-relevance-type-variable-upper-bound into javaparserutil-unit-tests
…ework-fork-mernst-branch-relevance-type-variable-upper-bound into javaparserutil-unit-tests
…ework-fork-mernst-branch-relevance-type-variable-upper-bound into javaparserutil-unit-tests
…ework-fork-mernst-branch-relevance-type-variable-upper-bound into javaparserutil-unit-tests
A class's member types are in scope in its body, but not in its header:
its annotations, its type parameter bounds, and its supertype names.
Likewise, the member types of an anonymous class are in scope only in
its body, not in the arguments to its constructor.  `resolveTypeName`
now tests whether the name appears in the body, rather than testing only
whether it is one of the supertype names.

Other fixes:

 * In `outer.new Inner() { ... }`, `Inner` is a member of the type of
   `outer` rather than a name that is resolved in the scope of the
   expression, so the anonymous class's supertype cannot be determined.
   Return null (conservative) rather than resolving `Inner` lexically.

 * An enum inherits the member type `EnumDesc` from its implicit
   supertype `java.lang.Enum`.  Search `java.lang.Enum` when the enum is
   unnameable, rather than letting the name fall through to an enclosing
   scope.

 * Pass `typeElementCache` to `typeToTypeMirror`, which otherwise
   allocated a fresh cache per call, so the field was never read.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`typeIsRelevant` called the 3-arg `JavaParserUtil.typeToTypeMirror`, which
allocates a fresh cache per call, leaving `typeElementCache` unused.  Pass the
field to the 4-arg overload.

In `extract-annotations` and `insert-annotations`, `AFU` silently became empty
if the `cd`/`pwd` failed; fail there instead of at the eventual `java` call.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ork-fork-mernst-branch-resolve-type-name-local-anonymous into resolve-type-name-member-scope
…-fork-mernst-branch-resolve-type-name-member-scope into resolve-member-type-inheritance
…k-fork-mernst-branch-resolve-member-type-inheritance into relevance-type-variable-upper-bound
…ework-fork-mernst-branch-relevance-type-variable-upper-bound into javaparserutil-unit-tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant