Skip to content

Commit

Permalink
Fix some NPEs in completion
Browse files Browse the repository at this point in the history
Signed-off-by: David Thompson <davthomp@redhat.com>
  • Loading branch information
datho7561 committed Oct 23, 2024
1 parent b427bb8 commit df710af
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,11 @@ public void run() {

if (context instanceof FieldAccess fieldAccess) {
statementLikeKeywords();
processMembers(fieldAccess, fieldAccess.getExpression().resolveTypeBinding(), specificCompletionBindings, false);

ITypeBinding fieldAccessType = fieldAccess.getExpression().resolveTypeBinding();
if (fieldAccessType != null) {
processMembers(fieldAccess, fieldAccess.getExpression().resolveTypeBinding(), specificCompletionBindings, false);
}
if (specificCompletionBindings.stream().findAny().isPresent()) {
specificCompletionBindings.stream()
.filter(binding -> this.pattern.matchesName(this.prefix.toCharArray(), binding.getName().toCharArray()))
Expand Down Expand Up @@ -269,12 +273,15 @@ public void run() {
}
// complete name
ITypeBinding type = expression.resolveTypeBinding();
processMembers(expression, type, specificCompletionBindings, false);
specificCompletionBindings.stream()
.filter(binding -> this.pattern.matchesName(this.prefix.toCharArray(), binding.getName().toCharArray()))
.filter(IMethodBinding.class::isInstance)
.map(binding -> toProposal(binding))
.forEach(this.requestor::accept);
if (type != null) {
processMembers(expression, type, specificCompletionBindings, false);
specificCompletionBindings.stream()
.filter(binding -> this.pattern.matchesName(this.prefix.toCharArray(), binding.getName().toCharArray()))
.filter(IMethodBinding.class::isInstance)
.map(binding -> toProposal(binding))
.forEach(this.requestor::accept);
}
suggestDefaultCompletions = false;
}
// else complete parameters, get back to default
}
Expand Down Expand Up @@ -892,20 +899,23 @@ private CompletionProposal toProposal(IBinding binding, String completion) {
res.setSignature(
Signature.createTypeSignature(variableBinding.getType().getQualifiedName().toCharArray(), true)
.toCharArray());
res.setReceiverSignature(
variableBinding.isField()
? Signature
.createTypeSignature(
variableBinding.getDeclaringClass().getQualifiedName().toCharArray(), true)
.toCharArray()
: new char[] {});
res.setDeclarationSignature(
variableBinding.isField()
? Signature
.createTypeSignature(
variableBinding.getDeclaringClass().getQualifiedName().toCharArray(), true)
.toCharArray()
: new char[] {});
if (variableBinding.isField()) {
ITypeBinding declaringClass = variableBinding.getDeclaringClass();
if (declaringClass != null) {
char[] declSignature = Signature
.createTypeSignature(
variableBinding.getDeclaringClass().getQualifiedName().toCharArray(), true)
.toCharArray();
res.setReceiverSignature(declSignature);
res.setDeclarationSignature(declSignature);
} else {
res.setReceiverSignature(new char[0]);
res.setDeclarationSignature(new char[0]);
}
} else {
res.setReceiverSignature(new char[0]);
res.setDeclarationSignature(new char[0]);
}
} else if (kind == CompletionProposal.TYPE_REF) {
var typeBinding = (ITypeBinding) binding;
res.setSignature(
Expand Down Expand Up @@ -1067,7 +1077,7 @@ private int computeRelevanceForExpectingType(ITypeBinding proposalType){

if(Objects.equals(expectedType.getQualifiedName(), proposalType.getQualifiedName())) {
return RelevanceConstants.R_EXACT_EXPECTED_TYPE;
} else if (proposalType.getPackage().isUnnamed()) {
} else if (proposalType.getPackage() != null && proposalType.getPackage().isUnnamed()) {
return RelevanceConstants.R_PACKAGE_EXPECTED_TYPE;
}
relevance = RelevanceConstants.R_EXPECTED_TYPE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static void createMethod(IMethodBinding methodBinding, StringBuilder completion)
static void createType(ITypeBinding type, StringBuilder completion) {
if (type.isWildcardType() || type.isIntersectionType()) {
completion.append('?');
if (type.isUpperbound()) {
if (type.isUpperbound() && type.getBound() != null) {
completion.append(' ');
completion.append(EXTENDS);
completion.append(' ');
Expand All @@ -115,7 +115,7 @@ static void createType(ITypeBinding type, StringBuilder completion) {
createType(bound, completion);
}
}
} else {
} else if (type.getBound() != null) {
completion.append(' ');
completion.append(SUPER);
completion.append(' ');
Expand Down

0 comments on commit df710af

Please sign in to comment.