Fixing imports for static item completion. #8210
Merged
+329
−30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Consider case like:
https://github.com/openjdk/jdk/blob/55c3e78f4ec982908e9a4b5e64b8be89717c49f4/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java#L2382
calling the code completion after
.hasTag(. GivenTypeTagis an enum, the CC should show all the enum constants. But, inside the VS Code, it fails to show anything.This is (sadly) a consequence of a series of mishaps (see later), but one of them is that
JavaCompletionCollector.createStaticMemberItemis usingGeneratorUtilities.addImport, which itself misbehaves. But, the collector should not use this method at all:addImportdoes not allow to inject FQNs if needed, etc. The main proposal in this patch is to useSourceUtils.resolveImportto resolve imports forcreateStaticMemberItem, which adds imports as needed, and provides the simple or qualified name that should be injected into the source.resolveImportwas already used on another place in the class.The other problems I've ran into, but are not fixed by this PR:
TextEdit.getNewTextis specified to never return null, but it might return null, as there's no check when the instance is created.TextEditwith thenullnew text is created from aModificationResult.Differencefor text removal - where the method is also specified to not return nullGeneratorUtilities.addImportsis removing package imports, intending to replace them with single-class imports, but it does not do the replacement. I thinkaddImportsshould not remove package imports, unless called fromOrganizeImports. Or, possibly, there should be a different entrypoint forOrganizeImports. But it seems wrong to manipulate imports in such an intrusive manner in simpleaddImports.I've also fixed for I think was flipped logic for sort text and smart typing for
createStaticMemberItem.