Skip to content

Commit

Permalink
Set NON_INHERITED on relevance
Browse files Browse the repository at this point in the history
Start implementing conditions for
+ Some other fixes
  • Loading branch information
mickaelistria committed Dec 19, 2024
1 parent b415e6b commit cdeede4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class DOMCompletionContext extends CompletionContext {
}

private String tokenBefore(IBuffer cuBuffer) {
int position = this.offset - 1;
int position = Math.min(this.offset, cuBuffer.getLength()) - 1;
StringBuilder builder = new StringBuilder();
while (position >= 0 && Character.isJavaIdentifierPart(cuBuffer.getChar(position))) {
builder.append(cuBuffer.getChar(position));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,7 @@ private CompletionProposal toProposal(IBinding binding, String completion) {
res.setCompletion(completion.toCharArray());
res.setFlags(binding.getModifiers());

boolean inheritedValue = false;
if (kind == CompletionProposal.METHOD_REF || kind == CompletionProposal.METHOD_NAME_REFERENCE) {
var methodBinding = (IMethodBinding) binding;
var paramNames = DOMCompletionEngineMethodDeclHandler.findVariableNames(methodBinding);
Expand All @@ -1483,16 +1484,17 @@ private CompletionProposal toProposal(IBinding binding, String completion) {
}
res.setParameterTypeNames(Stream.of(methodBinding.getParameterNames()).map(String::toCharArray).toArray(char[][]::new));
res.setSignature(DOMCompletionEngineBuilder.getSignature(methodBinding));
res.setDeclarationSignature(Signature
.createTypeSignature(methodBinding.getDeclaringClass().getQualifiedName().toCharArray(), true)
.toCharArray());
if (!methodBinding.getDeclaringClass().getQualifiedName().isEmpty()) {
res.setDeclarationSignature(Signature
.createTypeSignature(methodBinding.getDeclaringClass().getQualifiedName().toCharArray(), true)
.toCharArray());
}

if ((methodBinding.getModifiers() & Flags.AccStatic) != 0) {
ITypeBinding topLevelClass = methodBinding.getDeclaringClass();
while (topLevelClass.getDeclaringClass() != null) {
topLevelClass = topLevelClass.getDeclaringClass();
}
boolean inheritedValue = false;
ITypeBinding methodTypeBinding = methodBinding.getDeclaringClass();
AbstractTypeDeclaration parentTypeDecl = DOMCompletionUtil.findParentTypeDeclaration(this.toComplete);
if (parentTypeDecl != null) {
Expand Down Expand Up @@ -1529,10 +1531,10 @@ private CompletionProposal toProposal(IBinding binding, String completion) {
res.setSignature(
Signature.createTypeSignature(variableBinding.getType().getQualifiedName().toCharArray(), true)
.toCharArray());
if (declaringClass != null) {
if (declaringClass != null && !declaringClass.getQualifiedName().isEmpty()) {
char[] declSignature = Signature
.createTypeSignature(
variableBinding.getDeclaringClass().getQualifiedName().toCharArray(), true)
declaringClass.getQualifiedName().toCharArray(), true)
.toCharArray();
res.setDeclarationSignature(declSignature);
} else {
Expand All @@ -1544,7 +1546,6 @@ private CompletionProposal toProposal(IBinding binding, String completion) {
while (topLevelClass.getDeclaringClass() != null) {
topLevelClass = topLevelClass.getDeclaringClass();
}
boolean inheritedValue = false;
ITypeBinding variableTypeBinding = variableBinding.getDeclaringClass();
AbstractTypeDeclaration parentTypeDecl = DOMCompletionUtil.findParentTypeDeclaration(this.toComplete);
if (parentTypeDecl != null) {
Expand All @@ -1563,10 +1564,14 @@ private CompletionProposal toProposal(IBinding binding, String completion) {
} else {
ITypeBinding directParentClass = variableBinding.getDeclaringClass();
res.setRequiredProposals(new CompletionProposal[] { toStaticImportProposal(directParentClass) });
StringBuilder builder = new StringBuilder(new String(res.getCompletion()));
builder.insert(0, '.');
builder.insert(0, directParentClass.getName());
res.setCompletion(builder.toString().toCharArray());
if (this.toComplete.getLocationInParent() != QualifiedName.NAME_PROPERTY &&
this.toComplete.getLocationInParent() != FieldAccess.NAME_PROPERTY &&
this.toComplete.getLocationInParent() != NameQualifiedType.NAME_PROPERTY) {
StringBuilder builder = new StringBuilder(new String(res.getCompletion()));
builder.insert(0, '.');
builder.insert(0, directParentClass.getName());
res.setCompletion(builder.toString().toCharArray());
}
}
}
}
Expand Down Expand Up @@ -1622,8 +1627,8 @@ private CompletionProposal toProposal(IBinding binding, String completion) {
binding instanceof IVariableBinding variableBinding ? variableBinding.getType() :
this.toComplete.getAST().resolveWellKnownType(Object.class.getName())) +
(res.getRequiredProposals() != null ? 0 : computeRelevanceForQualification(false)) +
CompletionEngine.computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE) //no access restriction for class field
//RelevanceConstants.R_NON_INHERITED // TODO: when is this active?
CompletionEngine.computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE) + //no access restriction for class field
(!staticOnly() || inheritedValue ? 0 : RelevanceConstants.R_NON_INHERITED) // TODO: when is this active?
);
if (res.getRequiredProposals() != null) {
for (CompletionProposal req : res.getRequiredProposals()) {
Expand All @@ -1633,6 +1638,13 @@ private CompletionProposal toProposal(IBinding binding, String completion) {
return res;
}

private boolean staticOnly() {
if (this.toComplete.getLocationInParent() == QualifiedName.NAME_PROPERTY) {
return DOMCodeSelector.resolveBinding(((QualifiedName)this.toComplete.getParent()).getQualifier()) instanceof ITypeBinding;
}
return false;
}

private String qualifiedTypeName(ITypeBinding typeBinding) {
if (typeBinding.isTypeVariable()) {
return typeBinding.getName();
Expand Down Expand Up @@ -1685,7 +1697,8 @@ private CompletionProposal toProposal(IType type) {
}
} else {
// in imports list
if (this.cuBuffer.getChar(this.toComplete.getStartPosition() + this.toComplete.getLength()) != ';') {
int lastOffset = this.toComplete.getStartPosition() + this.toComplete.getLength();
if (lastOffset >= this.cuBuffer.getLength() || this.cuBuffer.getChar(lastOffset) != ';') {
completion.append(';');
}
}
Expand Down

0 comments on commit cdeede4

Please sign in to comment.