Static import fix#459
Conversation
|
Warning Review limit reached
Next review available in: 47 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/java/org/checkerframework/specimin/SpeciminRunner.java`:
- Around line 459-491: Update getUsedPackagesAndClasses to continue processing
each compilation unit’s TypeDeclaration entries even when no package declaration
exists; record the default-package marker without returning early. In the
enumeratorResult class-name loop, also add className itself when it has no dot,
while preserving existing package and fully qualified name tracking for dotted
names.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 5e1d79cd-6228-4796-9791-5a0c7b31e84f
📒 Files selected for processing (6)
src/main/java/org/checkerframework/specimin/SpeciminRunner.javasrc/test/java/org/checkerframework/specimin/StaticWildcardClassImportTest.javasrc/test/resources/staticwildcardclassimport/expected/com/example/Foo.javasrc/test/resources/staticwildcardclassimport/expected/com/example/Simple.javasrc/test/resources/staticwildcardclassimport/input/com/example/Foo.javasrc/test/resources/staticwildcardclassimport/input/com/example/Simple.java
| private static Set<String> getUsedPackagesAndClasses( | ||
| SliceResult sliceResult, UnsolvedSymbolEnumeratorResult enumeratorResult) { | ||
| Set<String> usedPackagesAndClasses = new HashSet<>(); | ||
| for (CompilationUnit cu : sliceResult.solvedSlice()) { | ||
| if (cu.getPackageDeclaration().isEmpty()) { | ||
| usedPackagesAndClasses.add(""); | ||
| continue; | ||
| } | ||
| usedPackagesAndClasses.add(cu.getPackageDeclaration().get().getNameAsString()); | ||
|
|
||
| for (TypeDeclaration<?> typeDecl : cu.findAll(TypeDeclaration.class)) { | ||
| String fqn = typeDecl.getFullyQualifiedName().orElse(null); | ||
|
|
||
| if (fqn == null) { | ||
| continue; | ||
| } | ||
|
|
||
| usedPackagesAndClasses.add(fqn); | ||
| } | ||
| } | ||
|
|
||
| for (String className : enumeratorResult.classNamesToFileContent().keySet()) { | ||
| int lastDot = className.lastIndexOf('.'); | ||
| if (lastDot < 0) { | ||
| usedPackagesAndClasses.add(""); | ||
| } else { | ||
| usedPackagesAndClasses.add(className.substring(0, lastDot)); | ||
| usedPackagesAndClasses.add(className); | ||
| } | ||
| } | ||
| return usedPackagesAndClasses; | ||
| } | ||
|
|
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Fix logic that skips tracking fully-qualified names in the default package.
When a compilation unit has no package declaration (the default package), the continue statement skips the inner loop, meaning no TypeDeclarations from that file are added to the set. Similarly, for class names without a dot, className itself is not added to the set.
While Java prohibits importing types from the unnamed package—which prevents this bug from affecting the wildcard import removal directly—this logic leaves the usedPackagesAndClasses set incomplete and could lead to subtle bugs if the set is ever repurposed.
🐛 Proposed fix
private static Set<String> getUsedPackagesAndClasses(
SliceResult sliceResult, UnsolvedSymbolEnumeratorResult enumeratorResult) {
Set<String> usedPackagesAndClasses = new HashSet<>();
for (CompilationUnit cu : sliceResult.solvedSlice()) {
- if (cu.getPackageDeclaration().isEmpty()) {
- usedPackagesAndClasses.add("");
- continue;
- }
- usedPackagesAndClasses.add(cu.getPackageDeclaration().get().getNameAsString());
+ if (cu.getPackageDeclaration().isPresent()) {
+ usedPackagesAndClasses.add(cu.getPackageDeclaration().get().getNameAsString());
+ } else {
+ usedPackagesAndClasses.add("");
+ }
for (TypeDeclaration<?> typeDecl : cu.findAll(TypeDeclaration.class)) {
String fqn = typeDecl.getFullyQualifiedName().orElse(null);
if (fqn == null) {
continue;
}
usedPackagesAndClasses.add(fqn);
}
}
for (String className : enumeratorResult.classNamesToFileContent().keySet()) {
int lastDot = className.lastIndexOf('.');
if (lastDot < 0) {
usedPackagesAndClasses.add("");
} else {
usedPackagesAndClasses.add(className.substring(0, lastDot));
- usedPackagesAndClasses.add(className);
}
+ usedPackagesAndClasses.add(className);
}
return usedPackagesAndClasses;
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| private static Set<String> getUsedPackagesAndClasses( | |
| SliceResult sliceResult, UnsolvedSymbolEnumeratorResult enumeratorResult) { | |
| Set<String> usedPackagesAndClasses = new HashSet<>(); | |
| for (CompilationUnit cu : sliceResult.solvedSlice()) { | |
| if (cu.getPackageDeclaration().isEmpty()) { | |
| usedPackagesAndClasses.add(""); | |
| continue; | |
| } | |
| usedPackagesAndClasses.add(cu.getPackageDeclaration().get().getNameAsString()); | |
| for (TypeDeclaration<?> typeDecl : cu.findAll(TypeDeclaration.class)) { | |
| String fqn = typeDecl.getFullyQualifiedName().orElse(null); | |
| if (fqn == null) { | |
| continue; | |
| } | |
| usedPackagesAndClasses.add(fqn); | |
| } | |
| } | |
| for (String className : enumeratorResult.classNamesToFileContent().keySet()) { | |
| int lastDot = className.lastIndexOf('.'); | |
| if (lastDot < 0) { | |
| usedPackagesAndClasses.add(""); | |
| } else { | |
| usedPackagesAndClasses.add(className.substring(0, lastDot)); | |
| usedPackagesAndClasses.add(className); | |
| } | |
| } | |
| return usedPackagesAndClasses; | |
| } | |
| private static Set<String> getUsedPackagesAndClasses( | |
| SliceResult sliceResult, UnsolvedSymbolEnumeratorResult enumeratorResult) { | |
| Set<String> usedPackagesAndClasses = new HashSet<>(); | |
| for (CompilationUnit cu : sliceResult.solvedSlice()) { | |
| if (cu.getPackageDeclaration().isPresent()) { | |
| usedPackagesAndClasses.add(cu.getPackageDeclaration().get().getNameAsString()); | |
| } else { | |
| usedPackagesAndClasses.add(""); | |
| } | |
| for (TypeDeclaration<?> typeDecl : cu.findAll(TypeDeclaration.class)) { | |
| String fqn = typeDecl.getFullyQualifiedName().orElse(null); | |
| if (fqn == null) { | |
| continue; | |
| } | |
| usedPackagesAndClasses.add(fqn); | |
| } | |
| } | |
| for (String className : enumeratorResult.classNamesToFileContent().keySet()) { | |
| int lastDot = className.lastIndexOf('.'); | |
| if (lastDot < 0) { | |
| usedPackagesAndClasses.add(""); | |
| } else { | |
| usedPackagesAndClasses.add(className.substring(0, lastDot)); | |
| } | |
| usedPackagesAndClasses.add(className); | |
| } | |
| return usedPackagesAndClasses; | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/main/java/org/checkerframework/specimin/SpeciminRunner.java` around lines
459 - 491, Update getUsedPackagesAndClasses to continue processing each
compilation unit’s TypeDeclaration entries even when no package declaration
exists; record the default-package marker without returning early. In the
enumeratorResult class-name loop, also add className itself when it has no dot,
while preserving existing package and fully qualified name tracking for dotted
names.
Fixes: * Constructors are preserved/created with a minimal super call when its superclass does not have a parameterless constructor Once #459 merges and this PR is reviewed, set base to branch main and let the CI run again. (I based this off of static-import-fix instead of main because I figured it would avoid merge conflicts down the line once this is merged) --------- Co-authored-by: Martin Kellogg <martin.kellogg@njit.edu>
Fixes: