Author: vrubezhny
Date: 2008-10-16 10:34:05 -0400 (Thu, 16 Oct 2008)
New Revision: 10889
Modified:
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/SortingCompoundContentAssistProcessor.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2118 Cleanup/unify the EL code completion used in
JSF, Java, Seam completions
Modified:
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/SortingCompoundContentAssistProcessor.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/SortingCompoundContentAssistProcessor.java 2008-10-16
14:16:06 UTC (rev 10888)
+++
trunk/common/plugins/org.jboss.tools.common.text.xml/src/org/jboss/tools/common/text/xml/contentassist/SortingCompoundContentAssistProcessor.java 2008-10-16
14:34:05 UTC (rev 10889)
@@ -16,6 +16,7 @@
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
@@ -207,10 +208,33 @@
ICompletionProposal[] resultArray = ret.toArray(new ICompletionProposal[ret.size()]);
Object[] sorted = createSorter().sort(resultArray);
System.arraycopy(sorted, 0, resultArray, 0, sorted.length);
+ resultArray = makeUnique(resultArray);
return resultArray;
}
+ /**
+ * Removes duplicates of completion strings
+ *
+ * @param suggestions a list of suggestions ({@link String}).
+ * @return a list of unique completion suggestions.
+ */
+ public ICompletionProposal[] makeUnique(ICompletionProposal[] proposals) {
+ HashSet<String> present = new HashSet<String>();
+ ArrayList<ICompletionProposal> unique= new
ArrayList<ICompletionProposal>();
+
+ for (int i = 0; proposals != null && i < proposals.length; i++) {
+
+ if (!present.contains(proposals[i].getDisplayString())) {
+ present.add(proposals[i].getDisplayString());
+ unique.add(proposals[i]);
+ }
+ }
+
+ present.clear();
+ return unique.toArray(new ICompletionProposal[unique.size()]);
+ }
+
protected Sorter createSorter() {
return new Sorter() {
public boolean compare(Object proposal1, Object proposal2) {
@@ -233,7 +257,7 @@
return str2.compareTo(str1) > 0;
}
- return (pr1 < pr2);
+ return (pr2 > pr1);
}
};
}