Skip to content

Commit

Permalink
Fix for #787: reduce relevance of qualified proposals within a closure
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jan 7, 2019
1 parent b99a032 commit f928e35
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2018 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -359,8 +359,8 @@ private List<ICompletionProposal> createJavaProposals(Collection<IGroovyProposal

private static void setClosureQualifiers(Collection<IGroovyProposal> delegateProposals, Collection<IGroovyProposal> ownerProposals, int resolveStrategy) {

Function<IGroovyProposal, String> toName = (IGroovyProposal proposal) -> {
AnnotatedNode node = ((AbstractGroovyProposal) proposal).getAssociatedNode();
Function<IGroovyProposal, String> toName = p -> {
AnnotatedNode node = ((AbstractGroovyProposal) p).getAssociatedNode();
if (node instanceof FieldNode) {
return ((FieldNode) node).getName();
}
Expand All @@ -373,14 +373,19 @@ private static void setClosureQualifiers(Collection<IGroovyProposal> delegatePro
throw new IllegalStateException("unexpected node type: " + node.getClass());
};

Consumer<IGroovyProposal> reduceRelevance = p -> {
AbstractGroovyProposal agp = (AbstractGroovyProposal) p;
agp.setRelevanceMultiplier(agp.getRelevanceMultiplier() * 0.9f);
};

if (!delegateProposals.isEmpty()) {
Consumer<IGroovyProposal> addDelegateQualifier = p -> ((AbstractGroovyProposal) p).setRequiredQualifier("delegate");

if (resolveStrategy == Closure.OWNER_FIRST && !ownerProposals.isEmpty()) {
Set<String> names = ownerProposals.stream().map(toName).collect(Collectors.toSet());
delegateProposals.stream().filter(p -> names.contains(toName.apply(p))).forEach(addDelegateQualifier);
} else if (resolveStrategy == Closure.TO_SELF) {
delegateProposals.forEach(addDelegateQualifier);
delegateProposals.forEach(addDelegateQualifier.andThen(reduceRelevance));
}
}

Expand All @@ -391,7 +396,7 @@ private static void setClosureQualifiers(Collection<IGroovyProposal> delegatePro
Set<String> names = delegateProposals.stream().map(toName).collect(Collectors.toSet());
ownerProposals.stream().filter(p -> names.contains(toName.apply(p))).forEach(addOwnerQualifier);
} else if (resolveStrategy == Closure.TO_SELF) {
ownerProposals.forEach(addOwnerQualifier);
ownerProposals.forEach(addOwnerQualifier.andThen(reduceRelevance));
}
}
}
Expand Down

0 comments on commit f928e35

Please sign in to comment.