-
Notifications
You must be signed in to change notification settings - Fork 669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SOLR-16271: remove wildcard imports #938
Conversation
@@ -16,7 +16,13 @@ | |||
*/ | |||
package org.apache.solr.handler; | |||
|
|||
import static org.apache.solr.handler.ReplicationTestHelper.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dsmiley what do you think of this style?
Thanks for giving this a shot @epugh! I now remember what I found when Googling how to get Spotless to do this some months ago. It's this technique used on another project (Geode): CC @uschindler -- when discussing source validations in general, I recall you have strong opinions |
Just pushed up the spotless version. We don't get the nice report, since it just stops on the first one with an exception:
|
@dsmiley before I go futhur, what do you think of the way I fixed the imports? Does this pattern for both regular and statics make sense? |
No wildcards -- not because of me or you or whatever IntelliJ or other IDE ships by default, but because we are trying to adhere to a particular style guide: https://google.github.io/styleguide/javaguide.html#s3.3.1-wildcard-imports |
awesome, so, is everything in this style guide "solr community accepted"? As in, can I reference this to understand what our style is? We should have a FAQ entry about that for the next person ;-) |
Lucene agreed to the Spotless code formatting with the Google Java. In Lucene's precommit will fail, if you have code not formatted like that. In general it's plain easy: run "./gradlew tidy" before commit. No need to take care anything. If your IDE has slightly different style it does not matter if you run the command before commit. 👍 |
I don't think this PR is needed. I'd just go with spotless. |
I believe that we have to manually deal with the import statements, that spotless can alert, but can't fix it....? |
From my knowledge, spotless can deal with imports. It uses javac to scan the code, so it understands how to expand wildcards. |
Our repo already documents adherence to "Google Java Format" -- https://github.com/apache/solr/blob/main/help/formatting.txt but perhaps we should restate this in more places. Spotless supports multiple formats, including "Google Java Style Guide", but it has limitations. Also CC @dweiss as you may be interested in this. |
From my investigation, spotless can reorder imports, but not expand them.... Any links/docs on how to enable it? |
Just a quick tip: IntelliJ can do all the work here across the project; no need to open any source file at all. Just select the root of the project in the navigation tree and choose "Optimize Imports" in the Code menu. It might be influenced by having the "Google-java-format" plugin enabled. |
To keep the build changes clearly visible from a massive commit that makes us adhere, I propose doing this in two PRs; first actually optimizes imports via the IDE (a different PR), and the second (this PR) then enforces the rule. |
Could we flip it? Only that this PR says "remove wildcard imports", and I'll add another that is "Check and prevent wildcard imports" ??? |
Trying it now! Still learning my way around intellij, thanks for sharing! |
@dsmiley the organize imports work great, however intellij had different order then spotless, so re-ran spotless to restore orginal order ,and now I am about to push up the explicit import changes. Will move the enforcement code to another issue. |
Just a note that some imports exist because of javadoc references and I think automated tools sometimes has issues in the past with removing them too aggressively. Worth a check after changes instead of blindly committing, and if you see it hopefully this is enough warning that you won't be surprised :) |
@madrob I did notice the |
I ran Other suggestions on what to verify? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this!
119 / 119 files viewed
import org.apache.lucene.analysis.Analyzer; | ||
import org.apache.lucene.queryparser.charstream.CharStream; | ||
import org.apache.lucene.queryparser.charstream.FastCharStream; | ||
import org.apache.lucene.search.BooleanClause; | ||
import org.apache.lucene.search.Query; | ||
import org.apache.solr.search.QParser; | ||
import org.apache.solr.search.SyntaxError; | ||
|
||
import java.io.StringReader; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.apache.lucene.analysis.Analyzer; | ||
import org.apache.lucene.search.BooleanClause; | ||
import org.apache.lucene.search.Query; | ||
import org.apache.solr.search.SyntaxError; | ||
import org.apache.solr.search.QParser; | ||
|
||
import org.apache.lucene.queryparser.charstream.CharStream; | ||
import org.apache.lucene.queryparser.charstream.FastCharStream; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: technically not wildcard import removal
solr/core/src/test/org/apache/solr/handler/admin/SolrEnvironmentTest.java
Outdated
Show resolved
Hide resolved
It looks like the comment was the only thing removed, not the import itself. If we can leave the comment somehow then I'd try to keep it, otherwise somebody in the future is inevitably going to try to flag those as unused imports and then stub their toe on it (that person is going to be me, I am the one that will stub his toe) |
are you saying the text |
I imagined |
…ntTest.java Co-authored-by: Christine Poerschke <cpoerschke@apache.org>
Okay, I think I am starting to understand... For the example of So, I guess, if we only have those three files that follow this pattern, then we can leave the comment in, but maybe change it from Or, maybe since intellij flags the missing import if you don't have it, then we don't need the comment at all? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but also okay with jdoc
comments being retained or changed to something similar.
This also removes the // jdoc comments, as IntelliJ does properly flag imports missing that are referenced in JavaDocs. Co-authored-by: Christine Poerschke <cpoerschke@apache.org>
https://issues.apache.org/jira/browse/SOLR-16271
Description
Remove wildcard imports from the build. In later issue, will add a spotless based check.
Solution
made the changes.
Tests
manually run tests.
Checklist
Please review the following and check all that apply:
main
branch../gradlew check
.