Skip to content

Commit

Permalink
[26621] Mehrere gleiche Platzhalter durch HashSet entfernt (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daksic28 authored Sep 17, 2024
1 parent a48b306 commit d0b5a64
Showing 1 changed file with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.inject.Inject;

Expand Down Expand Up @@ -122,26 +124,30 @@ public void save() {

private class ReplacementProposalProvider implements IContentProposalProvider {

@Override
public IContentProposal[] getProposals(String contents, int position) {
contents = contents.toLowerCase();
List<IContentProposal> proposals = new ArrayList<>();
for (ITextPlaceholderResolver resolver : replacementService.getResolvers()) {
List<PlaceholderAttribute> attributes = resolver.getSupportedAttributes();
for (PlaceholderAttribute attribute : attributes) {
String proposalText = attribute.getTypeName() + "." + attribute.getAttributeName(); //$NON-NLS-1$
if (proposalText.toLowerCase().contains(contents)) {
proposals.add(new ContentProposal(proposalText));
}
}
}
proposals.sort(new Comparator<IContentProposal>() {
@Override
public int compare(IContentProposal arg0, IContentProposal arg1) {
return arg0.getLabel().compareTo(arg1.getLabel());
}
});
return proposals.toArray(new IContentProposal[proposals.size()]);
}
@Override
public IContentProposal[] getProposals(String contents, int position) {
contents = contents.toLowerCase();
Set<String> proposalTexts = new HashSet<>();
for (ITextPlaceholderResolver resolver : replacementService.getResolvers()) {
List<PlaceholderAttribute> attributes = resolver.getSupportedAttributes();
for (PlaceholderAttribute attribute : attributes) {
String proposalText = attribute.getTypeName() + "." + attribute.getAttributeName(); //$NON-NLS-1$
if (proposalText.toLowerCase().contains(contents)) {
proposalTexts.add(proposalText);
}
}
}
List<IContentProposal> proposals = new ArrayList<>();
for (String text : proposalTexts) {
proposals.add(new ContentProposal(text));
}
proposals.sort(new Comparator<IContentProposal>() {
@Override
public int compare(IContentProposal arg0, IContentProposal arg1) {
return arg0.getLabel().compareTo(arg1.getLabel());
}
});
return proposals.toArray(new IContentProposal[proposals.size()]);
}
}
}

0 comments on commit d0b5a64

Please sign in to comment.