fix(gradle): replace internal IElementType.getDebugName() with direct type equality#254
Conversation
Review Summary by QodoAdd pyproject.toml support for Python dependency analysis with PEP 621 and Poetry formats
WalkthroughsDescription• Add pyproject.toml support for Python dependency analysis - Parses PEP 621 [project.dependencies] and [project.optional-dependencies] - Parses Poetry [tool.poetry.dependencies] format with inline tables - Extracts PEP 508 package names, versions, extras, and environment markers • Register PyprojectCAAnnotator and PyprojectCAInspection in plugin.xml • Update package manager detection and API settings for pyproject.toml • Fix Cargo.toml file validation with early return check • Replace internal IElementType.getDebugName() with direct type equality • Update documentation with pyproject.toml examples and ignore syntax Diagramflowchart LR
A["pyproject.toml file"] -->|parsed by| B["PyprojectCAAnnotator"]
B -->|extracts dependencies| C["PEP 621<br/>Poetry<br/>Optional deps"]
C -->|creates| D["Dependency objects"]
D -->|triggers| E["PyprojectCAInspection"]
E -->|shows violations| F["PyprojectCAIntentionAction"]
F -->|updates versions| A
G["ApiService"] -->|applies Python settings| H["pyproject.toml analysis"]
File Changes1. src/main/java/org/jboss/tools/intellij/componentanalysis/pypi/PyprojectCAAnnotator.java
|
Code Review by Qodo
1. Gradle repositories lookup throws
|
| private static @NotNull PsiElement getRepositoriesFromBuildGradle(PsiFile file) { | ||
| PsiElement repositories = Arrays.stream(file.getChildren()).filter(psi -> psi instanceof LeafPsiElement) | ||
| .filter(psi -> ((LeafPsiElement) psi).getElementType().getDebugName().equals(BuildGradleTypes.REPOSITORIES.getDebugName())).findFirst().get(); | ||
| .filter(psi -> ((LeafPsiElement) psi).getElementType() == BuildGradleTypes.REPOSITORIES).findFirst().get(); | ||
| return repositories; |
There was a problem hiding this comment.
1. Gradle repositories lookup throws 🐞 Bug ☼ Reliability
GradleCAUpdateManifestIntentionAction.getRepositoriesFromBuildGradle() uses findFirst().get(), so if no REPOSITORIES leaf is produced it throws NoSuchElementException; isAvailable() calls it unguarded, so simply querying intentions can crash for such build.gradle files.
Agent Prompt
### Issue description
`GradleCAUpdateManifestIntentionAction#getRepositoriesFromBuildGradle` calls `findFirst().get()` which can throw `NoSuchElementException` when the lexer/parser does not produce a `REPOSITORIES` token (e.g., the file has no repositories block or the block does not match the lexer regex). This also impacts `isAvailable()` because it calls `getRepositoriesFromBuildGradle(file)` unguarded.
### Issue Context
This intention is queried frequently by the IDE; throwing from `isAvailable()` degrades stability.
### Fix Focus Areas
- src/main/java/org/jboss/tools/intellij/componentanalysis/gradle/GradleCAUpdateManifestIntentionAction.java[47-63]
- src/main/java/org/jboss/tools/intellij/componentanalysis/gradle/build/buildGradle.flex[54-62]
### What to change
- Make `getRepositoriesFromBuildGradle` return `@Nullable PsiElement` or `Optional<PsiElement>`.
- In `isAvailable()`, return `false` when repositories cannot be found.
- In `updateManifest()`, either:
- create/insert a new `repositories { ... }` block when missing, or
- fail gracefully (no-op) with a clear user-facing message (avoid throwing).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
… type equality Use direct == comparison on IElementType singleton instances instead of comparing debug name strings via the internal getDebugName() API. Implements TC-4167 Assisted-by: Claude Code
Configure pluginVerification to treat INTERNAL_API_USAGES as a build failure, preventing future internal API regressions from passing CI. Implements TC-4167 Assisted-by: Claude Code
Return null instead of throwing NoSuchElementException when the repositories block is not found, preventing IDE crashes when querying intentions for build.gradle files without a repositories block. Implements TC-4167 Assisted-by: Claude Code
|



Summary
IElementType.getDebugName()internal API call with direct==type identity comparison inGradleCAUpdateManifestIntentionActionIElementTypeinstances are singletons, so direct equality is both correct and idiomaticImplements TC-4167
Test plan
./gradlew compileJavapasses./gradlew test— all existing tests pass./gradlew runPluginVerifier— no internal API warning forIElementType.getDebugNamebuild.gradlefile, trigger update manifest intention action, confirm it works🤖 Generated with Claude Code