Skip to content

Commit

Permalink
Improve some import static type completion
Browse files Browse the repository at this point in the history
  • Loading branch information
mickaelistria committed Jan 14, 2025
1 parent a0a7e5d commit 203f4a8
Showing 1 changed file with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,25 @@ public void run() {
}
if (context instanceof QualifiedName qualifiedName) {
ImportDeclaration importDecl = (ImportDeclaration)DOMCompletionUtil.findParent(context, new int[] { ASTNode.IMPORT_DECLARATION });
if (importDecl != null
&& importDecl.getAST().apiLevel() >= AST.JLS23
if (importDecl != null) {
if(importDecl.getAST().apiLevel() >= AST.JLS23
&& this.modelUnit.getJavaProject().getOption(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, true).equals(JavaCore.ENABLED)
&& importDecl.modifiers().stream().anyMatch(node -> node instanceof Modifier modifier && modifier.getKeyword() == ModifierKeyword.MODULE_KEYWORD)) {
findModules((this.qualifiedPrefix + "." + this.prefix).toCharArray(), this.modelUnit.getJavaProject(), this.assistOptions, Collections.emptySet()); //$NON-NLS-1$
suggestDefaultCompletions = false;
findModules((this.qualifiedPrefix + "." + this.prefix).toCharArray(), this.modelUnit.getJavaProject(), this.assistOptions, Collections.emptySet()); //$NON-NLS-1$
suggestDefaultCompletions = false;
} else {
suggestPackages(context);
suggestTypesInPackage(qualifiedName.toString());
if (importDecl.isStatic() &&
qualifiedName.getQualifier().resolveBinding() instanceof ITypeBinding type) {
Stream.of(type.getDeclaredFields(), type.getDeclaredMethods(), type.getDeclaredTypes())
.flatMap(Arrays::stream) //
.filter(binding -> (binding.getModifiers() & Modifier.STATIC) != 0) //
.map(this::toProposal) //
.forEach(this.requestor::accept);
}
suggestDefaultCompletions = false;
}
} else {
IBinding qualifiedNameBinding = qualifiedName.getQualifier().resolveBinding();
if (qualifiedNameBinding instanceof ITypeBinding qualifierTypeBinding && !qualifierTypeBinding.isRecovered()) {
Expand Down Expand Up @@ -1994,12 +2007,18 @@ private CompletionProposal toProposal(IType type) {
if (parentTypeDeclaration != null && type.getFullyQualifiedName().equals(((IType)parentTypeDeclaration.resolveBinding().getJavaElement()).getFullyQualifiedName())) {
completion.insert(0, cursor.getElementName());
} else {
while (cursor instanceof IType) {
ASTNode currentName = this.toComplete instanceof Name ? this.toComplete : null;
while (cursor instanceof IType currentType && (currentName == null || !Objects.equals(currentName.toString(), currentType.getFullyQualifiedName()))) {
if (!completion.isEmpty()) {
completion.insert(0, '.');
}
completion.insert(0, cursor.getElementName());
cursor = cursor.getParent();
if (currentName != null && currentName.getLocationInParent() == QualifiedName.NAME_PROPERTY) {
currentName = ((QualifiedName)currentName.getParent()).getQualifier();
} else {
currentName = null;
}
}
}
AbstractTypeDeclaration parentType = DOMCompletionUtil.findParentTypeDeclaration(this.toComplete);
Expand Down

0 comments on commit 203f4a8

Please sign in to comment.