ITextSelection selection = (ITextSelection)viewer.getSelectionProvider().getSelection();
WordFinderAdaptor wordFinder = new WordFinderAdaptor(viewer.getDocument(), fIdentDetector);
String prefix = wordFinder.getPrefix(offset);
ICocoRegion region = new CocoRegion(offset - prefix.length(), prefix.length() + selection.getLength());
String prefixLow = prefix.toLowerCase();
LinkedList<ICompletionProposal> completionProposals = new LinkedList<ICompletionProposal>();
Set<ICompletionProposal> fieldProposals = new TreeSet<ICompletionProposal>(new PorposalComparator());
Set<ICompletionProposal> methodProposals = new TreeSet<ICompletionProposal>(new PorposalComparator());
Set<ICompletionProposal> constructorProposals = new TreeSet<ICompletionProposal>(new PorposalComparator());
Set<ICompletionProposal> localProposals = new TreeSet<ICompletionProposal>(new PorposalComparator());
ATGLabelProvider labelProvider = new ATGLabelProvider();
if(fields!=null){
for(VarProposal entry : fields){
String text = entry.toString();
if (text.toLowerCase().startsWith(prefixLow)) {
fieldProposals.add(new StyledCompletionProposal(entry,
region.getOffset(), region.getLength(), labelProvider));
}
}
}
if(methods!=null){
for(MethProposal entry : methods){
String text = entry.toString();
if (text.toLowerCase().startsWith(prefixLow)) {
if(entry.getBinding().isConstructor()){
constructorProposals.add(new StyledCompletionProposal(entry,
region.getOffset(), region.getLength(), labelProvider));
}
else{
methodProposals.add(new StyledCompletionProposal(entry,
region.getOffset(), region.getLength(), labelProvider));
}
}
}
}
if(locals!=null){
for(VarProposal entry : locals){
String text = entry.toString();
if (text.toLowerCase().startsWith(prefixLow)) {
fieldProposals.add(new StyledCompletionProposal(entry,
region.getOffset(), region.getLength(), labelProvider));
}
}
}
completionProposals.addAll(constructorProposals);
completionProposals.addAll(localProposals);
completionProposals.addAll(fieldProposals);
completionProposals.addAll(methodProposals);
if(completionProposals.isEmpty()){
String entry = prefix+"no Default Proposals";
completionProposals.add(new StyledCompletionProposal (entry,
region.getOffset(), region.getLength(), labelProvider));
}
return completionProposals.toArray(new ICompletionProposal[completionProposals.size()]);
}