Skip to content
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

fix: auto-import works for compilation units with multiple classes #1322

Merged
merged 7 commits into from
May 29, 2017

Conversation

monperrus
Copy link
Collaborator

No description provided.

this.importsContext = new MinimalImportScanner();
}
// warning: the import scanner used in this pretty-printer has been set once and for all in the constructor
// this is required to reuse import when multiple classes are in the same compilation unit
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is required to reuse import when multiple classes are in the same compilation unit

If they are in the same compulation unit, then we enter only once in this method and it's already using the same importContext.
However it could mess things with different compilation units: let's say we are in no-autoimport and we have two CU, the first one use B but have a collision, then it should import B, if the second CU also use B, even without collision it will be imported too and that's not the expected behaviour.

@@ -207,9 +172,6 @@ public void scan(CtElement element) {

@Override
public Collection<CtReference> computeAllImports(CtType<?> simpleType) {
classImports.clear();
fieldImports.clear();
methodImports.clear();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added them by security if computeAllImports was called multiple times with the same instance.

@@ -224,11 +186,7 @@ public void scan(CtElement element) {

@Override
public Collection<CtTypeReference<?>> computeImports(CtElement element) {
classImports.clear();
fieldImports.clear();
methodImports.clear();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is used to for toString so it can really be used multiple times with the same instance, it would be safer to keep it that way, don't you think?

@@ -404,7 +362,7 @@ protected boolean isImportedInClassImports(CtTypeReference<?> ref) {
*/
private boolean declaringTypeIsLocalOrImported(CtTypeReference declaringType) {
if (declaringType != null) {
if (isImportedInClassImports(declaringType) || classNamePresentInJavaLang(declaringType)) {
if (!isTypeInCollision(declaringType, false) && (isImportedInClassImports(declaringType) || classNamePresentInJavaLang(declaringType))) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I was testing that and trying to import the declaring type just below. So I assume you had a problem somewhere importing a declaring type: the condition below is useless then...

@monperrus monperrus merged commit 0b96506 into INRIA:master May 29, 2017
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.

2 participants