How to make unqualified Java type names resolve without explicit imports, from a plugin?

I'm building a plugin that reads a global-imports.xml file from the project root and makes those imports available project-wide — so a developer can write List<String> in any Java class without an explicit import java.util.List at the top of that file.

The build side works (a Maven plugin injects the imports before compilation). The IDE side is what I'm stuck on.

What I want: For any simple name in global-imports.xml (e.g. List, ResponseEntity, Service), IntelliJ should treat it as resolved in every Java file in the project — no red marks, no "cannot resolve symbol" errors.

What I've tried:

  • PsiShortNamesCache — registered via java.shortNamesCache, returns the correct PsiClass from getClassesByName(), but red marks remain
  • ImplicitUsageProvider — wrong extension point, meant for unused code warnings not resolution
  • InspectionSuppressor / lang.inspectionSuppressor — suppresses inspection IDs but doesn't affect the underlying resolution error highlight
  • HighlightInfoFiltercom.intellij.highlightInfoFilter not found as a valid extension point in 2024.2

Target IDE version: IntelliJ IDEA 2024.2.1 (IC-242.21829.142)

Question: What is the correct extension point or API to make an unqualified Java type name resolve to a known FQN without a physical import statement in the file? Is there something equivalent to how Kotlin's default imports (kotlin.*, kotlin.collections.*) work, but accessible from a plugin? Or is there a way to virtually add imports to a PsiJavaFile's import list without modifying the file on disk?

Any pointer to a working example or the correct class/interface to implement would be hugely appreciated.

1

PsiShortNamesCache won't affect Java resolution. For project-wide implicit imports, you'll need to hook into Java's reference resolution (e.g., via custom PSI/reference handling), not inspections or caches. Looking at how Lombok support or Kotlin's resolver integrates with IntelliJ is probably the best path, since there isn't a simple "global Java imports" extension point exposed by the platform.

0

请先登录再写评论。