use of org.eclipse.jdt.internal.ui.text.template.contentassist.PositionBasedCompletionProposal in project che by eclipse.
the class ParameterGuesser method parameterProposals.
/**
* Returns the matches for the type and name argument, ordered by match quality.
*
* @param expectedType - the qualified type of the parameter we are trying to match
* @param paramName - the name of the parameter (used to find similarly named matches)
* @param pos the position
* @param suggestions the suggestions or <code>null</code>
* @param fillBestGuess <code>true</code> if the best guess should be filled in
* @param isLastParameter <code>true</code> iff this proposal is for the last parameter of a method
* @return returns the name of the best match, or <code>null</code> if no match found
* @throws org.eclipse.jdt.core.JavaModelException if it fails
*/
public ICompletionProposal[] parameterProposals(String expectedType, String paramName, Position pos, IJavaElement[] suggestions, boolean fillBestGuess, boolean isLastParameter) throws JavaModelException {
List<Variable> typeMatches = evaluateVisibleMatches(expectedType, suggestions);
orderMatches(typeMatches, paramName);
boolean hasVarWithParamName = false;
ICompletionProposal[] ret = new ICompletionProposal[typeMatches.size()];
int i = 0;
int replacementLength = 0;
for (Iterator<Variable> it = typeMatches.iterator(); it.hasNext(); ) {
Variable v = it.next();
if (i == 0) {
fAlreadyMatchedNames.add(v.name);
replacementLength = v.name.length();
}
String displayString = v.name;
hasVarWithParamName |= displayString.equals(paramName);
final char[] triggers;
if (isLastParameter) {
triggers = v.triggerChars;
} else {
triggers = new char[v.triggerChars.length + 1];
System.arraycopy(v.triggerChars, 0, triggers, 0, v.triggerChars.length);
triggers[triggers.length - 1] = ',';
}
ret[i++] = new PositionBasedCompletionProposal(v.name, pos, replacementLength, getImage(v.descriptor), displayString, null, null, triggers);
}
if (!fillBestGuess && !hasVarWithParamName) {
// insert a proposal with the argument name
ICompletionProposal[] extended = new ICompletionProposal[ret.length + 1];
System.arraycopy(ret, 0, extended, 1, ret.length);
extended[0] = new PositionBasedCompletionProposal(paramName, pos, replacementLength, null, paramName, null, null, isLastParameter ? null : new char[] { ',' });
return extended;
}
return ret;
}
Aggregations